Losing resolution after transformation using imwarp

7 views (last 30 days)
I'm working on a camera calibration through a series of pictures of a checkerboard. The original size of the images are 2048x2448. After transformation, the resulting corrected image with 'imwarp' is only 310x367. Although the transformation seems correct, the resolution seems very low to me and I'm wondering why the resolution dropped so significantly. The transformation I performing is some minor intrinsic/extrinsic corrections.
Here is the code used. The variable 'cameraParams' is obtained after successfully using the "camera calibration tool" from the "Computer Vision Toolbox v10.2". Both the raw image (.bmp) and the 'cameraParams.mat' are attached.
Thanks for the help.
[im_a, newOrigin] = undistortImage(imread(strcat(figlocation,fig_name)), cameraParams);
imagePoints = squeeze(cameraParams.ReprojectedPoints(:,:,end));
tf = fitgeotrans(imagePoints,cameraParams.WorldPoints,'projective');
[xf1,xf1_ref] = imwarp(im_a,tf,'cubic');
im_b=rot90(xf1);
figure;imshow(im_a);title('image')
figure;imshow(im_b);title('transformed image')

Accepted Answer

Matt J
Matt J on 5 Jan 2023
load cameraParams
im0=imread('b8-12212022142637-2006.Bmp');
[im_a, newOrigin] = undistortImage(im0, cameraParams);
imagePoints = squeeze(cameraParams.ReprojectedPoints(:,:,end));
tf = fitgeotrans(imagePoints,cameraParams.WorldPoints,'projective');
[~,xf1_ref] = imwarp(im_a,tf,'cubic');
xf1_ref.ImageSize=flip(size(im_a));
[xf1,xf1_ref] = imwarp(im_a,tf,'cubic','OutputView',xf1_ref);
im_b=rot90(xf1);
figure;imshow(im_a);title('image')
figure;imshow(im_b);title('transformed image')
  2 Comments
Jos Muller
Jos Muller on 5 Jan 2023
Edited: Jos Muller on 5 Jan 2023
Thanks Matt,
Neat solution.
Sofar I understand from your awnser, imwarp default changes the imageSize of the projected image to 367x310. To prevent this, you first generate a 'imref2d' object where you manually change the image size. By then explicitly mention the 'outputview' parameter, 'imwrap' retains the image resolution. Is this correct?
However, aside the resolution, the projection from pixels to actual distances through worldpoints seems to be affected by this solution as well. In the projection I want the checkerboard to correspond to 20 mm distance (as in 'cameraParams.WorldPoints' mat-file. However, when measuring the distance in imtool(im_b), this now looks like 138 (mm?)
Best,
Jos
Matt J
Matt J on 5 Jan 2023
Edited: Matt J on 5 Jan 2023
imtool() is assuming the pixel sizes are 1 mm. I'm not aware if there is a way to tell it that the actual pixel sizes are about 0.15 mm,
xf1_ref =
imref2d with properties:
XWorldLimits: [-76.6815 233.3185]
YWorldLimits: [-105.2473 261.7527]
ImageSize: [2448 2048]
PixelExtentInWorldX: 0.1514
PixelExtentInWorldY: 0.1499
ImageExtentInWorldX: 310
ImageExtentInWorldY: 367
XIntrinsicLimits: [0.5000 2.0485e+03]
YIntrinsicLimits: [0.5000 2.4485e+03]

Sign in to comment.

More Answers (0)

Categories

Find more on Display Image in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!