0
$\begingroup$

I need to find the contours for each of the instances of microscopic cells in a binary image mask of dimensions 256 x 256 shown below.

Microscopic image mask

My approach involves thresholding the image to get a binary mask (foreground = 1,background = 0) as follows and then finding the contours of each instance of cell.

ret, binary = cv2.threshold(mask,0,255,cv2.THRESH_BINARY_INV)
contours, hierarchy = cv2.findContours(binary,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

After binary thresholding

The instances that are very close to each other are combined resulting in a single contour which is undesirable. Is there a way to achieve separate contours for each mask based on color?

$\endgroup$

2 Answers 2

1
$\begingroup$

well you discard that information the moment you convert to binary (your input is not binary – it has more than 2 values). So, don't do that.

$\endgroup$
0
$\begingroup$

I assume you threshold the image in order to be able to run cv.findContours on it. Here it would be better to use cv.split. split gives you three channels(one for every color) and thus the edges should be maintained (in most cases).

You could then either discard two of the channels(which would give you similar results to what you already have) or run findContours on all three of them and combine the result.

As cv.findContours requires a binary image, you'll probably have to do the latter. If you combine the resulting contours for every channel(binary or or just an addition should do the trick), you should get what you expect.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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