0

I have tried to segment cells in H&E-stained histopathological images using Watershed algorithm of opencv-python. The code I used is totally same as Docs opencv code in link below.

Watershed Code Source

Result Image

But as you see the result, the performance of segmentation is not that much good. Some cells could not be detected.

I want to detect all of cells at a time in that image.

In the case of cell in biomedical, I think this is more sensitive than normal object segmentation.

In original code, I added and applied two Blur algorithms before using cv2.morphologyEx().

img = cv2.imread("Path_of_Image")
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

# Convert to Binary Image
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

kernel = np.ones((3, 3), np.uint8)
opening = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel, iterations=2)

sure_bg = cv2.dilate(opening, kernel, iterations=3)
dist_transform = cv2.distanceTransform(opening, cv2.DIST_L2, 5)

ret, sure_fg = cv2.threshold(dist_transform, 0.5*dist_transform.max(), 255, 0)

sure_fg = np.uint8(sure_fg)

unknown = cv2.subtract(sure_bg, sure_fg)

ret, markers = cv2.connectedComponents(sure_fg)

markers = markers + 1
markers[unknown == 255] = 0

markers = cv2.watershed(img_rgb, markers)
img_rgb[markers == -1] = [255, 0, 0]

images = [gray, thresh, sure_bg, dist_transform, sure_fg, unknown, markers, img_rgb]
titles = ['Gray','Binary','Sure BG','Distance','Sure FG','Unknow','Markers','Result']

plt.figure(figsize=(12, 12))
for i in range(len(images)):
    plt.subplot(2, 4, i + 1),
    plt.imshow(images[i], cmap='gray'),
    plt.title(titles[i]),
    plt.xticks([]),plt.yticks([])
#     plt.figure(figsize= (5, 5))

# plt.tight_layout()
plt.show()

There was a litte bit improvement, but still need changes.

How can I deal with this problem? Do I have to more examine Marker value or something?

I wonder your thinking.

Thank you in advance.

[Add] This is Original Image. Original Image

hailey
  • 23
  • 5
  • Post your image. This forum wants reproducible code and example. Why did it not work or help? – fmw42 Jan 18 '23 at 02:17
  • The image I uploaded was not properly attached. I fixed it now – hailey Jan 18 '23 at 02:27
  • I'd recommend AI for this. semantic/instance segmentation. low level image processing, for such varied appearances, is at least a decade out of date. if you wanna stick with low level stuff, work with color information (staining). we'll need source data, not just a screenshot of a plot. – Christoph Rackwitz Jan 18 '23 at 11:31
  • Please provide the original coloured input image with orignial resolution. – Markus Jan 18 '23 at 13:58
  • I added original image below! I processed by using this image. – hailey Jan 19 '23 at 00:24
  • It seems to me that you just need to adjust some thresholds for your application. – Cris Luengo Jan 19 '23 at 00:55
  • I must admit that I am struggeling to do the segmentation even manually. Can you give an example of how you as an expert would properly segment the image? Can you define rules, how the segmentation should be done? – Markus Jan 19 '23 at 11:41

0 Answers0