2016-03-15 185 views
1

我正在處理一個圖像處理項目,其中我充斥了原始圖像。圖像處理洪水填充圖像

現在

  1. 我需要刪除在這張照片是手的圖像周圍的白線的噪聲。我想通過將這些白線合併爲黑色背景色來刪除這些白線。

  2. 我需要將充滿水的區域的灰色(值爲127)更改爲白色。請注意背景顏色應該保持黑色。

enter image description here


這是this question後續。該圖像是用this answer中的代碼獲得的。

+0

好涼。你到目前爲止嘗試了什麼? –

+0

你在這幅圖像中氾濫了什麼? – Guiroux

+1

看看兩種可能的解決方案: 1.縮小圖像。它將刪除小功能,但不完全。 2.做侵蝕,然後擴張。它將完全移除小於侵蝕/擴張半徑的特徵。 – ZuOverture

回答

3

在您的問題中生成圖像的代碼可在your previous question中找到。

因此,我們知道充水區域的價值爲127


從該圖像開始,可以容易地獲得洪水填充區域的掩模爲:

Mat1b mask = (img == 127); 

enter image description here

單通道掩模將有值要麼黑色0或白色255

如果你想有一個彩色圖像,你需要創建一個同樣大小的黑色初始化圖像爲img,並根據面膜自己喜歡的顏色(綠色在這裏)設置像素:

// Black initialized image, same size as img 
Mat3b out(img.rows, img.cols, Vec3b(0,0,0)); 

Scalar some_color(0,255,0); 
out.setTo(some_color, mask); 

enter image description here

代碼以供參考:

#include <opencv2/opencv.hpp> 
using namespace cv; 

int main() 
{ 
    Mat1b img = imread("path_to_floodfilled_image", IMREAD_GRAYSCALE); 

    // 127 is the color of the floodfilled region 
    Mat1b mask = (img == 127); 

    // Black initialized image, same size as img 
    Mat3b out(img.rows, img.cols, Vec3b(0,0,0)); 

    Scalar some_color(0,255,0); 
    out.setTo(some_color, mask); 

    // Show results 
    imshow("Flood filled image", img); 
    imshow("Mask", mask); 
    imshow("Colored mask", out); 
    waitKey(); 

    return 0; 
} 
+0

Thankyou。這一個工程。你一直很有幫助。 –

+0

很高興幫助; D – Miki

+0

請檢查下面的評論回答 –