matlab 边缘光滑,如何使用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);
結果:
這有點粗糙,但這會給你一個開始.您可以嘗試調整迭代次數以及圓形濾波器和中值濾波器的大小.嘗試用平均值等改變中位數.
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的matlab 边缘光滑,如何使用matlab来平滑图片的边缘的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: if var matlab,matlab
- 下一篇: php import用法,JavaScr