0

目标: 我想检测叶片图像的某些区域。 我发现我的相关问题,接近这个segment object(leaf) which is on the white paper using image processing(从白色背景中删除叶)但我的超越它,它旨在提取/分割叶的病变区域。如何分割叶片图像中感兴趣的区域

问题: 如何准确地分割和提取图像中叶子的病变区域。

我尝试:
1. INRANGE()函数的OpenCV -threshold绿颜色,所以我不会对非绿色区域(棕色,灰色等),我可以做几个INRANGE值将有望消除绿色;我施加高斯模糊,从RGB转换为HSV分割

链接到文件 image1的,图像2输入和结果之前:
IMAGE1: 结果:格林被分段(被认为不是很准确),但我仍然不知道如何提取非绿色区域(如下一步)

镜像2: 结果:被列入黑暗的小圆圈/考虑绿色据称不应

我是新来的OpenCV(也是C++)和我已看过一些技术(如聚类方法模糊C和K-手段,等)为分割,但我不能决定哪种分割技术用于我的图像。我也从我读过的文章中了解到,通用分割技术不适用于所有图像。因此,我想知道哪种技术(聚类方法?基于区域的直方图?等)或过程最适用于我有的图像种类,以准确地分割所述图像。

非常感谢。

回答

4

刚刚尝试下面的步骤

创建模板图片: -首先,你需要为叶创建蒙版图像,你需要做的阈值,找到轮廓(最大),画出轮廓(用实心)等...为了消除边缘效应,你需要侵蚀你的面具,这会产生更好的效果。

enter image description hereenter image description here

enter image description hereenter image description here

下面的代码片段会做上述

Mat thr; 
Mat src=imread("image2.png",1); //Your processed image 
cvtColor(src,thr,CV_BGR2GRAY); 
threshold(thr,thr,180,255,THRESH_BINARY_INV); 

vector< vector <Point> > contours; // Vector for storing contour 
vector<Vec4i> hierarchy; 
int largest_contour_index=0; 
int largest_area=0; 
Mat mask(src.rows,src.cols,CV_8UC1,Scalar::all(0)); //create destination image 
findContours(thr.clone(), contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); // Find the contours in the image 
for(int i = 0; i< contours.size(); i++) // iterate through each contour. 
    { 
    double a=contourArea(contours[i],false); // Find the area of contour 
    if(a>largest_area){ 
    largest_area=a; 
    largest_contour_index=i;    //Store the index of largest contour 
    } 
    } 
drawContours(mask,contours, largest_contour_index, Scalar(255,255,255),CV_FILLED, 8, hierarchy); // Draw the largest contour using previously stored index. 
int dilation_size = 2; 
Mat element = getStructuringElement(MORPH_RECT, 
             Size(2*dilation_size + 1, 2*dilation_size+1), 
             Point(dilation_size, dilation_size)); 
erode(mask, mask, element); 

提取绿色区域: -这里你应该用HSV色彩空间,INRANGE等。正如你的问题中提到的那样。

enter image description hereenter image description here

Mat HSV,hsv_thr,dst; 
cvtColor(src,HSV,CV_BGR2HSV); 
inRange(HSV,Scalar(20,10,10),Scalar(90,255,255),hsv_thr); 

以上图片bitwise_not: -这里你应该用上面创建的面具。

enter image description hereenter image description here

bitwise_not(hsv_thr, dst, mask); 

绘制发病面积: - 再次在这里,您需要做的找到轮廓画出轮廓等...

enter image description hereenter image description here

findContours(dst.clone(), contours, hierarchy,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); // Find the contours in the image 
    for(int i = 0; i< contours.size(); i++) // iterate through each contour. 
     drawContours(src,contours, i, Scalar(0,0,255),1, 8, hierarchy); 

你可以通过适当的滤波,阈值提高结果使用适当的hsv范围等等......另外上面的算法认为你的背景总是白色的,对于其他背景你需要改变创建遮罩图像的步骤。

希望这些有帮助...

+0

这是我真正需要的。这确实是非常有用的。 我只想问一下,有没有其他可用于感兴趣区域(非绿色)区域的格式?我想要一个roi(不是二进制)的灰度或彩色图像版本进行进一步处理。 – user3339658

+0

在这里使用这个答案[link](http://stackoverflow.com/questions/10176184/with-opencv-try-to-extract-a-region-of-a-picture-described-by-arrayofarrays#),I试图让轮廓内的区域(其中只有roi是可见的,其他人是黑色的),但我只能在图像的第一轮廓内获得该区域,而不是所有轮廓。你能给我一些关于如何获得所有轮廓内容的指针吗?非常感谢你提前。 :) – user3339658

+0

只需使用[Mat :: copyTo()](http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-copyto)和轮廓作为蒙版。 – Haris

相关问题