clc;
    clear all;
    close all;

    addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm');
    I=imread('4.jpg');
    Image=double(I)/255;
    [height, width, depth]=size(Image);

    rNW=1.0;     gNW=0.0;    bNW=0.0;
    rNE=1.0;     gNE=1.0;    bNE=0.0;
    rSW=0.0;     gSW=0;      bSW=1.0;
    rSE=0.0;     gSE=1.0;    bSE=0.0;

    Img_new=Image;

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

            fx = jj / width;
            fy = ii / height;

            p = rNW + (rNE - rNW) * fx;
            q = rSW + (rSE - rSW) * fx;
            r = ( p + (q - p) * fy );
            r = min(max(r, 0), 1);

            p = gNW + (gNE - gNW) * fx;
            q = gSW + (gSE - gSW) * fx;
            g = ( p + (q - p) * fy );
            g = min(max(g, 0) ,1);

            p = bNW + (bNE - bNW) * fx;
            q = bSW + (bSE - bSW) * fx;
            b = ( p + (q - p) * fy );
            b = min(max(b, 0), 1);

            Img_new(ii, jj, 1)=r;
            Img_new(ii, jj, 2)=g;
            Img_new(ii, jj, 3)=b;
        end    
    end

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

参考来源:http://www.jhlabs.com/index.html

效果图:

这里写图片描述

posted on 2015-11-11 15:17  未雨愁眸  阅读(330)  评论(0编辑  收藏  举报