2016-12-16 94 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

你必须玩的索贝尔门槛,因为我确实不知道你用什么来得到你想要所需的图像。只要说缺省的阈值并不能给出你的预期结果。