%%% Wave
%%% 波浪效果

clc;
clear all;
close all;

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

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

% Image=0.2989 * I(:,:,1) + 0.5870 * I(:,:,2) + 0.1140 * I(:,:,3); 

[row, col,channel]=size(Image);
R=floor(max(row, col)/2);
Image_new=Image;

Degree=30;    % 控制扭曲的程度

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

for i=1:row
    for j=1:col
        x0=j-Center_X;
        y0=Center_Y-i;
        x=Degree*sin(2*pi*y0/128)+x0;
        y=Degree*cos(2*pi*x0/128)+y0;
        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-09 12:59  未雨愁眸  阅读(311)  评论(0编辑  收藏  举报