0

I'm working with Python. I want to know if there is a python way to mask a 3d array XYZ (volumetric image) to perform a segmentation analysis such as skeletonization.

I'm handling a 600x600x300 array so reducing the number of candidates to be analyzed is key to performance. I tried np.array[mask] but the array dimension changes to 1. The where method such as this How to Correctly mask 3D Array with numpy performs the change to one value at the time, but skeletonization needs to analyze the neighbors to be performed.

Edit: This is something simple but it might help you to get the idea. It's to create a 3d AOI inside a volume.

# create array with random numbers
Array = np.random.random([10, 10,10])

# create a boolean mask of zeros
maskArr=np.zeros_like(Array, dtype=bool)

# set a few values in the mask to true
maskArr[1:8,1:5,1:3] = 1

# Try to analise the data with mask
process= morphology.skeletonize(Array[maskArr])

this is the error due to the 1-d array:

ValueError: skeletonize requires a 2D or 3D image as input, got 1D.

jopemora
  • 1
  • 1
  • 1
    Please provide more details about your problem. Have you tried multiplying the mask and the volume elementwise? – alan.elkin Jun 26 '20 at 01:51
  • 1
    I tried your solution and it reduced the time to perform the analysis, but I don't know if it could d be improved the ways to tackle this problem. I started with a 2d array with the tuples, but I decided to create a boolean mask array to avoid scanning a list. I will try to create a small code to explain. – jopemora Jun 26 '20 at 02:04
  • You cannot create images of arbitrary shape, it has to be a rectangle. So extracting the pixels masked cannot preserve neighborhood information by definition. But what you can do is find the bounding box of your mask and extract that. You should get a smaller image. – Cris Luengo Jun 26 '20 at 02:38
  • you can think of it as a 2d images stacked one on top of the other as slices, like a CT scan. I don't want to extract a new volume, just to mask or create an AOI inside the volume avoiding the analysis over other areas for performance. imagine a complete volume of a human head and I just want to analyze one eye without cropping. – jopemora Jun 26 '20 at 02:44

0 Answers0