matlab - Matlab中图像的边界去除

标签 matlab image-processing

我正在尝试从 Matlab 中的图像中删除边界。 enter image description here 这个我试过了

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. edge 的输出默认 Sobel 包含形状的一些内部部分。

  2. 灰度一张中减去binary图像!(edge的输出是binary)

    如有任何帮助,我们将不胜感激。

Download原图。

最佳答案

我能想到的一种方法是对图像设置阈值,这样你就有了一个纯白色的物体,稍微缩小物体。然后,使用稍微缩小的对象索引到主要对象蒙版中并删除该区域。此外,稍微增加中间结果的面积以确保移除边界的外边缘。这最终会产生一个挖空的蒙版,该蒙版旨在在一定公差范围内移除对象的边界,同时保持图像的其余部分完好无损。此掩码中为真的任何值都可用于移除边界。

为了可重现性,我已将您的图片上传到 Stack Imgur,这样我们就不必依赖第三方网站来下载您的图片:

enter image description here

这个用于收缩和生长的“一点点”你将不得不玩弄。我选择了 5 个像素,因为这似乎可行。要进行收缩和增长,请分别使用腐 eclipse 和膨胀 imerodeimdilate分别使用 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);

我们现在得到这张图片:

enter image description here

您必须尝试使用​​ Sobel 阈值,因为我实际上不知道您使用什么来获得所需的图像。可以说默认阈值没有给出您预期的结果。

关于matlab - Matlab中图像的边界去除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41189698/

相关文章:

string - Octave - 返回字符串在元胞数组中第一次出现的位置

matlab - 排列矩阵行内的元素

python - 在 python 中复制 MATLAB 联合的索引输出

matlab - 易于编辑的 matlab 函数配置文件

pdf - 如何在我的pdf中读出JBIG2算法使用的符号字典的属性?

python - 使用 OpenCV 提高检测线的准确性

java - 在 r 或其他软件中查找草图图像的坐标(例如扫描为照片格式)

c++ - MATLAB MEX C++ 文件编译错误 g++ command not found

opencv - Haar培训-在哪里获取眼镜图像?

java - 使用 BufferedImage.TYPE_BYTE_BINARY 作为输出的 Sobel 边缘检测