我正在尝试计算一种将笛卡尔坐标中的图像转换为极坐标表示的有效方法。我知道有些功能(例如ImToPolar)正在执行此操作,并且效果很好,但是对于大图像来说需要花费大量时间,尤其是当它们需要来回处理时。
这是我的输入图片:
然后我使用以0为中心的笛卡尔网格和函数生成极坐标网格cart2pol()
。最后,我使用绘制图像mesh(theta, r, Input)
。
这是我得到的:
它正是我需要的图像,并且与之相同ImToPolar
甚至更好。
由于MATLAB知道如何计算它,所以有人知道如何从此输出中提取极性表示形式的矩阵吗?还是在MATLAB上计算极坐标变换(和逆变换)的快速方法(如快速傅立叶变换)?
pol2cart
并meshgrid
和interp2
足以创建结果:
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')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句