简体   繁体   中英

Slicing a 3D array vs projecting it

Link to array file

I am new to image processing and trying to understand projection. So when we have a 3D image, it is simply a 3D numpy array and i view it by slicing a 2D array out of the 3D array. In order to do a orthogonal projection, i simply sum up the arrays along one axis. This is my code for doing that:

import numpy as np
import matplotlib.pyplot as plt

#shape of the 'image' array is (256, 256, 176) so i am assuming there are 256 slices and row and column of each slice is 256x176
image = np.load('brain_ct.npy')

#when i sum along axis 0 or axis 1, the image shows up as blank with some warnings
#(Warning: converting a masked element to nan)
#only summing up along axis 2 works (not sure why is that)
collapsed = np.sum(image, axis=2)

plt.imshow(collapsed, cmap='gray')

I am not sure why summing up along axis 0 and 1 does not work. Also, i am not sure what view (top/down/side) axis 2 is giving me? Finally, if summing up along one axis gives orthogonal projection, how can i go about doing an oblique and perspective projection. Is there any transformation matrix that i have to multiply the image coordinates with?

Thanks everyone.

The error appears to show that you are loading a numpy.ma.MaskedArray rather than a NumPy array. However, I don't understand why you would not get the error along axis=2, since any masked points will be projected along each dimension. It could be that you have a whole plane masked, and then summing along 0 will just give you an array of nans. I am not sure but it could be that np.sum does not handle masked arrays properly, and you should instead use image.sum() , which might know better how to handle the masks. If you share your .npy file we can provide a more personalised response.

In general, summing is one way to project, but you could also do max() , which is the most common form of volumetric projection.

Regarding oblique projections, that's far more than can be succinctly summarised in a SO answer, but in general yes, you want to transform your image and then do the projection. You can look at the scipy.ndimage module for more information on this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM