随记2(swt)

function imR = PolarToIm (imP, rMin, rMax, Mr, Nr)
% POLARTOIM converts polar image to rectangular image. 
%
% V0.1 16 Dec, 2007 (Created) Prakash Manandhar, pmanandhar@umassd.edu
%
% This is the inverse of ImToPolar. imP is the polar image with M rows and
% N columns of data (double data between 0 and 1). M is the number of
% samples along the radius from rMin to rMax (which are between 0 and 1 and
% rMax > rMin). Mr and Nr are the number of pixels in the rectangular
% domain. The center of the image is assumed to be the origin for the polar
% co-ordinates, and half the width of the image corresponds to r = 1.
% Bilinear interpolation is performed for points not in the imP image and
% points not between rMin and rMax are rendered as zero. The output is a Mr
% x Nr grayscale image (with double values between 0.0 and 1.0).




imR = zeros(Mr, Nr);
Om = (Mr+1)/2; % co-ordinates of the center of the image
On = (Nr+1)/2;
sx = (Mr-1)/2; % scale factors
sy = (Nr-1)/2;


[M N] = size(imP);


delR = (rMax - rMin)/(M-1);
delT = 2*pi/N;


for xi = 1:Mr
for yi = 1:Nr
    x = (xi - Om)/sx;
    y = (yi - On)/sy;
    r = sqrt(x*x + y*y);
    if r >= rMin && r <= rMax
       t = atan2(y, x);
       if t < 0
           t = t + 2*pi;
       end
      
    end
end
end


function v = interpolate (imP, r, t, rMin, rMax, M, N, delR, delT)
    ri = 1 + (r - rMin)/delR;
    ti = 1 + t/delT;
    rf = floor(ri);
    rc = ceil(ri);
    tf = floor(ti);
    tc = ceil(ti);
    if tc > N
        tc = tf;
    end
    if rf == rc & tc == tf
        v = imP (rc, tc);
    elseif rf == rc
        v = imP (rf, tf) + (ti - tf)*(imP (rf, tc) - imP (rf, tf));
    elseif tf == tc
        v = imP (rf, tf) + (ri - rf)*(imP (rc, tf) - imP (rf, tf));
    else
       A = [ rf tf rf*tf 1
             rf tc rf*tc 1
             rc tf rc*tf 1
             rc tc rc*tc 1 ];
       z = [ imP(rf, tf)
             imP(rf, tc)
             imP(rc, tf)
             imP(rc, tc) ];
       a = A\double(z);
       w = [ri ti ri*ti 1];
       v = w*a;
    end
A=imread('image2','jpg');
B=rgb2gray(A);
B=double(B);
B=B/255;
imR = PolarToIm (B, 0, 1, 512, 512);
subplot(1,2,1)
imshow(B);
subplot(1,2,2)
imshow(imR);  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值