ndimage

How to align principal axes of 3D density map in numpy with Cartesian axes?

北城以北 提交于 2021-02-07 22:50:38
问题 I have an n x n x n numpy array that contains density values on a cubic grid. I'm trying to align the principal axes of inertia of the density map with the cartesian x,y,z axes of the grid. I have the following so far: import numpy as np from scipy import ndimage def center_rho(rho): """Move density map so its center of mass aligns with the center of the grid""" rhocom = np.array(ndimage.measurements.center_of_mass(rho)) gridcenter = np.array(rho.shape)/2. shift = gridcenter-rhocom rho =

How to align principal axes of 3D density map in numpy with Cartesian axes?

爷,独闯天下 提交于 2021-02-07 22:47:34
问题 I have an n x n x n numpy array that contains density values on a cubic grid. I'm trying to align the principal axes of inertia of the density map with the cartesian x,y,z axes of the grid. I have the following so far: import numpy as np from scipy import ndimage def center_rho(rho): """Move density map so its center of mass aligns with the center of the grid""" rhocom = np.array(ndimage.measurements.center_of_mass(rho)) gridcenter = np.array(rho.shape)/2. shift = gridcenter-rhocom rho =

Finding image peaks using ndimage.maximum_filter and skimage.peak_local_max

假装没事ソ 提交于 2021-01-03 02:22:28
问题 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 I have modified an example from skimage shown here in order to compare the peaks found. from scipy import ndimage as ndi import matplotlib.pyplot as plt from skimage.feature import peak_local_max from skimage import data, img_as_float im = img_as

Finding image peaks using ndimage.maximum_filter and skimage.peak_local_max

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-03 02:01:21
问题 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 I have modified an example from skimage shown here in order to compare the peaks found. from scipy import ndimage as ndi import matplotlib.pyplot as plt from skimage.feature import peak_local_max from skimage import data, img_as_float im = img_as

How to produce a 2D cut through a 3D image?

≡放荡痞女 提交于 2019-12-25 12:48:05
问题 I have a 3D array with some data (a raster 3D image). I would like to get a 2D cut through that array, using some suitable interpolation (preferably linear - that's probably "trilinear" in this case). The plane of the cut can be described however is convenient, for example using a normal vector and distance. If the cut is parallel to one of the axes, this is trivial, just slice the 3D array (with numpy index slice). But if the cut is not parallel to an axis, I don't see a good way to get

scipy ndimage measurement labeling is not working properly

给你一囗甜甜゛ 提交于 2019-12-24 23:14:34
问题 I am trying to label this image into two regions: And here is my code: from scipy.ndimage import measurements,morphology from PIL import Image from numpy import * im = array(Image.open('two_leds.png').convert('L')) im = 1*(im<200) result = Image.fromarray((im * 255).astype(uint8)) result.save('results.png') labels, nbr_objects = measurements.label(im) print 'number of objects equals: {}'.format(nbr_objects) Here is the filtered image "results.png" with low-pass filter My problem is the output

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

时光毁灭记忆、已成空白 提交于 2019-12-09 12:22:33
问题 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:

Shift interpolation does not give expected behaviour

巧了我就是萌 提交于 2019-12-07 01:37:17
问题 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

Directly “plot” line segments to numpy array

做~自己de王妃 提交于 2019-12-06 09:24:57
问题 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