首页 > 解决方案 > 在单元格图像中查找椭圆

问题描述

我有组织切片的图像,我想从中分离出所有隐窝,即您可以在此图像中看到的大椭圆(在二进制阈值处理之后):

组织切片

在这里,它们看起来像圆形,但在一般情况下,它们形成近似椭圆。

我尝试在 openCV 中使用 canny、findContours 或 hough_ellipse 但没有成功。

有任何想法吗?

标签: algorithmimage-processingellipse

解决方案


我没有花太长时间来完善这个答案,但它应该让你开始,然后你可以整理它。基本思想是将黄色转换为白色,将其他所有颜色转换为黑色:

#!/usr/bin/env python3

import numpy as np
import cv2
from scipy.ndimage.morphology import distance_transform_edt

# Load the image
im = cv2.imread('cells.png')

# Form binary image which is white where orginal is yellow and black everywhere else
B = np.zeros_like(im[...,0])
B = im == [38, 230, 253]
cv2.imwrite('tmp.png', (B*255).astype(np.uint8))

这让你:

在此处输入图像描述

现在,做一个距离变换

# Get distance transform
distance = distance_transform_edt(B)

# Normalise for contrast and save
cv2.normalize(distance, distance, 0, 255, cv2.NORM_MINMAX)
cv2.imwrite('result.png', distance.astype(np.uint8))

在此处输入图像描述

所以,基本上,结果图像中的点越亮,它离细胞壁和其他东西就越远。然后,您可以在此处找到最大值并使用它们进行进一步检查。


推荐阅读