# Find outline of a cell

I have a set of images of biological cells, which look like this:

How do I find the edge of these cells in a robust way (i.e. without having to manually tweak each one. I have three images here:

img1 = Import["https://i.stack.imgur.com/hZ5Vt.jpg"]
img2 = Import["https://i.stack.imgur.com/tQ5wd.jpg"]
img3 = Import["https://i.stack.imgur.com/wjfvW.jpg"]


and I'm looking for ways to deliminate the outer edge. I need the actual edge (accurately), not a bounding box. The background should be relatively constant between images.

This does reasonably on the first image, but not on the others:

HighlightImage[img1,
DeleteSmallComponents@EdgeDetect[CurvatureFlowFilter[img1, 10], 15]]


# Refer to the Green chromaticity of the overlaid fluorescence channel

I suggest to adopt the inverted red chromaticity channel as used for the third channel of the YCC color space, as the green fluorescence visible in your images might be the most stable cell shape related information. I also added a parabolic tonality curve, have left the curvature flow filter as you were using, added an Otsu binarization and a filling transform, so please see the outlines this method provides:

ParallelMap[
HighlightImage[
#,
EdgeDetect@
FillingTransform@
Binarize@
CurvatureFlowFilter[#,10]&@
ColorNegate@ImageApply[1/2+{1/2,-587/1402,-57/701}.#&,#],
"HighlightColor"->Red,Method->{"Boundary",10}
]&,
{img1, img2, img3}
]


# Or try a GradientFilter based approach

ParallelMap[
HighlightImage[#,
FillingTransform@
Closing[#,5]&@
DeleteSmallComponents@
Binarize@

• Thank you (and sorry for the delay). They are actually 2d slices of 3D cysts rather than cells, so what you can see as different thicknesses is partly due to that. Can you explain what you are doing with the ImageApply in the first example? – KraZug May 2 at 15:08
• I should have seen that this is something but not a cell :-) Well, using ImageApply I refer to YCbCr and simply use the negative of the Cr channel, which emphasises the Green fluorencent overlaid channel. I do this since you already have mixed if with the transmission channel.{1/2, -587/1402, -57/701} is nothing but {0.5, -0.418688, -0.0813124} as you find in the third line of the matrix. What I do using ImageApply is to compute the scalar products from RGB to Cr, and ColorNegatecomputes the negative, – UDB May 2 at 17:16
• Do you prefer the solution with the chromaticity? BTW, the pure function ColorNegate@ImageApply[1/2+{1/2,-587/1402,-57/701}.#& simply can be abbreviated using ImageApply[1/2-{1/2,-587/1402,-57/701}.#&. The offset 1/2 is required to put the result on a scale between 0. and 1.. May I ask if you let the 3D cysts grow in a petri dish or thelike? Are these experiments with intestinal organoids? Appears to be quite interesting. – UDB May 2 at 20:29