Dear Sckit users,
I thresholded muscle fibers to obtain a binary mask (
preMask) as such:
and I would like to filter the fibers based on size and circularity, here is the different steps I followed:
label_image = sc.measure.label(preMask)
fiberList = sc.measure.regionprops(label_image)
The number of objects found is 299 using
len(fiberList), I then filter the list using:
correct_labels = [fiber.label for fiber in fiberList if ( (fiber.area*(pixelSize**2) >= 150) and (fiber.area*(pixelSize**2)<=10000) and (4*math.pi*(fiber.area/fiber.perimeter**2) > 0.4) ) ]
To obtain 293 fibers (
len(correct_labels)) that pass the cut.
I then recreate an image with only the correct fibers for subsequent processing:
finalMask = np.zeros_like(preMask) # create the final mask image, empty at the moment for label in correct_labels: # loop through the list of filtered labels obj = fiberList[label-1] # assign the coming fiber to 'obj' (need to be label-1 because it start at 0) for r,c in obj.coords: finalMask[r,c] = True # Assign label value
To obtain this final mask:
Now is the core of my question: how can I recreate this final mask with a more intelligent solution? One way would be to put the pixels belonging to rejected fibers to
False in the
preMask images but it still requires to loop through a certain number of pixels…
Is there a way to pop regions out of the
fiberList and recreate an Image using this “cleaned” List ?
I couldn’t find a way to go back from a regionprops to an image without drawing each pixels independently.
Thank you for your help.