Image projection (homography with 4 points)

10 visualizzazioni (ultimi 30 giorni)
Margherita Dotti
Margherita Dotti il 12 Set 2022
Risposto: Pratyush Swain il 26 Set 2023
Hello,
I have to project an image taken from an angle into a specific plane, so that that I can look straight at that plane.
Following How to find projective transformation with 4 points? - MATLAB Answers - MATLAB Central (mathworks.com) I wrote the code here below, but do not get any reasonable image as output.
I am not sure what I do wrong. Is it the reference system or?
img_in = imread('Test_D9.jpg');
% 4 3D points on the laser sheet plane
pA = [0 2.1 0 1]'; % [m]
pB = [4.2 6 0 1]'; % [m]
pC = [4.111 3.929 0 1]'; % [m]
pD = [2.056 3.015 0 1]'; % [m]
worldPoints = [pA pB pC pD]';
% modify the ref system to agree with the pin --> needed??
worldPoints(:,1) = (5-worldPoints(:,1));
worldPoints(:,2) = (7-worldPoints(:,2));
pA_projected = [2300 1332]'; % px center light
pB_projected = [560 272]'; % px higher point
pC_projected = [536 1484]'; % px probe tip
pD_projected = [1548 1376]'; % px probe half
imagePoints = [pA_projected(1:2) pB_projected(1:2) pC_projected(1:2) ...
pD_projected(1:2)]';
% Homography
H = fitgeotrans(imagePoints,worldPoints(:,1:2),'projective');
xWorldLimits = [0.5 5.5];
yWorldLimits = [0.5 5.5];
imref = imref2d([diff(yWorldLimits), diff(xWorldLimits)]*1e3, xWorldLimits, yWorldLimits);
% This way, each px is 1mm
%Attempt
[img_out, img_out_size] = imwarp(img_in,(H),'OutputView',imref);
figure()
imshow(img_out,img_out_size)
If you could help, I'd be very glad :)

Risposte (1)

Pratyush Swain
Pratyush Swain il 26 Set 2023
Hi Magheritta,
I understand you want to perform projective transformation and you are using the 'fitgeotrans' function for the same.Please refer to this matlab answer - https://in.mathworks.com/matlabcentral/answers/1817630-i-am-having-a-query-in-image-transformation-on-fitgeotform2d-function-can-anyone-please-explain-wha , where it has been demonstrated how to perform projective tranformation on a sample image.
Please note 'fitgeotrans' is not recommended to use for MATLAB version since R2022b, it has been replaced by 'fitgeoform2d'.
Hope this helps.

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by