zoukankan      html  css  js  c++  java
  • matlab练习程序(图像球面化)

    十一没什么事干,接着看图像算法。

    这个球面化算法最初是在ps上的球面化滤镜中看到的,感觉挺有意思,就研究了一下。

    算法的详细推导可以在这篇博客中找到,我比较懒,只在纸上推了一遍,就不在博客上编辑了。

    不过这里还是要把逆变换公式写一下。

    公式如下:

    其中R为球的半径,x,y为目标图像像素坐标,xx,yy为源图像像素坐标。

    原图:

    球面化后:

    matlab代码如下:

    clear all;close all;clc;
    
    img=imread('lena.jpg');
    [h w]=size(img);
    imshow(img);
    
    imgn=zeros(h,w);
    R=h/2;
    cenX=w/2;
    cenY=h/2;
    theta=pi;
    for y=1-cenY:h-cenY
        for x=1-cenX:w-cenX
            
            disX=1.3*x;     %系数为1则半径为h/2
            disY=1.3*y;
          
            dis=disX^2+disY^2;
            r=sqrt(disX^2+disY^2);
            if r<=R        
                xx=2*R*disX*acos(sqrt(R^2-dis)/R)/(theta*r)+cenX;
                yy=2*R*disY*acos(sqrt(R^2-dis)/R)/(theta*r)+cenY;
                          
                xx=round(xx);
                yy=round(yy);
                if xx>=1 && xx<=w && yy>=1 && yy<=h
                    imgn(y+cenY,x+cenX)=img(yy,xx);
                end
            else
                imgn(y+cenY,x+cenX)=img(y+cenY,x+cenX);
            end
            
        end
    end
    
    figure;
    imshow(imgn,[])
  • 相关阅读:
    优化-IO
    优化-cpu
    优化-内存
    系统优化
    snort -- 入侵检测系统
    tripwire--入侵检测系统
    sudo
    selinux
    pptpd
    C++ 内联函数
  • 原文地址:https://www.cnblogs.com/tiandsp/p/4003524.html
Copyright © 2011-2022 走看看