Converting a 3D polar binary image to a cartesian 3D binary image

조회 수: 1 (최근 30일)
JoaquinB
JoaquinB 2020년 2월 28일
댓글: JoaquinB 2020년 3월 12일
Hello, i do have a grayscale binary image B, of dimensions 280x3072x4000.
I would like to convert it to a cartesian image, with the origin (centre) on x=2143, y=2091, in the cartesian space. ( I dont care about the grayscale values, i just want the pixels that were 1 on my polar image to keep being 1 on my cartesian image)
Im an trying to use the PolarToIm functiont avalible on File Exchange but I dont know anything about the size scale factor and how i should modify it to apply it to my image ( I think the creator had an image where the dimensions of his image were odd for example)
Edit: Function is working fine for my image but it takes too long for my image (around 7 hours). Does anyone know how to improve the efficiency of this code? Maybe introducing the interpolation or vectorising?
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 = 2143; %(Mr+1)/2; % co-ordinates of the center of the image
On = 2091; %(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
imR (xi, yi) = interpolate (imP, r, t, rMin, rMax, M, N, delR, delT);
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
I guess I could use pol2cart function but i dont know how to apply it to an image.
Thanks

답변 (1개)

Prabhan Purwar
Prabhan Purwar 2020년 3월 11일
Hi,
Try making use of the code, illustrated in the following link:
Hope it helps!!
  댓글 수: 1
JoaquinB
JoaquinB 2020년 3월 12일
Is it possible to select a certain centre of the cartesian image?
I mean, I do have the cartesian coordinates of the centre (X=2143, Y= 2091) that I would like my cartesian image to have so i can compare it with other images. How would you apply it into the code?
Giving xyz0 in ffgrid function the values?
Thanks Prabhan

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by