use*_*274 4 matlab image-processing
我在下面看到一张照片,但照片边缘非常难看.我想使用matlab编程来平滑图片的边缘并使其看起来更漂亮,任何想法或方法都有意义吗?
谢谢!!!
这是一个选项(已编辑):
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);
Run Code Online (Sandbox Code Playgroud)
结果:

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