Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Image from polar to cartesian gives only two quadrants
Date: Tue, 1 May 2012 17:49:06 +0000 (UTC)
Organization: University of Iowa
Lines: 48
Message-ID: <jnp7mi$9lj$1@newscl01ah.mathworks.com>
References: <jnncme$9b8$1@newscl01ah.mathworks.com> <jnnhpn$s45$1@newscl01ah.mathworks.com> <jnnmui$idd$1@newscl01ah.mathworks.com> <jnp2hj$h5t$1@newscl01ah.mathworks.com> <jnp5qj$24n$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1335894546 9907 172.30.248.45 (1 May 2012 17:49:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 1 May 2012 17:49:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2464728
Xref: news.mathworks.com comp.soft-sys.matlab:766506

"Roger Stafford" wrote in message <jnp5qj$24n$1@newscl01ah.mathworks.com>...
>   Please show us your revised code.  Very likely your trouble lies with the negative values given out by 'atan2'.  Remember, I told you that 'atan2' ranges full circle from -pi to +pi.  These need to be properly transformed into the entirely positive-valued columns of polarInputImage.
> 
> Roger Stafford

-----------------------

I got the solution now. I just added 180 degrees to each value of 'theta' so that they go over the full range of 0 to 360 degrees.

Thanks a lot for your help!! 

function[cartIm, xValues, yValues] = createCartImage(polarInputImage, ...
                                                     xStart, ...
                                                     xEnd, ... 
                                                     numX, ...
                                                     numY)
[numRows, numCols] = size(polarInputImage);

cartIm = zeros(numX, numY);
xStep = (xEnd-xStart)/numX;
xValues = xStart + (0:numX-1)*xStep;

yStart = -360; 
yStep = 1;
yValues = yStart + (0:numY-1)*yStep;

% compute corresponding Polar coordinates
[X,Y] = meshgrid(xValues, yValues); %create a grid of X and Y values
RD = sqrt(X.^2 + Y.^2);
TH = atan2(Y,X).*(180/pi) + 180;   

RD = round(RD);
TH = round(TH);

% create cartesian image
%counter = 1;
for y=1:numY %(rows)
    for x=1:numX %(cols)
        row = RD(y,x); 
        col = TH(y,x);
       
        if (row > 0 && row < numRows && col > 0 && col < numCols)
            xx = x;% + 240;
            yy = y;% + 360;
            cartIm(xx,yy) = polarInputImage(row,col);  
        end   
    end
end