这里给出灰度图像的模糊算法,彩色图像只要分别对三个通道做模糊即可。
%% spin blur
% 旋转模糊clc;
clear all;
close all;
I=imread('4.jpg');
I=double(I);
% % % I_new=I;
% % % for kk=1:3
% % % I_new(:,:,kk)=Spin_blur_Fun(I(:,:,kk), 30, 30);
% % % end
% % % imshow(I_new/255)
Image=0.2989 * I(:,:,1) + 0.5870 * I(:,:,2) + 0.1140 * I(:,:,3);
[row, col]=size(Image);
Image_new=Image;
Center_X=(col+1)/2;
Center_Y=(row+1)/2;
validPoint=1;
angle=5;
radian=angle*pi/180;
radian2=radian*radian;
Num=30;
Num2=Num*Num;
for i=1:row
for j=1:col
validPoint=1;
x0=j-Center_X;
y0=Center_Y-i;
x1=x0;
y1=y0;
Sum_Pixel=Image(i,j);
for k=1:Num
x0=x1;
y0=y1;
%%% 逆时针
% x1=x0-radian*y0/Num-radian2*x0/Num2;
% y1=y0+radian*x0/Num-radian2*y0/Num2;
%%% 顺时针
x1=x0+radian*y0/Num-radian2*x0/Num2;
y1=y0-radian*x0/Num-radian2*y0/Num2;
x=floor(x1+Center_X);
y=floor(Center_Y-y1);
if(x>1 && x<col && y>1 && y<row)
validPoint=validPoint+1;
Sum_Pixel=Sum_Pixel+Image(y,x);
end
end
Image_new(i,j)=Sum_Pixel/validPoint;
end
end
imshow(Image_new/255);
原图
效果图
效果图