3
这是测试pol2cart()和cart2pol代码:matlab如何从warp()函数中提取二维图像数据?
clear all
close all
clc
% data = imread('D:\Projects\CarPool\TestData\test_img1.bmp');
data = phantom(128);
img = sum(data, 3);
[M, N] = size(img);
xvec = linspace(-N/2, N/2);
% convert pixel coordinates from cartesian to polar
[x, y] = meshgrid(xvec,xvec);
[theta, rho] = cart2pol(x, y);
[xx, yy] = pol2cart(theta, rho);
%# show pixel locations (subsample to get less dense points)
xdisp = x(1:8:end,1:4:end);
ydisp = y(1:8:end,1:4:end);
tdisp = theta(1:8:end,1:4:end);
rdisp = rho(1:8:end,1:4:end);
xxdisp = xx(1:8:end,1:4:end);
yydisp = yy(1:8:end,1:4:end);
% h = warp(xx, yy, zeros(size(xx)), img);
% imgWarp = get(h, 'FaceColor');imgWapr = sum(imgWarp,3);
% imgWarp = (imgWarp - min(imgWarp(:)))/max(imgWarp(:));
% img = (img - min(img(:)))/max(img(:));
% diffImg = img - imgWarp;
figure; clf
subplot(241)
scatter(xdisp(:),ydisp(:),3,'filled', 'red'), axis ij image
title('cartesian coordinates'); xlabel('x'); ylabel('y');
subplot(242)
scatter(tdisp(:),rdisp(:),3,'filled'), axis ij square tight,
title('cartesian to polar coordinates'); xlabel('\theta'); ylabel('\rho');
subplot(243)
scatter(xxdisp(:),yydisp(:),3,'filled'), axis ij square tight,
title('cartesian to polar coordinates'); xlabel('x'); ylabel('y');
subplot(244)
scatter(xdisp(:),ydisp(:),3,'filled', 'red'), axis ij image; hold on
scatter(xxdisp(:),yydisp(:),3,'filled', 'blue'), axis ij square tight,
legend('orginal cartesian coordinates', 'coordinates from polar to cartesian');
title('cartesian to polar coordinates'); xlabel('x'); ylabel('y');
%# show images
subplot(245), imshow(img), axis on
title('cartesian'); xlabel('x'); ylabel('y');
subplot(246), warp(theta, rho, zeros(size(theta)), img)
title('cartesian to polar'); xlabel('\theta'); ylabel('\rho');
view(2), axis square
subplot(247), warp(xx, yy, zeros(size(xx)), img)
title('polar to cartesian'); xlabel('x'); ylabel('y');
view(2), axis image
subplot(248)
imagesc(diffImg); colormap(gray); colorbar;
title('difference'); xlabel('x'); ylabel('y');
view(2), axis image
这里是我的结果。基本上第一个图像是原始的,第二个是cart2pol,第三个是pol2cart。
我的问题是:如何查看第一和第三图像之间的差异? (如果你看我的脚本,第一个图像的数据是img
,但我不知道如何找到这样的第三个图像的数据?第三个图像是简单地使用warp()
功能来做显示。)
因此,如果matlab中的图像是cart2pol()首先获取imgPol,那么imgPol会使用pol2cart()来处理以获取imgCart,那么imgCart与img相同?这听起来没有道理..... –
cart2pol适用于坐标,但不是img。 cart2pol的输出提供给表面功能,只是告诉它如何显示img。 – lennon310
所以它所做的所有重新采样,重新网格的表面功能? –