Problem using imtransform with custom functions

2 vues (au cours des 30 derniers jours)
Christopher Hall
Christopher Hall le 20 Mai 2011
I am having a problem understanding the use of imtransform. I have tried to generate tform structures that can be used to convert between cartesian and polar representation of an image. The following code shows my latest attempt. The cartesian to polar transform appears to miss out the last 45 degree segment of the image. Any clues as to what I am doing wrong?
P.S. In the example of using imtransform by Steve Eddins from 2006 http://blogs.mathworks.com/steve/2006/08/04/spatial-transformations-defining-and-applying-custom-transforms/ He uses the inverse function in the tform when using it with imtransform. Surely it should be the forward function??
% Map cartesian to polar radial component in x and y.
%
% Functions for polar to cartesian conversion...
rho = @(x) sqrt(x(:,1).^2 + x(:,2).^2);
theta = @(x) atan2(x(:,1),x(:,2));
xy2rt = @(x, unused) [rho(x), theta(x)];
% and vice versa
xC = @(x) x(:,1).*cos(x(:,2));
yC = @(x) x(:,1).*sin(x(:,2));
rt2xy = @(x, unused) [xC(x), yC(x)];
% Make the tform struture.
tForm1 = maketform('custom', 2, 2, xy2rt, rt2xy, []);
% Generate a test image and note its dimensions and axes
testImage=spiral(200);
xSize=size(testImage,1);
ySize=size(testImage,2);
xSpan=[-1 1];
ySpan=[-1 1];
subplot(1,3,1), imagesc(testImage,'XData',xSpan,'YData',ySpan), axis on
% Now transform image from cartesian to polar
[rti rSpan tSpan]= imtransform(testImage, tForm1, 'UData', xSpan, 'VData', ySpan,...
'Size', [xSize ySize]);
subplot(1,3,2), imagesc(rti,'XData',rSpan,'YData',tSpan), axis on
% Make the inverse tform by swapping the function pointers.
tForm2= maketform('custom', 2, 2,rt2xy,xy2rt, []);
% Convert back to cartesian
[xyi xxSpan xySpan]= imtransform(rti, tForm2, 'UData',rSpan, 'VData', tSpan,...
'Size', [xSize ySize]);
subplot(1,3,3), imagesc(xyi,'XData',xxSpan,'YData',xySpan), axis on

Réponses (1)

Steve Eddins
Steve Eddins le 27 Mai 2011
imtransform uses the "inverse mapping" technique to compute the geometric transform of an image. See my blog posts on forward mapping and inverse mapping.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by