2014-02-07 51 views
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。

enter image description here

我的問題是:如何查看第一和第三圖像之間的差異? (如果你看我的腳本,第一個圖像的數據是img,但我不知道如何找到這樣的第三個圖像的數據?第三個圖像是簡單地使用warp()功能來做顯示。)

回答

2

函數warp(x,y,z,img)首先調用函數[x,y,z,cdata,cdatamapping,clim,map,likeimage] = parse_inputs(varargin{:});解析您的輸入,其中im2double應用於您的img以獲得cdata。之後,

surface(x,y,z,cdata,'EdgeColor','none','FaceColor','texturemap', ... 
     'CDataMapping',cdatamapping); 

被調用來顯示您的圖像。

所以你的三個數字都顯示img與你給定的座標,你的數字1和3應該是相同的。

您可以通過type warp瞭解該功能的更多詳細信息。

+0

因此,如果matlab中的圖像是cart2pol()首先獲取imgPol,那麼imgPol會使用pol2cart()來處理以獲取imgCart,那麼imgCart與img相同?這聽起來沒有道理..... –

+0

cart2pol適用於座標,但不是img。 cart2pol的輸出提供給表面功能,只是告訴它如何顯示img。 – lennon310

+0

所以它所做的所有重新採樣,重新網格的表面功能? –