2016-12-16 96 views
4

我試圖從Matlab的圖像中刪除邊界。 enter image description here 我已經試過這邊界在Matlab中刪除圖像

clc,clear,clf 

Im=im2double(imread('Im.png')); 
imshow(Im);title('Original Image') 
pause(.5) 
imshow(edge(Im));title('after Sobel') 
pause(.5) 
imshow(Im-edge(Im));title('Im-edge(Im)') 

,其結果是

enter image description here

但有兩個明顯的問題:

  1. 默認Sobel輸出的edge含有形狀的一些內部部分。
  2. 減去gray scale一個binary圖像!(的edge輸出binary

    任何幫助,將不勝感激。

Download original image。

+0

你是什麼意思的「刪除邊界」?你的意思是刪除物體的白色邊界?您在文章頂部的所需結果包含對象內部的邊緣像素,因此您所描述的內容與您期望的結果不會相互對應。 – rayryeng

+0

是啊只是想刪除形狀周圍的白色帶,所需的圖像已被顯示在二進制模式。 – asys

+0

的主要目標是確定照片中的接縫。這張照片是通過hough lines進行背景分割後獲得的 – asys

回答

1

我可以想到的一種方式是對圖像進行閾值處理,以便獲得一個堅實的白色物體,並通過一點點縮小物體。然後,使用略微減少的對象索引到主對象遮罩中並刪除此區域。此外,稍微增加中間結果的面積以確保刪除邊界的外邊緣。這將最終產生一個挖空的面具,旨在在一定的容差範圍內移除物體的邊界,同時保持圖像的其餘部分不變。這個掩碼中的任何真值都可以用來刪除邊界。

對於重現,我已經上傳你的圖片堆棧Imgur,使我們不必依靠第三方網站下載你的形象:

enter image description here

這「一點」爲收縮和增長,你將不得不玩。我選擇了5個像素,因爲這似乎工作。爲了縮小和增長,分別使用imerodeimdilate分別使用侵蝕和膨脹,並且使用了5×5像素正方形的結構元素。

% Read from Stack Imgur directly 
im = imread('https://i.stack.imgur.com/UJcKA.png'); 

% Perform Sobel Edge detection 
sim = edge(im, 'sobel'); 

% Find the mask of the object 
mask = im > 5; 

% Shrink the object 
se = strel('square', 5); 
mask_s = imerode(mask, se); 

% Remove the inner boundary of the object 
mask(mask_s) = false; 

% Slightly enlarge now to ensure outer boundary is removed 
mask = imdilate(mask, se); 

% Create new image by removing the boundaries of the 
% edge image 
sim(mask) = false; 

% Show the result 
figure; imshow(sim); 

我們現在得到這個圖片:

enter image description here

你必須玩的索貝爾門檻,因爲我確實不知道你用什麼來得到你想要所需的圖像。只要說缺省的閾值並不能給出你的預期結果。