首页 > 代码库 > PS 滤镜—— 径向模糊
PS 滤镜—— 径向模糊
这里给出灰度图像的模糊算法,彩色图像只要分别对三个通道做模糊即可。
%%% radiation blur
%%%
clc;
clear all;
close all;
I=imread(‘4.jpg‘);
I=double(I);
% Image=I;
Image=0.2989 * I(:,:,1) + 0.5870 * I(:,:,2) + 0.1140 * I(:,:,3);
[row, col]=size(Image);
Image_new(1:row,1:col)=255;
Center_X=(col+1)/2;
Center_Y=(row+1)/2;
alpha=0.85;
for i=1:floor(Center_Y)
for j=floor(Center_X)+1:col
% 第一象限
x1=j-Center_X;
y1=Center_Y-i;
T1=Image(i,j);
% 第三象限
x3=-x1;
y3=-y1;
x_image=floor(Center_X+x3);
y_image=floor(Center_Y-y3);
i3=y_image;
j3=x_image;
T3=Image(y_image,x_image);
% 第二象限
x2=-x1;
y2=y1;
x_image=floor(Center_X+x2);
y_image=floor(Center_Y-y2);
i2=y_image;
j2=x_image;
T2=Image(y_image,x_image);
%第四象限
x4=x1;
y4=-y1;
x_image=floor(Center_X+x4);
y_image=floor(Center_Y-y4);
i4=y_image;
j4=x_image;
T4=Image(y_image,x_image);
k=y1/x1;
x_start=x1*alpha;
y_start=k*x_start;
x_end=x1;
y_end=y1;
x=x_start;
y=y_start;
if(x1>y1)
Num_Pixel=floor(x_end-x_start)+1;
for x=x_start:x_end-1
y0=k*(x+1);
% 第一象限
x1=x+1;
y1=round(y0);
% y=y+1;
x_image=floor(Center_X+x1);
y_image=floor(Center_Y-y1);
T1=T1+Image(y_image,x_image);
% 第三象限
x3=-x1;
y3=-y1;
x_image=floor(Center_X+x3);
y_image=floor(Center_Y-y3);
T3=T3+Image(y_image,x_image);
% 第二象限
x2=-x1;
y2=y1;
x_image=floor(Center_X+x2);
y_image=floor(Center_Y-y2);
T2=T2+Image(y_image,x_image);
% 第四象限
x4=x1;
y4=-y1;
x_image=floor(Center_X+x4);
y_image=floor(Center_Y-y4);
T4=T4+Image(y_image,x_image);
end
else
Num_Pixel=floor(y_end-y_start)+1;
for y=y_start:y_end-1
x0=(y+1)/k;
% 第一象限
x1=floor(x0);
y1=y+1;
x_image=floor(Center_X+x1);
y_image=floor(Center_Y-y1);
T1=T1+Image(y_image,x_image);
% 第三象限
x3=-x1;
y3=-y1;
x_image=floor(Center_X+x3);
y_image=floor(Center_Y-y3);
T3=T3+Image(y_image,x_image);
% 第二象限
x2=-x1;
y2=y1;
x_image=floor(Center_X+x2);
y_image=floor(Center_Y-y2);
T2=T2+Image(y_image,x_image);
% 第四象限
x4=x1;
y4=-y1;
x_image=floor(Center_X+x4);
y_image=floor(Center_Y-y4);
T4=T4+Image(y_image,x_image);
end
end
Image_new(i,j)=T1/Num_Pixel;
Image_new(i2,j2)=T2/Num_Pixel;
Image_new(i3,j3)=T3/Num_Pixel;
Image_new(i4,j4)=T4/Num_Pixel;
end
end
imshow(Image_new/255);
原图
效果图
效果图
PS 滤镜—— 径向模糊