Questions tagged [ndimage]

Multi-dimensional image processing module within Scipy.

Scipy contains modules for a variety of scientific computing tasks.

ndimage is used for multi-dimensional image processing and contains the following submodules,

  • Filters scipy.ndimage.filters
  • Fourier filters scipy.ndimage.fourier
  • Interpolation scipy.ndimage.interpolation
  • Measurements scipy.ndimage.measurements
  • Morphology scipy.ndimage.morphology
  • Utility
108 questions
8
votes
1 answer

Rotate a batch of images using `scipy.ndimage.interpolation.rotate`

Let's suppose that X is a numpy.ndarray tensor that holds a set of color images. For instance, X's shape is (100, 3, 32, 32); i.e., we have 100 32x32 rgb images (such as those provided by the CIFAR dataset). I want to rotate the images in X and I…
nullgeppetto
  • 539
  • 1
  • 8
  • 25
8
votes
3 answers

Removing completely isolated cells from Python array?

I'm trying to reduce noise in a binary python array by removing all completely isolated single cells, i.e. setting "1" value cells to 0 if they are completely surrounded by other "0"s. I have been able to get a working solution by removing blobs…
7
votes
1 answer

Which cubic spline method does scipy ndimage use for affine_transform?

Background/Context I was trying to reproduce the values output by scipy's ndimage.affine_transform function, but it seems I am using a different "cubic" interpolation scheme compared to the scipy implementation. Example Let's take a look at a very…
NOhs
  • 2,780
  • 3
  • 25
  • 59
7
votes
1 answer

Finding image peaks using ndimage.maximum_filter and skimage.peak_local_max

I am trying to find some relative maximums of a given image. I understand that there are two possible methods, the first is using scipy.ndimage.maximum_filter() and the second using skimage.feature.peak_local_max(). In order to compare both methods…
Jose M Gonzalez
  • 349
  • 3
  • 16
7
votes
2 answers

Shift interpolation does not give expected behaviour

When using scipy.ndimage.interpolation.shift to shift a numpy data array along one axis with periodic boundary treatment (mode = 'wrap'), I get an unexpected behavior. The routine tries to force the first pixel (index 0) to be identical to the last…
bproxauf
  • 1,076
  • 12
  • 23
7
votes
4 answers

How to convert a wand image object to numpy array (without OpenCV)?

I am converting pdf files to image using Wand. Then, I do further image processing using ndimage. I would like to directly convert the Wand image into a ndarray... I have seen the answer here, but it use OpenCV. Is this possible without using…
xdze2
  • 3,986
  • 2
  • 12
  • 29
7
votes
1 answer

Transforming and Resampling a 3D volume with numpy/scipy

UPDATE: I created a well documented ipython notebook. If you just want the code, look at the first answer. Question I've got a 40x40x40 volume of greyscale values. This needs to be rotated/shifted/sheared. Here is a useful collection of homogeneous…
lhk
  • 27,458
  • 30
  • 122
  • 201
7
votes
2 answers

Scipy filter with multi-dimensional (or non-scalar) output

Is there a filter similar to ndimage's generic_filter that supports vector output? I did not manage to make scipy.ndimage.filters.generic_filter return more than a scalar. Uncomment the line in the code below to get the error: TypeError: only…
user12719
  • 211
  • 1
  • 6
6
votes
2 answers

How to silence the UserWarning from scipy.ndimage.zoom

I'm using scipy.ndimage.zoom and I get this annoying warning: UserWarning: From scipy 0.13.0, the output shape of zoom() is calculated with round() instead of int() - for these inputs the size of the returned array has changed. I'm not sure what I…
filippo
  • 5,197
  • 2
  • 21
  • 44
6
votes
1 answer

How do I use scipy.ndimage.filters.gereric_filter?

I'm trying to use scipy.ndimage.filters.generic_filter to calculate a weighted sum from a neighborhood. The neighborhood will be variable at some point but for now 3x3 is what I'm working towards. So far this is where I am: def Func(a): …
user3684221
  • 73
  • 1
  • 4
5
votes
2 answers

How to apply a uniform filter using SciPy Image where the data outside the boundary is not tallied?

I have spent lots of time on this, and I know how to manually do it by slicing and indexing the boundary rows/cols, but there has to be a simpler way with SciPy. I need to set the CVAL (values to fill past the edges when mode=constant) to NaN,…
dfresh22
  • 961
  • 1
  • 15
  • 23
5
votes
2 answers

How to find the diameter of objects using image processing in Python?

Given an image with some irregular objects in it, I want to find their individual diameter. Thanks to this answer, I know how to identify the objects. However, is it possible to measure the maximum diameter of the objects shown in the image? I have…
FaCoffee
  • 7,609
  • 28
  • 99
  • 174
5
votes
1 answer

scipy.ndimage.zoom result depends on image size

I noticed that the result of scipy.ndimage.zoom depends on the size of the original image. In the following code sample a checkerboard image is generated and then zoomed with ndimage.zoom. If one checkerboard tile is just 2x2 pixels, the zoom factor…
Christian K.
  • 2,785
  • 18
  • 40
4
votes
1 answer

Find the 1s pixels that immediately and completely enclose an area of 0s

Starting with a 2d array of 0s and 1s, I need to identify which 1s form a united fence completely enclosing one or more adjacent 0s. Those 0s are considered adjacent if they touch on their sides or the diagonal. The fence must exist on the…
Jim
  • 155
  • 1
  • 8
4
votes
0 answers

How does ndimage.generic_filter() work with multidimensional arrays

I think I understand the working of ndimage.generic_filter but I don't understand what happens when you throw in an array with more than 2 dimensions (like [[R],[G],[B]] values from an image) Given the following code: import numpy as np from…
tilt
  • 220
  • 1
  • 11
1
2 3 4 5 6 7 8