MATLAB实现图像羽化处理(图像羽化处理)



相关的程序:

%{
时间:2014年9月24日19:51:39
整理:天空之恋
参考:http://blog.csdn.net/yangtrees/article/details/9210153
原文使用opencv编写的,这个地方稍微修改了一下改成MATLAB实现的
经过实际测试效果还是可以的。


%}
clc;
clear all;
src=imread('test.png');
subplot(121)
imshow(src),title('原始图像');
srcgray=rgb2gray(src);%首先进行灰度变换
[height,width] = size(srcgray);%获得图像的高度和宽度
centery=width/2;
centerx=height/2;


maxv=centerx*centerx+centery*centery;
msize=0.5;%改变这个值,可以改变羽化效果,羽化明显或者不明显
minv=(maxv*(1-msize));
diff=maxv-minv;
%ratio=width>height? height/width : width/height;
if width>height
    ratio=(height/width);
else
    ratio=(width/height);
end
height=height-1;
width=width-1;
for x=1:height
    for y=1:width
        r=src(x,y,1);
        g=src(x,y,2);
        b=src(x,y,3);        
        dy=centery-y;      
        dx=centerx-x;     
        dstsq=(dx*dx+dy*dy);        
        v=((dstsq/diff)*128); %原文这个地方是255,我们实际测试的时候
        %发现这个地方应该改成128,否则效果会过于明显
        r=r+v;
        g=g+v;
        b=b+v;        
      if r>255
          r=255;
      elseif r<0
          r=0;
      end      
      if g>255
        g=255;
      elseif g<0
         g=0;
      end
      
      if b>255
          b=255;
      elseif b<0
          b=0;
      end
      dst(x,y,1)=uint8(r);
      dst(x,y,2)=uint8(g);
      dst(x,y,3)=uint8(b);      
    end    
end
subplot(122);
imshow(dst),title('羽化结果');
       

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值