%%%% Water wave
%%%% 制作水波效果

clc;
clear all;
close all;

addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm');

I=imread('4.jpg');
I=double(I);
Image=I;

[row, col, channel]=size(Image);

A=7;
B=2.5;

Center_X=(col+1)/2;
Center_Y=(row+1)/2;

Image_new=Image;

for i=1:row
    for j=1:col
        x0=j-Center_X;
        y0=Center_Y-i;
        if(x0~=0)
            beta=atan(y0/x0);
            if(x0<0)
                beta=beta+pi;
            end
        else
            beta=pi/2;
        end
        r0=sqrt(x0*x0+y0*y0);
        r1=r0+A*col*0.01*sin(B*0.1*r0);
        x=r1*cos(beta);
        y=r1*sin(beta);
        x=x+col/2;
        y=row/2-y;
        if(x>1 && x<col && y<row && y>1)
            x1=floor(x);
            y1=floor(y);
            p=x-x1;
            q=y-y1;
            
            Image_new(i,j,:)=(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
end

figure, imshow(Image_new/255);


原图 


效果图


posted on 2015-03-15 16:56  未雨愁眸  阅读(162)  评论(0编辑  收藏  举报