ndimage

Shift interpolation does not give expected behaviour

纵饮孤独 提交于 2019-12-05 04:17:09
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 one ( index N-1 ) instead of the "last plus one ( index N )". Minimal example: # module import import numpy as np from scipy.ndimage.interpolation import shift import matplotlib.pyplot as plt # print scipy.__version__ # 0.18.1 a = range(10) plt.figure(figsize=(16,12)) for i, shift_pix in enumerate(range(10)): # shift the data via spline

Directly “plot” line segments to numpy array

China☆狼群 提交于 2019-12-04 17:35:02
One of my first projects realized in python does Monte Carlo simulation of stick percolation. The code grew continually. The first part was the visualization of the stick percolation. In an area of width*length a defined density (sticks/area) of straight sticks with a certain length are plotted with random start coordinates and direction. As I often use gnuplot I wrote the generated (x, y) start and end coordinates to a text file to gnuplot them afterwards. I then found here a nice way to analyze the image data using scipy.ndimage.measurements. The image is read by using ndimage.imread in

scipy.ndimage.zoom result depends on image size

烂漫一生 提交于 2019-12-04 07:35:18
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 seems to be too large and the resulting image gets cropped. In contrast, if the tile has dimensions 10x10, the result looks good. from __future__ import division import numpy as np from scipy import ndimage, misc import wx y,x = 2,2 # change tile size here imgdata = np.zeros((y,x),dtype='uint8') imgdata[y/2:,x/2:] = 255 imgdata[:y/2,:x/2] = 255

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

烂漫一生 提交于 2019-12-03 14:43:42
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 length-1 arrays can be converted to Python scalars . I'm looking for a generic filter that process 2D or 3D arrays and returns a vector at each point. Thus the output would have one added dimension. For the example below I'd expect something like this: m.shape # (10,10) res.shape # (10,10,2) Example Code import numpy as np from scipy import ndimage a =

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

三世轮回 提交于 2019-11-30 17:08:20
问题 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 looked into the scipy-ndimage documentation and haven't found a dedicated function. Code for object identification: import numpy as np from scipy import ndimage from matplotlib import pyplot as plt # generate some lowpass-filtered noise as a test