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

相關問題