4
$\begingroup$

How can I extract each cell (= patch that is not crossed by the contour) from an image such as

enter image description here

I thought SelectComponents (e.g. SelectComponents[img, #Width > 1 &]) could do it but I did not manage. I need to keep track of the position of the cell also, so the output could be a few hundreds images of the same size as the original image, with white everywhere except for the cells.

$\endgroup$
7
$\begingroup$

Here is a start:

img = ColorConvert[Import["https://i.stack.imgur.com/8SREb.png"], "Grayscale"];
MorphologicalComponents[Binarize[img, .7]] // Colorize

Mathematica graphics

If you want some insight, why this works, then look at the binary image. You'll see that each white patch is surrounded by a black line.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.