http://www.vision.ee.ethz.ch/~konrads/code/logpolar.m
function [I_lp,I_nearest,I_bilinear] = logpolar(I,slices)
%
% [I_lp,I_nearest,I_bilinear] = logpolar(I,slices)
%
% Log-polar resampling of an image, and back-sampling to retinal plane
%
% INPUT:
% I ... source image
% slices ... number of radial slices
%
% OUTPUT:
% I_lp ... the log-polar image
% I_nearest ... backprojection, nearest-neighbor resampling (shows log-polar pixels)
% I_bilinear ... backprojection, bilinear resampling (smooth image with varying resolution)
%
% Konrad, 22.09.2006
I = double(I);
[rows,cols,planes] = size(I);
%%%%%%%%%%%%%%%%%%%
% log-polar mapping
%%%%%%%%%%%%%%%%%%%
ctr = [rows cols]/2;
mult = 1+2*pi/slices;
% make empty log-polar image
lpcols = slices;
lprows = floor(log(max(ctr)*sqrt(2))/log(mult));
I_lp = zeros(lpcols,lprows,planes,'uint8');
% fill pixels
for u = 1:lpcols
for v = 1:lprows
% find the center of the log-polar bin in the original image
ang = u/slices*2*pi;
pt = ctr+mult^v*[cos(ang) sin(ang)];
pt = round(pt);
if pt(1)<1 || pt(2)<1 || pt(1)>rows || pt(2)>cols, continue; end
% integrate over log-polar pixel
rd = mult^v-mult^(v-1);
sz = ceil(rd);
if sz<1
filt = 1;
bbximg = [ pt ; pt ];
else
filt = fspecial('disk',sz);
bbximg = [ pt-[sz sz] ; pt+[sz sz] ];
bbxflt = [ 1 1 ; 2*[sz sz]+[1 1] ];
if bbximg(1,1)>rows || bbximg(1,2)<1 || bbximg(2,1)>cols || bbximg(2,2)<1
continue;
end
% correct for pixels overlapping the image boundary
if bbximg(1,1)<1, bbxflt(1,1) = 2-bbximg(1,1); bbximg(1,1) = 1; end
if bbximg(1,2)<1, bbxflt(1,2) = 2-bbximg(1,2); bbximg(1,1) = 1; end
if bbximg(2,1)>rows, bbxflt(2,1) = bbxflt(2,1)-bbximg(2,1)+rows; bbximg(2,1) = rows; end
if bbximg(2,2)>cols, bbxflt(2,2) = bbxflt(2,2)-bbximg(2,2)+cols; bbximg(2,2) = cols; end
filt = filt(bbxflt(1,1):bbxflt(2,1),bbxflt(1,2):bbxflt(2,2));
filt = filt/sum(sum(filt));
end
for p = 1:planes
val = I(bbximg(1,1):bbximg(2,1),bbximg(1,2):bbximg(2,2),p).*filt;
I_lp(u,v,p) = uint8(sum(val(:)));
end
end
end
% move 360 degrees to 0
I_lp = [I_lp(2:end,:,:) ; I_lp(1,:,:)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% back-projection to retina
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% circular extension of log-polar image
lpcols = lpcols+1;
I_lpbig = [I_lp;I_lp(1,:,:)];
% make empty images
I_nearest = zeros(rows,cols,planes,'uint8');
I_bilinear = zeros(rows,cols,planes,'uint8');
% fill pixels
for u = 1:rows
for v = 1:cols
% get log-polar coordinate
uu = u-ctr(1);
vv = v-ctr(2);
rfloat = 0.5*log(max(1,uu^2+vv^2))/log(mult)-1.5;
afloat = atan2(vv,uu)/(2*pi)*slices-1.5;
ri = afloat<=1;
afloat(ri) = slices+afloat(ri);
% round for nearest neighbor
rind = round(rfloat);
aind = round(afloat);
if afloat<1 || rfloat<1 || afloat>lpcols || rfloat>lprows, continue; end
% get values
for p = 1:planes
I_nearest(u,v,p) = I_lpbig(aind,rind,p);
af = floor(afloat);
rf = floor(rfloat);
I_bilinear(u,v,p) = interp2(I_lpbig(af:af+1,rf:rf+1,p),rfloat-rf+1,afloat-af+1,'*linear');
end
end
end
http://blog.csdn.net/luhuillll/archive/2007/08/08/1732818.aspx
% POLARTRANS - Transforms image to polar coordinates
%
% Usage: pim = polartrans(im, nrad, ntheta, cx, cy, linlog, shape)
%
% Arguments:
% im - image to be transformed.
% nrad - number of radius values.
% ntheta - number of theta values.
% cx, cy - optional specification of origin. If this is not
% specified it defaults to the centre of the image.
% linlog - optional string 'linear' or 'log' to obtain a
% transformation with linear or logarithmic radius
% values. linear is the default.
% shape - optional string 'full' or 'valid'
% 'full' results in the full polar transform being
% returned (the circle that fully encloses the original
% image). This is the default.
% 'valid' returns the polar transform of the largest
% circle that can fit within the image.
%
% Returns pim - image in polar coordinates with radius increasing
% down the rows and theta along the columns. The size
% of the image is nrad x ntheta. Note that theta is
% +ve clockwise as x is considered +ve along the
% columns and y +ve down the rows.
%
% When specifying the origin it is assumed that the top left pixel has
% coordinates (1,1).
% Copyright (c) 2002 Peter Kovesi
% School of Computer Science & Software Engineering
% The University of Western Australia
% http://www.csse.uwa.edu.au/
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the "Software"), to deal
% in the Software without restriction, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in
% all copies or substantial portions of the Software.
%
% The Software is provided "as is", without warranty of any kind.
% December 2002
% November 2006 Correction to calculation of maxlogr (thanks to Chang Lei)
function pim = polartrans(im, nrad, ntheta, cx, cy, linlog, shape)
[rows, cols] = size(im);
if nargin==3 % Set origin to centre.
cx = cols/2+.5; % Add 0.5 because indexing starts at 1
cy = rows/2+.5;
end
if nargin < 7, shape = 'full'; end
if nargin < 6, linlog = 'linear'; end
if strcmp(shape,'full') % Find maximum radius value
dx = max([cx-1, cols-cx]);
dy = max([cy-1, rows-cy]);
rmax = sqrt(dx^2+dy^2);
elseif strcmp(shape,'valid') % Find minimum radius value
rmax = min([cx-1, cols-cx, cy-1, rows-cy]);
else
error('Invalid shape specification');
end
% Increments in radius and theta
deltatheta = 2*pi/ntheta;
if strcmp(linlog,'linear')
deltarad = rmax/(nrad-1);
[theta, radius] = meshgrid([0:ntheta-1]*deltatheta, [0:nrad-1]*deltarad);
elseif strcmp(linlog,'log')
maxlogr = log(rmax);
deltalogr = maxlogr/(nrad-1);
[theta, radius] = meshgrid([0:ntheta-1]*deltatheta, exp([0:nrad-1]*deltalogr));
else
error('Invalid radial transformtion (must be linear or log)');
end
xi = radius.*cos(theta) + cx; % Locations in image to interpolate data
yi = radius.*sin(theta) + cy; % from.
[x,y] = meshgrid([1:cols],[1:rows]);
pim = interp2(x, y, double(im), xi, yi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
新的对数极变换的代码
%function [rout,g,b] = LHimlogpolar(image,Nrho,Ntheta,Method,Center,Shape)
function [rout,g,b] = LHimlogpolar(varargin)
%IMLOGPOLAR Compute logarithmic polar transformation of image.
% B = IMLOGPOLAR(A,NRHO,NTHETA,METHOD) computes the logarithmic
% polar transformation of image A, generating a log polar image
% of size NRHO by NTHETA. METHOD describes the interpolation
% method. METHOD is a string that can have one of these values:
%
% 'nearest' (default) nearest neighbor interpolation
%
% 'bilinear' bilinear interpolation
%
% 'bicubic' bicubic interpolation
%
% If you omit the METHOD argument, IMLOGPOLAR uses the default
% method of 'nearest'.
%
% B = IMLOGPOLAR(A,NRHO,NTHETA,METHOD,CTR) assumes that the 2x1
% vector CTR contains the coordinates of the origin in image A.
% If CTR is not supplied, the default is CTR = [(m+1)/2,(n+1)/2],
% where A has n rows and m columns.
%
% B = IMLOGPOLAR(A,NRHO,NTHETA,METHOD,CTR,SHAPE) where SHAPE is a
% string that can have one of these values:
%
% 'full' - returns log polar transformation containing ALL
% pixels from image A (the circumscribed circle
% centered at CTR)
%
% 'valid' - returns log polar transformation containing only
% pixels from the largest inscribed circle in image A
% centered at CTR.
%
% If you omit the SHAPE argument, IMLOGPOLAR uses the default shape
% of 'valid'. If you specify the shape 'full', invalid values on the
% periphery of B are set to NaN.
%
% Class Support
% -------------
% The input image can be of class uint8 or double. The output
% image is of the same class as the input image.
%
% Example
% -------
% I = imread('ic.tif');
% J = imlogpolar(I,64,64,'bilinear');
% imshow(I), figure, imshow(J)
%
% See also IMCROP, IMRESIZE, IMROTATE.
% Nathan D. Cahill 8-16-01, modified from:
% Clay M. Thompson 8-4-92
% Copyright 1993-1998 The MathWorks, Inc. All Rights Reserved.
% $Revision: 5.10 $ $Date: 1997/11/24 15:35:33 $
% Grandfathered:
% Without output arguments, IMLOGPOLAR(...) displays the transformed
% image in the current axis.
% Outputs: A the input image
% Nrho the desired number of rows of transformed image
% Ntheta the desired number of columns of transformed image
% Method interpolation method (nearest,bilinear,bicubic)
% Center origin of input image
% Shape output size (full,valid)
% Class storage class of A
[Image,rows,cols,Nrho,Ntheta,Method,Center,Shape,ClassIn] = LHparse_inputs(varargin{:});
threeD = (ndims(Image)==3); % Determine if input includes a 3-D array
if threeD,
[r,g,b] = LHtransformImage(Image,rows,cols,Nrho,Ntheta,Method,Center,Shape);
if nargout==0,
imshow(r,g,b);
return;
elseif nargout==1,
if strcmp(ClassIn,'uint8');
rout = repmat(uint8(0),[size(r),3]);
rout(:,:,1) = uint8(round(r*255));
rout(:,:,2) = uint8(round(g*255));
rout(:,:,3) = uint8(round(b*255));
else
rout = zeros([size(r),3]);
rout(:,:,1) = r;
rout(:,:,2) = g;
rout(:,:,3) = b;
end
else % nargout==3
if strcmp(ClassIn,'uint8')
rout = uint8(round(r*255));
g = uint8(round(g*255));
b = uint8(round(b*255));
else
rout = r; % g,b are already defined correctly above
end
end
else
r = LHtransformImage(Image,rows,cols,Nrho,Ntheta,Method,Center,Shape);
if nargout==0,
imshow(r);
return;
end
if strcmp(ClassIn,'uint8')
if islogical(image)
r = im2uint8(logical(round(r)));
else
r = im2uint8(r);
end
end
rout = r;
end
function [A,Ar,Ac,Nrho,Ntheta,Method,Center,Shape,Class] = LHparse_inputs(varargin)
% Outputs: A the input image
% Nrho the desired number of rows of transformed image
% Ntheta the desired number of columns of transformed image
% Method interpolation method (nearest,bilinear,bicubic)
% Center origin of input image
% Shape output size (full,valid)
% Class storage class of A
error(nargchk(3,6,nargin));
A = varargin{1};
Ar = size(A,1); % Ar = number of rows of the input image
Ac = size(A,2); % Ac = number of columns of the input image
Nrho = varargin{2};
Ntheta = varargin{3};
Class = class(A);
if nargin < 4
Method = '';
else
Method = varargin{4};
end
if isempty(Method)
Method = 'nearest';
end
Method = lower(Method);
if ~any(strcmp(Method,{'nearest','bilinear','bicubic'}))
error('Method must be one of ''nearest'', ''bilinear'', or ''bicubic''.');
end
if nargin < 5
Center = [];
else
Center = varargin{5};
end
if isempty(Center)
Center = [(Ac+1)/2 (Ar+1)/2];
end
if length(Center(:))~=2
error('Center should be 1x2 array.');
end
if any(Center(:)>[Ac;Ar] | Center(:)<1)
% THIS LINE USED TO READ 'ifany(Center(:)>[Ar;Ac] | Center(:)<1)' but Ar and Ac should be swapped round -- look at line 40 for whty this should be. A.I.Wilmer,12th Oct 2002
num2str(['Center is',num2str(Center(1)),',',num2str(Center(2)),'with size of image =',num2str(Ar),'x',num2str(Ac),' (rows,columns)']);
warning('Center supplied is not within image boundaries.');
end
if nargin < 6
Shape = '';
else
Shape = varargin{6};
end
if isempty(Shape)
Shape = 'valid';
end
Shape = lower(Shape);
if ~any(strcmp(Shape,{'full','valid'}))
error('Shape must be one of ''full'' or ''valid''.');
end
if isa(A, 'uint8'), % Convert A to Double grayscale for interpolation
if islogical(A)
A = double(A);
else
A = double(A)/255;
end
end
function [r,g,b] = LHtransformImage(A,Ar,Ac,Nrho,Ntheta,Method,Center,Shape)
% Inputs: A the input image
% Nrho the desired number of rows of transformed image
% Ntheta the desired number of columns of transformed image
% Method interpolation method (nearest,bilinear,bicubic)
% Center origin of input image
% Shape output size (full,valid)
% Class storage class of A
global rho;
theta = linspace(0,2*pi,Ntheta+1); theta(end) = [];
switch Shape
case 'full'
corners = [1 1;Ar 1;Ar Ac;1 Ac];
d = max(sqrt(sum((repmat(Center(:)',4,1)-corners).^2,2)));
case 'valid'
d = min([Ac-Center(1) Center(1)-1 Ar-Center(2) Center(2)-1]);
end
minScale = 1;
rho = logspace(log10(minScale),log10(d),Nrho)'; % default 'base 10' logspace - play with d to change the scale of the log axis
% convert polar coordinates to cartesian coordinates and center
xx = rho*cos(theta+pi) + Center(1);
yy = rho*sin(theta+pi) + Center(2);
if nargout==3
if strcmp(Method,'nearest'), % Nearest neighbor interpolation
[xi,yi] = meshgrid(-3:.1:3,-3:.1:3)
r=interp2(A(:,:,1),xx,yy,'nearest');
g=interp2(A(:,:,2),xx,yy,'nearest');
b=interp2(A(:,:,3),xx,yy,'nearest');
elseif strcmp(Method,'bilinear'), % Linear interpolation
r=interp2(A(:,:,1),xx,yy,'linear');
g=interp2(A(:,:,2),xx,yy,'linear');
b=interp2(A(:,:,3),xx,yy,'linear');
elseif strcmp(Method,'bicubic'), % Cubic interpolation
r=interp2(A(:,:,1),xx,yy,'cubic');
g=interp2(A(:,:,2),xx,yy,'cubic');
b=interp2(A(:,:,3),xx,yy,'cubic');
else
error(['Unknown interpolation method: ',method]);
end
% any pixels outside , pad with black
mask= (xx>Ac) | (xx<1) | (yy>Ar) | (yy<1);
r(mask)=NaN;
g(mask)=NaN;
b(mask)=NaN;
else
if strcmp(Method,'nearest'), % Nearest neighbor interpolation
r=interp2(A,xx,yy,'nearest');
%r=interp2(A,xx,yy,'nearest');
elseif strcmp(Method,'bilinear'), % Linear interpolation
size(A)
r=interp2(A,xx,yy,'linear');
%r=interp2(A,xx,yy,'linear');
elseif strcmp(Method,'bicubic'), % Cubic interpolation
r=interp2(A,xx,yy,'cubic');
%r=interp2(A,xx,yy,'cubic');
else
error(['Unknown interpolation method: ',method]);
end
% any pixels outside warp, pad with black
mask= (xx>Ac) | (xx<1) | (yy>Ar) | (yy<1);
r(mask)=NaN;
end
相关推荐
在图像拼接过程中对于旋转的图像需要进行对数极坐标变换,该程序可以实现这种功能。
一个简单的对数极坐标变换matlab程序,作为入门小白的一次尝试,希望能得到认可
总结来说,《图像对数极坐标变换的FPGA实现》一文提出了一种结合FPGA、QuartusII、Verilog和Matlab实现对数极坐标变换的方法,该方法可以有效地解决高精度导弹末制导景象匹配技术中的实时性问题。FPGA的硬件实现方式...
本主题将深入探讨“对数极坐标变换”,这是一种将图像从笛卡尔坐标系转换到对数极坐标系的方法。这种转换在某些特定应用中,如图像旋转不变性、小目标检测以及图像放大与缩小等方面具有优势。 首先,让我们理解...
极坐标,对数极坐标变换及其反变换分类matlab与图像处理
梅林变换是傅里叶变换与极坐标变换的组合,它将图像转换到梅林频域,这样就可以在频域内进行旋转操作,而不会改变频率内容。在MATLAB中,没有内置的梅林变换函数,但可以通过自定义代码实现。 描述中提到的"test....
总的来说,"matlab开发-Logpolarimagesampling"涉及的关键知识点包括MATLAB编程、图像处理、坐标变换、对数极坐标系、采样理论以及可能的插值算法。理解这些概念和函数的使用,能够帮助开发者更有效地处理和分析具有...
用matlab实现的对数极坐标转换图像配准算法,实验证明效果不错(Using matlab realize logarithmic polar coordinate conversion image registration algorithm, experiments show good results)
梅林变换是傅里叶变换与对数极坐标变换的组合,对图像的旋转具有良好的不变性。 4. **特征匹配**:比较两幅图像的梅林谱,找到对应的特征点,这通常可以通过计算两谱之间的相关性或最小化距离函数来实现。 5. **...
- **特殊曲线**:如对数螺旋线,其极坐标方程为 \(r = e^{a\theta}\),其中 \(a\) 为常数;又如双纽线,其极坐标方程为 \(r^2 = a^2 \cos 2\theta\)。 ### 三、常见曲线的参数方程 - **椭圆**:参数方程为 \(\left\...
在 MATLAB 开发环境中,`Polar_dB` 是一个用于绘制以分贝(dB)标度的极坐标数据的工具,特别适用于展示天线的辐射模式图。辐射模式图是描述天线向不同方向发射或接收电磁能量的能力的图形表示。这种图形在无线通信...
- **cart2pol**: 将笛卡尔坐标转换为极坐标。 - **cart2sph**: 将笛卡尔坐标转换为球坐标。 - **cell**: 创建单元数组。 - **cell2struct**: 将单元数组转换为结构体。 - **celldisp**: 显示单元数组的内容。 - **...
- **极坐标转换**:将二维傅立叶变换的结果从笛卡尔坐标系转换到极坐标系,其中径向距离代表频率,角度代表方向。 - **角度平均**:沿着不同的角度对极坐标系中的功率谱进行平均,得到径向平均值。 - **径向功率...
该文档涵盖了广泛的MATLAB绘图函数,这些函数使得用户能够创建各种类型的图形,包括基本的线条图、对数坐标图、极坐标图,以及更复杂的3D图形、条形图、饼图、等高线图、方向图等。以下是对这些绘图函数的详细解释:...
在MATLAB中,`logpolar`函数可以用来将频谱转换为对数极坐标表示,便于观察。 标签“二维频谱_matlab”进一步强调了这个主题是关于使用MATLAB处理二维频谱问题。 根据压缩包内的文件名,我们可以推测这里有两份...
- `polar`:创建二维极坐标图。 - `rectangulate`:创建二维矩形对象。 - `texlabel`:生成TeX格式的字符串,用于图形标题和标签。 4. **交互式工具**: - `figure`:创建新的图形窗口。 - `palette`:显示或...
因此,EnhancedErrorbarFunction的实现考虑了这些坐标变换,确保误差条的长度正确反映了实际的不确定性。 具体来说,该函数可能包含以下几个关键部分: 1. **坐标转换函数**:为了在不同坐标系统中正确显示误差条...
LPM将图像从笛卡尔坐标系变换到对数极坐标系,这种转换可以提高图像的旋转和缩放不变性。由于数字水印在应用过程中可能会遇到图像的旋转和缩放变形,因此,使用LPM可以提高数字水印检测的鲁棒性。 MATLAB编程在实现...
"自学Matlab必备的60个小程序代码"集合了Matlab的基础与进阶应用,对于初学者来说是极好的学习资源。下面,我们将深入探讨这些小程序代码所涵盖的Matlab知识点。 1. **基本语法与数据类型**:Matlab支持向量、矩阵...
奈奎斯特图是一种频率域分析方法,它将系统的开环传递函数表示为复频率的极坐标图,有助于我们理解系统的稳定性和动态特性。在本项目中,"nyquistplots"特别关注了对数有效性,即采用对数标度来解决在处理具有大振幅...