Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无需绘图即可检测等高线相交_Python_Opencv_Computer Vision_Contour - Fatal编程技术网

Python 无需绘图即可检测等高线相交

Python 无需绘图即可检测等高线相交,python,opencv,computer-vision,contour,Python,Opencv,Computer Vision,Contour,我正致力于检测显微镜图像中的细胞,如下图所示。由于显微镜载玻片上的缺陷,通常会绘制虚假轮廓,如下图图例下方的轮廓 我现在用它来清理这些东西。这是基本的想法 创建背景图像 blank=np.zerosimage.shape[0:2] background_image=cv2.drawContoursblank.copy,background_轮廓,0,1,-1 对于等高线中的i、c: 创建轮廓图像 contour_image=cv2.drawContoursblank.copy,轮廓,i,1,-1

我正致力于检测显微镜图像中的细胞,如下图所示。由于显微镜载玻片上的缺陷,通常会绘制虚假轮廓,如下图图例下方的轮廓

我现在用它来清理这些东西。这是基本的想法

创建背景图像 blank=np.zerosimage.shape[0:2] background_image=cv2.drawContoursblank.copy,background_轮廓,0,1,-1 对于等高线中的i、c: 创建轮廓图像 contour_image=cv2.drawContoursblank.copy,轮廓,i,1,-1 创建焦点轮廓+背景的图像 总图像=np。其中背景图像+轮廓图像>0,1,0 检查轮廓是否在正空间之外 如果total_image.sum>background_image.sum: 持续
这是意料之中的事;如果总图像面积大于背景图像面积,则c必须位于感兴趣区域之外。但是绘制所有这些等高线的速度非常慢,检查数千条等高线需要几个小时。是否有一种更有效的方法来检查轮廓是否重叠,而不需要绘制轮廓?

我认为目标是从进一步分析中排除外部轮廓?如果是这样,最简单的方法是使用红色背景轮廓作为遮罩。然后使用遮罩图像检测蓝色细胞

# Create image of background
blank = np.zeros(image.shape[0:2], dtype=np.uint8)
background_image = cv2.drawContours(blank.copy(), background_contour, 0, (255), -1)

# mask input image (leaves only the area inside the red background contour)
res = cv2.bitwise_and(image,image,mask=background_image )

#[detect blue cells]

假设您试图在不同的轮廓上找到重叠的点

将等高线视为

vector<vector<Point> > contours;
..... //obtain you contrours.

vector<Point> non_repeating_points;
for(int i=0;i<contours.size();i++)
{
    for(int j=0;j<contours[i].size();j++)
    {
        Point this_point= countour[i][j];
        for(int k=0;k<non_repeating_points.size();k++)
        {//check this list for previous record
            if(non_repeating_points[k] == this_point)
            {
               std::cout<< "found repeat points at "<< std::endl;
               std::cout<< this_point << std::endl;
               break;
            }
        }
        //if not seen before just add it in the list
        non_repeating_points.push_back(this_point);
    }
}
我只是没有编译就写了它。但我想你能理解这个想法

你提供的信息还不够。 如果你想找到最近的连通边界。没有重叠

可以在非重复点[k]附近声明一个本地簇。称之为环绕非重复点[k]; 您可以控制可视为截距的距离,并在此环绕中推送所有这些点[k]

然后只需在循环中检查
如果环绕非重复点[k]==此点

谢谢!我用的方式和你建议的略有不同。我首先找到了背景,然后像你一样使用分辨率蒙版创建了一个新的图像,用于查找轮廓。通过首先删除垃圾背景空间,我完全避免了检查生成轮廓的问题。