Log Polar就是所谓的极坐标变换,通过变换能将笛卡尔坐标系中的图像映射到极坐标系中。
确切的来说我这里不算是Log Polar,因为Log Polar是将图像从(x,y)映射到(log(r),theta),而我是将图像从(x,y)映射到(r,theta)。
原理是一样的。
变换公式是:
x=r*cos(theta);
y=r*sin(theta);
其中r代表极径,theta代表极角。这些应该学过高中的都会的。
下图能形象的表示变换:
似乎有通过此变换求图像特征的算法,不过具体操作我也不清楚。
我这里只是实现了变换的操作。
原图如下:
以图像中心作为极坐标原点进行极坐标变换:
matlab代码如下:
clear all; close all; clc; img=double(imread('lena.jpg')); imshow(img,[]); [m n]=size(img); [ox oy]=ginput(); %获得极坐标变换的原点 oy=round(oy); ox=round(ox); %求中心点到图像四个角的距离 up_left=sqrt((oy-0)^2+(ox-0)^2); up_right=sqrt((oy-0)^2+(ox-n)^2); down_left=sqrt((oy-m)^2+(ox-0)^2); down_right=sqrt((oy-m)^2+(ox-n)^2); %求中心点距离四角距离的最大值,作为变换后图像的高。 %这个最大值也是极坐标变换的极径 radius=round(max([up_left up_right down_left down_right])); angle=360; %变换后图像的宽 imgn=zeros(radius,angle); for i=1:radius %纵坐标代表极径,不同情况不一样 for j=1:angle %横坐标代表极角,恒为360 %oy,ox作为极坐标变换中心坐标,需要作为偏移量相加 h=oy+round(i*sin(j*pi/180)); w=ox+round(i*cos(j*pi/180)); if h>0 && w> 0&& h<=m && w<=n %超出原图像的像素忽略 imgn(i,j)=img(h,w); %最邻近插值,因为前面求h,w用了round(); end end end figure; imshow(imgn,[]);