如何使用matlab来平滑图片的边缘 [英] how to use matlab to smooth the edge of a picture

查看:2109
本文介绍了如何使用matlab来平滑图片的边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面看到一张图片,但图片边缘非常难看。
我想使用matlab编程来平滑图片的边缘并使其看起来更漂亮,任何想法或方法都有意义吗?



谢谢!!这是一个选项(编辑过):

  I = im2double(imread('ht4Za.jpg')); 
%分割对象:
gs = rgb2gray(I);
Object = ~im2bw(gs,graythresh(gs));

%使面具平滑:
BW = bwmorph(bwconvhull(Object),'erode',5);
Mask = repmat(BW,[1,1,3]);

%迭代开仓操作:
Interp = I;
表示k = 1:5
Interp = imopen(Interp,strel('disk',20));
end

%保留原始像素,添加新生成的像素并平滑输出​​:
插值(:,:,1)= medfilt2(imadd(I(:,: ,1)。* Object,Interp(:,:,1)。*〜(BW == Object)),[4 4]);
插值(:,:,2)= medfilt2(imadd(I(:,:,2)。* Object,Interp(:,:,2)。*〜(BW == Object)),[4 4]);
Interpolated(:,:,3)= medfilt2(imadd(I(:,:,3)。* Object,Interp(:,:,3)。*〜(BW == Object)),[4 4]);

%显示结果:
Masked = imadd(Interpolated。* im2double(Mask),im2double(~Mask));
imshow(蒙面);

结果:





这有点粗糙,但是给你一个开始。您可以尝试调整迭代次数以及循环滤波器和中值滤波器的大小。尝试用平均值等改变中位数


I get a picture below but the picture has a very ugly edges. I want to use matlab programming to smooth the edges of the picture and make it look more pretty,any ideas or ways make sense?

thank you!!!

解决方案

Here is an option (edited):

I = im2double(imread('ht4Za.jpg'));
% Segment the object:
gs = rgb2gray(I);
Object=~im2bw(gs, graythresh(gs));

% Smoothen the mask:
BW = bwmorph(bwconvhull(Object), 'erode', 5);
Mask=repmat(BW,[1,1,3]);

% Iterate opening operation:
Interp=I;
for k=1:5
    Interp=imopen(Interp, strel('disk',20));
end

% Keep original pixels, add the newly generated ones and smooth the output:
Interpolated(:,:,1)=medfilt2(imadd(I(:,:,1).*Object, Interp(:,:,1).*~(BW==Object)), [4 4]);
Interpolated(:,:,2)=medfilt2(imadd(I(:,:,2).*Object, Interp(:,:,2).*~(BW==Object)), [4 4]);
Interpolated(:,:,3)=medfilt2(imadd(I(:,:,3).*Object, Interp(:,:,3).*~(BW==Object)), [4 4]);

% Display the results:
Masked=imadd(Interpolated.*im2double(Mask), im2double(~Mask));
imshow(Masked);

Result:

It's a bit rough, but that'll give you a start. You can try to fiddle with the number of iteration and the size of the circular filter and the median filter. Try changing the median with average, etc.

这篇关于如何使用matlab来平滑图片的边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆