Matlab how to extract 2D image data from warp () function?

This is the code for checking pol2cart () and cart2pol:

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

Here are my results. Basically, the first image is original, the second is cart2pol, the third is pol2cart.

enter image description here

My questions: How do I see the difference between the first and third images? (If you look at my script, then the data of the first image will be img, but I don’t know how to find such data for the third image? The third image just uses the function warp()to execute the display.)

+3
source share
1 answer

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.

+2

All Articles