1

I'm working on a PIV-Workflow and I'm currently pre-processing the images. I need to get rid of the perspective distortion in the images. I do have the "image processing toolbox" and the "camera calibrator". I already got rid of the lens distortion with "undistortImage();" and the cameraParams object, which is inferred through a chessboard pattern.

First Question: Is it possible to use the cameraParams object to distort the image perspectively, so that my chessboard is rectified in the image?

Second Question: Since I were not able to use the cameraParams object, I tried to use the transformation functions manually. I tried to use pairs of control-points (with cpselection tool, the original image and a generated chessboard-image) and the fitgeotrans(movingPoints, fixedPoints, 'projective'); function to get my tform-object. However I always get the error message:

Error using fitgeotrans>findProjectiveTransform (line 189)
At least 4 non-collinear points needed to infer projective transform.
Error in fitgeotrans (line 102)
        tform = findProjectiveTransform(movingPoints,fixedPoints);

I tried a lot of different pairs of control-points (4 pairs or more). But I'm still getting this error. I believe I must overlook something here.

Any help is appreciated, thank you.

Stephan

Dima
  • 38,860
  • 14
  • 75
  • 115
Stephan
  • 13
  • 1
  • 6
  • **first question**: The only, only only reason of getting cameraParams is to undistrot the image. Therefore its not only possible, but "mandatory". **Second**: well it seems that the poins you are giving are in a line, and they should be non-collinear! – Ander Biguri Dec 02 '14 at 15:54
  • Thanks. 1.: Yes, this is what I thought, too. To get the lens distortion, Matlab must do some perspective corrections internally. However I can't find a way to apply that correction to the image. "undistortImage()" is just doing the lens correction. 2.: My points are aranged in a rectangle or a rhomb, so not actually in a line. So this error is confusing me a little... – Stephan Dec 02 '14 at 16:02
  • Here you have the equations : http://en.wikipedia.org/wiki/Distortion_%28optics%29 – Ander Biguri Dec 02 '14 at 16:03

1 Answers1

2

If you are using one of the calibration images, then all the information you need is in the cameraParams object.

Let's say you are using calibration image 1, and let's call it I. First, undistort the image:

I = undistortImage(I, cameraParams);

Get the extrinsics (rotation and translation) for your image:

R = cameraParams.RotationMatrices(:,:,1);
t = cameraParams.TranslationVectors(1, :);

Then combine rotation and translation into one matrix:

R(3, :) = t;

Now compute the homography between the checkerboard and the image plane:

H = R * cameraParams.IntrinsicMatrix;

Transform the image using the inverse of the homography:

J = imwarp(I, projective2d(inv(H)));
imshow(J);

You should see a "bird's eye" view of the checkerboard. If you are not using one of the calibration images, then you can compute R and t using the extrinsics function.

Another way to do this is to use detectCheckerboardPoints and generateCheckerboardPoints, and then compute the homography using fitgeotform.

Dima
  • 38,860
  • 14
  • 75
  • 115