|
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.youkuaiyun.com/luhuillll/archive/2007/08/08/1732818.aspx % POLARTRANS - Transforms image to polar coordinates |
对数极坐标变换MATLAB代码
最新推荐文章于 2023-05-15 23:43:15 发布

最低0.47元/天 解锁文章
2319

被折叠的 条评论
为什么被折叠?



