%%%% Spherize clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm'); I=imread('4.jpg'); Image=double(I); [row, col,layer]=size(Image); R=floor(min(row, col)/2); a=row/2; b=col/2; e=a/b; K=pi/2; alpha=1.0; % 控制变形程度 Image_new=Image; for i=1:row for j=1:col y0=(row+1)/2-i; x0=j-(col+1)/2; Dis=x0.^2+y0.^2; if(Dis<R*R) % if(x0*x0/(a*a)+(y0*y0)/(b*b)<1) if(x0~=0) beta=atan(y0/x0); if(x0<0) beta=beta+pi; end else beta=pi/2; end radius=asin(sqrt(Dis)/R)*R/K; radius=(sqrt(Dis)-radius)*(1-alpha)+radius; x=radius*cos(beta); y=radius*sin(beta); x=col/2+x; y=row/2-y; if(x>1 && x<col && y>1 && y<row) x1=floor(x); y1=floor(y); p=x-x1; q=y-y1; for k=1:layer Image_new(i,j,k)=(1-p)*(1-q)*Image(y1,x1,k)+p*(1-q)*Image(y1,x1+1,k)... +q*(1-p)*Image(y1+1,x1,k)+p*q*Image(y1+1,x1+1,k); end end end end end imshow(Image_new/255);
原图
效果图
原文:http://blog.csdn.net/matrix_space/article/details/42215127