2013-06-26 126 views
1

我想在matlab中寫一個簡單的二進制重建算法。到目前爲止,我知道這個算法是'開放'後使用長大後連接到開放的原始圖像的件。我還發現,它可以去除與大對象不相交的小區域,而不會扭曲大對象的小特徵。二進制重構算法

這是僞代碼:

1. J = I o Z; %open input image with some structre element 
2. T = J; 
3. J = J  Z(k) % Dilate J with Z(k). this is my first problems. if Z in first line is structure element, then what is Z(k)? 
4. J = I AND J % my second problem. how to AND these two on matlab. 
5. if J ~= T go to 2. 
6. else stop and J is the reconstructed image. 

假設我們有這樣的圖像作爲輸入:

input image

重建圖像看起來像:

reconstructed image
上述上面提到的代碼,到目前爲止我寫道:

img = imread ('Input.jpg'); 
img = im2bw(img, 0.8); 
J = bwmorph(img,'open'); 
T = J; 
J = bwmorph(J, 'dilate'); 

我的問題是如何在matlab中正確結束這個。 我的第二個問題是,如果我要使用'imdilate'而不是'bwmorph',應該是我提到的示例中的結構元素?

在此先感謝。

+1

上傳圖片到web服務(http://tinypic.com/),並張貼鏈接到圖片。 – Shai

+0

請更具體地說明你正在嘗試做什麼。請不要發送給我們閱讀論文 - 只需提供您正在嘗試的內容的簡要說明以及爲什麼您在這方面遇到問題。 – Shai

+0

我用(http://imgur.com)仍然有錯誤。這是我第一次做的: ![輸入圖像](http://i.imgur.com/34tXXPC.jpg) – Zahra

回答

1

基於上述意見,你會想要做這樣的事情:

img = imread ('Input.jpg'); 
img = im2bw(img, 0.8); 
J = bwmorph(img,'open'); 
THRESH = 0; 
while (1) 
    T = J; 
    J = bwmorph(J, 'dilate'); 
    J = img & J; 
    if (sum(T(:) - J(:)) <= THRESH) 
     break; 
    end 
end 

基於僞代碼,你可以設置THRESH = 0(即T = j),但在現實生活中,你可能接受一些小的差異。

+0

@ Hugh Nolan謝謝,就是這樣。根據你的評論,我想也可以使用[this](http://i.imgur.com/Sk2HLxN.jpg)作爲結構元素並寫下: J = imopen(img,se); T = J; (J〜= T) T = J; J = imdilate(J,se); J = I & J; end – Zahra