如何平滑多分量图像的边缘?
How do i smoothen the edges of a multicomponent image?
我有一张图片,我想平滑它的边缘。获得更准确的细分存在一些挑战。然而,我通过采纳来自 的建议得到了解决方案。
原图在这里:
还有分割图像
我使用的代码如下:
%# Read in image
Img = imread('image_name.png');
%# Apply filter
h = fspecial('average');
Img = imfilter(Img, h);
%# Segment image
Img = rgb2gray(Img);
thresh = multithresh(Img, 2);
Iseg = imquantize(Img, thresh);
figure, imshow(Iseg,[]), title('Segmented Image');
%# separate channels
blackPixels = (Iseg == 1);
grayPixels = (Iseg == 2);
whitePixels = (Iseg == 3);
%# grow white channel
whitePixels_dilated = imdilate(whitePixels, strel('disk', 4, 4));
%# Add all channels
Iseg(whitePixels | whitePixels_dilated) = 3;
figure, imshow(Iseg,[]);
我现在的挑战是平滑实体 (whitePixels) 的边缘或所有对象的边缘。我不知道该怎么做。我试过过滤,但只能去掉小点。
请提供任何帮助、想法或建议或建议,我们将不胜感激。谢谢。
我建议多次应用矩形滤镜。以下是如何执行此操作的方法:
I=imread('Orl1r.png');
I_gray=rgb2gray(I);
I_filtered=I_gray; % initialize the filtered image
for ii=1:10
I_filtered=imfilter(I_filtered,1/25*ones(5)); % apply rectangular-filter multiple times
end
figure
subplot(1,2,1)
imshow(I,[0 255]);
subplot(1,2,2);
imshow(I_filtered,[0 255])
过滤后的图像如下所示:
希望这对您有所帮助。
编辑:除了矩形滤波器,您还可以使用高斯滤波器。但是多次申请的一般想法仍然存在。您可以使用 f=fspecial('gaussian',5,6)
为 exapmle 创建一个高斯滤波器,它创建一个带有 sigma=6.
的 5x5
filtermask
我有一张图片,我想平滑它的边缘。获得更准确的细分存在一些挑战。然而,我通过采纳来自
原图在这里:
还有分割图像
我使用的代码如下:
%# Read in image
Img = imread('image_name.png');
%# Apply filter
h = fspecial('average');
Img = imfilter(Img, h);
%# Segment image
Img = rgb2gray(Img);
thresh = multithresh(Img, 2);
Iseg = imquantize(Img, thresh);
figure, imshow(Iseg,[]), title('Segmented Image');
%# separate channels
blackPixels = (Iseg == 1);
grayPixels = (Iseg == 2);
whitePixels = (Iseg == 3);
%# grow white channel
whitePixels_dilated = imdilate(whitePixels, strel('disk', 4, 4));
%# Add all channels
Iseg(whitePixels | whitePixels_dilated) = 3;
figure, imshow(Iseg,[]);
我现在的挑战是平滑实体 (whitePixels) 的边缘或所有对象的边缘。我不知道该怎么做。我试过过滤,但只能去掉小点。 请提供任何帮助、想法或建议或建议,我们将不胜感激。谢谢。
我建议多次应用矩形滤镜。以下是如何执行此操作的方法:
I=imread('Orl1r.png');
I_gray=rgb2gray(I);
I_filtered=I_gray; % initialize the filtered image
for ii=1:10
I_filtered=imfilter(I_filtered,1/25*ones(5)); % apply rectangular-filter multiple times
end
figure
subplot(1,2,1)
imshow(I,[0 255]);
subplot(1,2,2);
imshow(I_filtered,[0 255])
过滤后的图像如下所示:
希望这对您有所帮助。
编辑:除了矩形滤波器,您还可以使用高斯滤波器。但是多次申请的一般想法仍然存在。您可以使用 f=fspecial('gaussian',5,6)
为 exapmle 创建一个高斯滤波器,它创建一个带有 sigma=6.
5x5
filtermask