2016-09-23 214 views
0

我試圖計算一種將笛卡爾座標圖像轉換爲極座標表示的有效方法。我知道一些功能,如ImToPolar正在這樣做,它完美的工作,但需要大量的時間來處理大圖像,尤其是當它們需要來回處理時。Matlab:從笛卡爾的極座標表示中提取圖像

Here's我的輸入圖像:

input image

,然後我生成使用以0爲中心的笛卡爾網格和功能cart2pol()極性的網格。最後,我使用mesh(theta, r, Input)繪製我的圖像。

而且here's我獲得:

output image

它完全像我需要和it's一樣ImToPolar也許更好。

由於MATLAB知道如何計算它,是否有人知道如何從這個輸出中提取極座標表示的矩陣?或者,也許快速(如快速傅里葉變換)方式來計算MATLAB上的極座標變換(和反算)?

+0

你需要你的插值極座標圖象到規則的網格?你的方法導致非方形「像素」 – Suever

+0

[這裏](https://fossies.org/dox/octave-4.0.3/cart2pol_8m_source.html)是OCTAVE的cart2pol的來源。它可能需要一些更改才能使用。如果速度會更快,我不知道。你可能會適應它。我會_guess_ MATLAB有很多開銷,你可能會擺脫。 – chessofnerd

回答

0

pol2cartmeshgridinterp2足以創建結果:

I=imread('http://i.stack.imgur.com/HYSyb.png'); 
[r, c,~] = size(I); 
%rgb image can be converted to indexed image to prevent excessive copmutation for each color 
[idx, mp] = rgb2ind(I,32); 
% add offset to image coordinates 
x = (1:c)-(c/2); 
y = (1:r)-(r/2); 
% create distination coordinates in polar form so value of image can be interpolated in those coordinates 
% angle ranges from 0 to 2 * pi and radius assumed that ranges from 0 to 400 
% linspace(0,2*pi, 200) leads to a stretched image try it! 
[xp yp] = meshgrid(linspace(0,2*pi), linspace(0,400)); 
%translate coordinate from polar to image coordinates 
[xx , yy] = pol2cart(xp,yp); 
% interpolate pixel values for unknwon coordinates 
out = interp2(x, y, idx, xx, yy); 
% save the result to a file 
imwrite(out, mp, 'result.png') 
+0

謝謝,它完美的作品! – Marko

相關問題