我正在尝试从 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)')
结果是
但是有两个明显的问题:
edge
的输出默认Sobel
包含形状的一些内部部分。从
灰度
一张中减去binary
图像!(edge
的输出是binary
)如有任何帮助,我们将不胜感激。
Download原图。
最佳答案
我能想到的一种方法是对图像设置阈值,这样你就有了一个纯白色的物体,稍微缩小物体。然后,使用稍微缩小的对象索引到主要对象蒙版中并删除该区域。此外,稍微增加中间结果的面积以确保移除边界的外边缘。这最终会产生一个挖空的蒙版,该蒙版旨在在一定公差范围内移除对象的边界,同时保持图像的其余部分完好无损。此掩码中为真的任何值都可用于移除边界。
为了可重现性,我已将您的图片上传到 Stack Imgur,这样我们就不必依赖第三方网站来下载您的图片:
这个用于收缩和生长的“一点点”你将不得不玩弄。我选择了 5 个像素,因为这似乎可行。要进行收缩和增长,请分别使用腐 eclipse 和膨胀 imerode
和 imdilate
分别使用 5 x 5 像素正方形的结构元素。
% Read from Stack Imgur directly
im = imread('/image/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);
我们现在得到这张图片:
您必须尝试使用 Sobel 阈值,因为我实际上不知道您使用什么来获得所需的图像。可以说默认阈值没有给出您预期的结果。
关于matlab - Matlab中图像的边界去除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41189698/