【问题标题】:MATLAB: Segment ImageMATLAB:分割图像
【发布时间】:2023-03-06 03:09:01
【问题描述】:

MATLAB 和图像处理新手。我需要知道如何将图像分割成前景和背景,然后生成二进制图像作为输出。

我需要这个作为输出:

我已经尝试通过在线教程来实现这一点,这就是我设法得到的:

这是一个好的开始,但不是我所需要的。

我的代码:

I = imread('AssignmentInput.jpg');
figure;
imshow(I);
title('Step-1: Load input image');


img_filtered = I;
for c = 1 : 3
    img_filtered(:, :, c) = medfilt2(I(:, :, c), [3, 3]);
end
figure; 
imshow(img_filtered);
title('Step-3:Noise Removal');

H = fspecial('gaussian'); % Create the filter kernel.
img_filtered = imfilter(img_filtered,H); % Blur the image.
Mask = im2bw(img_filtered, 0.9); % Now we are generating the binary mask.
img_filtered([Mask, Mask, Mask]) = 0; % Now we have the image.
figure;
imshow(img_filtered);
title('Step-5:Segmented Image');

【问题讨论】:

  • 这看起来很接近我。两张图有什么区别?
  • 基本上我将颜色保留在第三张图片中,我只需要它作为第二张图片中显示的黑色和白色。
  • 这只是因为您将蒙版应用于原始图像。试试imshow(~Mask)
  • 哦,我真是个白痴!老实说,我没有看到。非常感谢您指出这一点,我没有充分观察我的代码是我的错。
  • 很高兴为您提供帮助。很容易陷入你认为你需要做的事情,而不是看看你已经拥有的东西。 :)

标签: matlab image-processing binary image-segmentation


【解决方案1】:

为了更好的去噪过程和更清晰的前景和背景分离,您还可以添加形态学操作,例如:

se = strel('square',2);
I = imclose(I,se);

您也可以尝试“strel”类的不同变体。下图是imclose操作后的2像素正方形

【讨论】:

    猜你喜欢
    • 2017-04-20
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    • 2016-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多