简体   繁体   English

如何使用Python / OpenCV从医学图像中分割单个细胞?

[英]How to segment individual cells from a medical image using Python/OpenCV?

So I am trying to segment individual cells from a loaded image using Python/OpenCV. 所以我试图使用Python / OpenCV从加载的图像中分割单个单元格。 My code currently is able to mask the cells, but I would like to segment individual cells and save them as separate images. 我的代码当前可以掩盖单元格,但是我想分割单个单元格并将其保存为单独的图像。

原始图像

遮罩的图像

So the output would be one of those single cells you see in the above (purposes for downstream use with 2D convnet) 因此输出将是您在上面看到的那些单个单元格之一(用于2D convnet的下游使用)

img_dir = '/path'
img = cv2.imread(img_dir, 0)
plt.imshow(img, cmap = 'gray', interpolation = 'bicubic') # swap hot 
for gray

# draw a contour image with fixed threshold 50
fig = plt.figure()
ax = fig.add_subplot(111)
ax.contourf(img, levels=[0, 10, 20, 30,  40, 50, 60, 70, 80, 120], 
colors='k')
plt.show()

res = cv2.resize(img,None,fx=0.5, fy=0.5, interpolation = 
cv2.INTER_CUBIC)

Actually in this problem, segmentation is the process of separating the cells from the background which you already accomplished. 实际上,在此问题中,分割是将单元格与已完成的背景分离的过程。

Being left with a binary image you have to perform a blob detection. 留下二进制图像后,您必须执行斑点检测。 After optionally filtering out everything that is of unwanted size or shape you are left with a list of blobs, each representing a cell I guess. 在有选择地过滤掉所有大小或形状不想要的东西之后,您将看到一系列斑点,每个斑点代表一个单元格。

http://docs.opencv.org/trunk/dd/d49/tutorial_py_contour_features.html http://docs.opencv.org/trunk/dd/d49/tutorial_py_contour_features.html

https://www.learnopencv.com/blob-detection-using-opencv-python-c/ https://www.learnopencv.com/blob-detection-using-opencv-python-c/

You then compute the so bounding rect of each of those blobs and use that rectangle to create a roi to crop the subimages. 然后,您可以计算每个斑点的边界矩形,并使用该矩形创建一个roi来裁剪子图像。

How to crop an image in OpenCV using Python 如何使用Python在OpenCV中裁剪图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM