I am having a query in image transformation on fitgeotform2d function. Can anyone please explain what is moving points and fixed points and how to find them please?

5 views (last 30 days)
I want to transform a narrow view image into a bied eye view projection on ADAS image. I selected the control points for the projection in this image. Please help me.
clear; close all
filename = 'C:\Users\dines\Downloads\43a.jpg';
img = im2double(rgb2gray(imread(filename)));
name = 'check2';
msgid = 'Images:initSize:adjustingMag';
warning('off',msgid);
imshow(img);
roadmarking=img;
[ xi , yi ] = getpts;
c = [ cpstruct.inputPoints(:,1) ]';
r = [cpstruct.inputPoints(:,2) ]';
base = [0 11; 11 11; 11 0; 0 0];
tf = fitgeotrans([c r],base*80,'projective');
disp('tf = ');
disp(tf)
T = tf.T;
disp('T =');
format short g
disp(T);
imshow(img);
hold on;
plot([c;c(1)],[r;r(1)],'r','Linewidth',2);
text(c(1),r(1)+20,'0, 11','Color','y');
text(c(2),r(2)+20,'11, 11','Color','y');
text(c(3),r(3)-20,'11, 0','Color','y');
text(c(4),r(4)-20,'0, 0','Color','y');
hold off;
F = getframe();
g = frame2im(F);
imwrite(g,[name '_overlay.jpg']);
[xf1, xf1_ref] = imwarp(img,tf);
imshow(xf1)
xf1_ref
imwrite(xf1,[name '_registered.jpg']);
bdi = [1 1; 1280 1; 1280 960; 1 960];
fill(bdi(:,1),bdi(:,2),'b');
axis ij;
hold on
fill(c,r,'r');
hold off
axis equal
% show the transformed simplified image
rd = transformPointsForward(tf,[c r]);
bds = transformPointsForward(tf,bdi);
fill(bds(:,1),bds(:,2),'b')
axis ij
hold on
fill(rd(:,1),rd(:,2),'r')
axis equal
hold off
% show that the control points map to the target points
prd = [c r ones(4,1)]*T;
% B = repmat(A,M,N) creates a large matrix B consisting of an M-by-N
% tiling of copies of A.
% This is used to produce two copies of the the third, homogeneous
% variable. The end result is to convert homogeneous to normal variables.
uv = prd(:,1:2)./repmat(prd(:,3),1,2);
disp('uv/80 = ');
disp(uv/80)
xf1_ref.XWorldLimits = [-500 1500];
xf1_ref.YWorldLimits = [-800 1200];
xf1_ref.ImageSize = [2000 2000];
[xf2 xf2_ref] = imwarp(img,tf,'OutputView',xf1_ref);
xf2_ref
imshow(xf2)
imwrite(xf2,[name '_truncated.jpg']);
warning('on',msgid);

Answers (1)

Pratyush Swain
Pratyush Swain on 19 Sep 2023
Edited: Pratyush Swain on 19 Sep 2023
Hi Dinesh,
I understand you want to create a bird's eye view projection of the given image.
Please go through the following implementation where i have leveraged 'fitgeotrans' function and 'imwarp' fucntion to create a transformed image:
% Load Image
filename = '43a.jpg';
image = imread(filename);
% Define the source and destination points for the transformation
sourcePoints = [0,780;1920,780;1920,1080;0,1080];
destinationPoints = [0,0;1920,0;1920,1080;0,1080];
% Create a projective transformation object
tform = fitgeotrans(sourcePoints, destinationPoints, 'projective');
% Apply the transformation to the image
transformedImage = imwarp(image, tform);
% Display the original and transformed images
figure;
imshow(transformedImage);
title('Bird''s Eye View Image');
Please note 'fitgeotrans' is no longer recommended since R2022b release,you can use 'fitgeotform2d' function instead.
Hope this helps.

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!