Matlab:从笛卡尔坐标中提取极坐标表示的图像
Matlab: Extract Image in polar representation from Cartesian
我正在尝试计算一种将笛卡尔坐标系中的图像转换为极坐标表示的有效方法。我知道一些功能,如 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')
我正在尝试计算一种将笛卡尔坐标系中的图像转换为极坐标表示的有效方法。我知道一些功能,如 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')