-->

Error in removing the fisheye lens distortion of a

2019-09-10 18:09发布

问题:

This question already has an answer here:

  • correcting fisheye distortion programmatically 6 answers

I have the following image:

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?

回答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!