# What is the third coordinate in “Projective Transformation” of an image and how to build the matrix of the inverse transform?

I am trying to understand the formalism of the projective transform of 2D image. it has 9 parameters (a-i) which the 9th is redundant since we use houmogenous coordinates. this transformation preserves only straight lines.

$\pmatrix{x'\\ y' \\ w'}$ = $\pmatrix{ a& b& c\\\ d& e& f \\\ g& h& i}$ $\pmatrix{x\\ y \\ w}$

I have three questions according this formalism:

1. Since the redundancy (from 8 to 9) of degrees of freedom is $i=1$ ?
2. what is the $w$ and $w'$ ? are they parameters? how do i calculate them?
3. How can I find the parameters so I can transform the image to its original(from the black background image to the square one).

what I want to do is build the matrix to transform this image: and find matrix $M$

so I get back this image: All the images above taken from here

What I want finally do is to find the

M = [a  b c;
d  e f;
g  h i];

t_proj = maketform('projective',T);
I_projective = imtransform(I,t_proj,'FillValues',.3);
imshow(I_projective)
title('unprojective - rectangular carpet')


taken from here

You have to understand that projective transformation is not linear. It's $(x,y) -> (X(x, y)/Z(x,y) , Y(x, y)/Z(x,y))$, where X, Y, Z - linear functions.
$w$ and $w'$ are essential here - they help represent this non-linear transformation as linear - matrix multiplication - and that way this linear representation is a homomorphism (preserve "chaining" of operations).$w$ for input image is usually taken as $1$; You get $w'$ from matrix multiplication ($w' = gx + hy + iw$ ) and the end result of transform is $(x'/w', y'/w')$
Generally speaking you can't just assign $i=1$, but due to homogeneity you can divide all the matrix by $i$ and get new matrix, representing the same transform with right-left element $1$