0

我需要用 Octave 生成​​一个黑白棋盘格。我想使用这个虚拟图像将笛卡尔投影转换为极坐标或透视投影。任何人都可以显示脚本?谢谢

我试过这个:

clear all
close all
clc

img = magic(16);

%# convert coordinates from cartesian to polar
[r c] = size(img);
[X Y] = meshgrid(1:c,1:r);
[theta rho] = cart2pol(X, Y);

figure
subplot(121), image(img), axis square

colormap(gray(256))

subplot(122), surf(theta, rho,img),axis square;
view(0,90)
4

1 回答 1

2

这可以满足 OP 的要求。但是这个问题是几个月前提出的!

对 OP 的代码稍作修改。

clear all
close all
clc
%my changes start
img = zeros(8,8);
img(1:2:end,1:2:end)=255;
img(2:2:end,2:2:end)=255;
%my changes end

%# convert coordinates from cartesian to polar
[r c] = size(img);
[X Y] = meshgrid(1:c,1:r);
[theta rho] = cart2pol(X, Y);

figure
subplot(121), image(img), axis square

colormap(gray(256))

subplot(122), surf(theta, rho,img),axis square;
view(0,90)
于 2013-01-28T03:57:11.527 回答