0

I have the following image:

enter image description here

I want to remove the fisheye lens distortion from this image, so I used the following code:

[X,map] = imread('Foam_Image.jpg');  % Read the indexed image
options = [size(X,1) size(X,2) 1];   % An array containing the columns, rows and exponent
tf = maketform('custom',2,2,[],...   % Make the transformation structure
               @fisheye_inverse,options);
newImage = imtransform(X,tf); 
imshow(newImage);                    % show image

But I get the following error:

Error using imtransform>parse_inputs (line 438)
XData and YData could not be automatically determined.  Try specifying XData and YData explicitly in the call to
IMTRANSFORM.

Error in imtransform (line 265)
args = parse_inputs(varargin{:});

I also used imwarp instead of imtransform, but I still get an error. Anyone has any idea why do I get this error and how to fix it?

Bowecho
  • 899
  • 2
  • 8
  • 17

1 Answers1

1

As the message says, you need to manually specify the XData and YData properties during the call to imtransform with the Name-Property arguments syntax.

According to the docs, XData for example is:

A two-element, real vector that, when combined with 'YData', specifies the spatial location of the output image B in the 2-D output space X-Y. The two elements of 'XData' give the x-coordinates (horizontal) of the first and last columns of B, respectively.

and likewise for YData. Therefore, you could modify your call to imtransform like so:

newImage = imtransform(X,tf,'XData',[1 col],'YData',[1 row]);

where col and row are the output of the size function you calculated earlier.

Hope that helps!

Benoit_11
  • 13,905
  • 2
  • 24
  • 35
  • Thank you for your answer, but I still have an error. I did like this: `x = size(X,1); y = size(X,2); newImage = imtransform(X,tf,'XData',[1 x],'YData',[1 y]);` – Bowecho Jun 29 '15 at 13:16
  • 1
    `XData` represents the number of columns, so here it would be `[ 1 size(X,2) ] ` Maybe that's not the cause of the error though. – Benoit_11 Jun 29 '15 at 13:20
  • Yea, sorry, I meant `x=size(X,2)`, so the error is still there. I think I am using the wrong function though, `@fisheye_inverse`, because I want to remove the fisheye distortion from an already distorted image, not to implement it.. this function actually implements the distortion, I think. – Bowecho Jun 29 '15 at 13:25
  • mhh yes actually I think you're right. Have you taken the function [here](http://stackoverflow.com/questions/2589851/how-can-i-implement-a-fisheye-lens-effect-barrel-transformation-in-matlab)? – Benoit_11 Jun 29 '15 at 13:33
  • Yes, that's correct. Unfortunately, I don't know of any function that inverses the distortion. – Bowecho Jun 29 '15 at 13:39
  • Me neither sorry. If you have the Computer Vision Toolbox you might want to check [here](http://stackoverflow.com/questions/12117825/how-can-i-undistort-an-image-in-matlab-using-the-known-camera-parameters) – Benoit_11 Jun 29 '15 at 13:42
  • Thank you, I am checking out. – Bowecho Jun 29 '15 at 14:20