zoukankan      html  css  js  c++  java
  • PS 滤镜— —球面化效果

        clc;
        clear all;
        close all;
    
        addpath('E:PhotoShop AlgortihmImage ProcessingPS Algorithm');
    
        I=imread('4.jpg');
        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');

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

    原图:
    这里写图片描述

    效果图:

    这里写图片描述

  • 相关阅读:
    shell-bash学习01基础、打印、环境变量
    css/js(工作中遇到的问题)-2
    git学习 git-flow
    js正则表达式练习
    12 链
    11数据访问
    10访问者,解释器
    08中介者,装饰者
    09 状态,适配器
    调试 scrapy 文件报错:line 48, in _load_handler、line 44, in load_object、 line 37, in import_module
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9412569.html
Copyright © 2011-2022 走看看