# PS 滤镜— —球面化效果

clc;
clear all;
close all;

I=double(I);
Image=I/255;

[height, width, depth]=size(Image);

a = 200;
b = 200;
centreX = 0.5;
centreY = 0.5;
refractionIndex = 1.25;  % >1

icentreX=width * centreX;
icentreY=height * centreY;

if (a==0)
a=width/2;
end

if (b==0)
b=height/2;
end

a2=a*a;
b2=b*b;

Image_new=Image;

for ii=1:height
for jj=1:width

dx=jj-icentreX;
dy=ii-icentreY;

x2=dx*dx;
y2=dy*dy;

if (y2 >= (b2 - (b2*x2)/a2))
x=jj;
y=ii;
else
rRefraction = 1.0/ refractionIndex;
z=sqrt((1.0 - x2/a2 - y2/b2) * (a*b));
z2=z*z;
xAngle = acos(dx /sqrt(x2+z2));
angle_1=pi/2-xAngle;
angle_2=asin(sin(angle_1));
angle_2=pi/2-xAngle - angle_2;
x=jj - tan(angle_2)*z;

yAngle = acos(dy /sqrt(y2+z2));
angle_1=pi/2-yAngle;
angle_2=asin(sin(angle_1)*rRefraction);
angle_2=pi/2-yAngle - angle_2;
y=ii - tan(angle_2)*z;

end

% %         if (x<=1)     x=1;  end
% %         if (x>=width)   x=width-1; end;
% %         if (y>=height)  y=height-1; end;
% %         if (y<1)  y=1;     end;
% %

if (x<=1)     continue;  end
if (x>=width)   continue; end;
if (y>=height)  continue; end;
if (y<1)  continue;     end;

x1=floor(x);
y1=floor(y);
p=x-x1;
q=y-y1;

Image_new(ii,jj,:)=(1-p)*(1-q)*Image(y1,x1,:)+p*(1-q)*Image(y1,x1+1,:)...
+q*(1-p)*Image(y1+1,x1,:)+p*q*Image(y1+1,x1+1,:);

end
end

imshow(Image_new);
imwrite(Image_new, 'out.jpg');

## OpenCV——PS滤镜算法之 球面化 (凹陷效果)

// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include #...

## PS 滤镜——（扭曲）逆球面化 （凹陷效果）

%%% Inverse_Spherize %%% 逆球面化 clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Pro...

## OpenCV——PS滤镜算法之Spherize 球面化（凸出效果）

// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include #...

## PS 滤镜——（扭曲）球面化 Spherize

%%%% Spherize clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algor...

## PS 滤镜— — 万花筒效果

clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imre...

## PS 滤镜— — sparkle 效果

clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imre...

## PS 滤镜— —挤压效果

clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imre...

## PS滤镜— —波浪效果

clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imre...

## PS 滤镜— —Marble 效果

clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imre...