将图像转换为极坐标的示例明确地做了 - 想要一个光滑的矩阵方法

use*_*512 4 matlab image-processing polar-coordinates

我试图将图像从笛卡尔坐标转换为极坐标.

我知道如何明确地使用for循环,但我正在寻找更紧凑的东西.

我想做的事情如下:

[x y] = size(CartImage);
minr = floor(min(x,y)/2);

r = linspace(0,minr,minr);
phi = linspace(0,2*pi,minr);

[r, phi] = ndgrid(r,phi);

PolarImage = CartImage(floor(r.*cos(phi)) + minr, floor(r.sin(phi)) + minr);
Run Code Online (Sandbox Code Playgroud)

但这显然不起作用.

基本上我希望能够在网格上索引CartImage.

然后在网格上定义极坐标图像.

bla*_*bla 5

给定矩阵M(本例中仅为2d高斯),以及发生极化变换的已知原点(X0,Y0),我们期望等强度圆将转换为等强度线:

 M=fspecial('gaussian',256,32); % generate fake image
 X0=size(M,1)/2; Y0=size(M,2)/2;
 [Y X z]=find(M);
 X=X-X0; Y=Y-Y0;
 theta = atan2(Y,X);
 rho = sqrt(X.^2+Y.^2);

 % Determine the minimum and the maximum x and y values:
 rmin = min(rho); tmin = min(theta);
 rmax = max(rho); tmax = max(theta);

 % Define the resolution of the grid:
 rres=128; % # of grid points for R coordinate. (change to needed binning)
 tres=128; % # of grid points for theta coordinate (change to needed binning)

 F = TriScatteredInterp(rho,theta,z,'natural');

 %Evaluate the interpolant at the locations (rhoi, thetai).
 %The corresponding value at these locations is Zinterp:

 [rhoi,thetai] = meshgrid(linspace(rmin,rmax,rres),linspace(tmin,tmax,tres));
 Zinterp = F(rhoi,thetai);

 subplot(1,2,1); imagesc(M) ; axis square
 subplot(1,2,2); imagesc(Zinterp) ; axis square
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

得到错误(X0,Y0)将在变换中显示为变形,所以要小心并检查.