Application of the projection matrix: Removing perspective distortion

I know that there are many posts about image treatment, but I still have trouble with this little challegene. Baisically I want to remove the perspective distorsion form this image: (source: http://www.canvas-of-light.com/2015/03/how-to-correct-perspective-distortion-in-lightroom-5/)

How I started:

1. Find two points witth should have the same x-coordinates:
x11 = 634.0260655160307; y11 = 672.1241170908934; x12 = 608.4425576092435; y12 = 523.0723753730896; Show[notreDame,   Graphics[{Point[{x11, y11}, VertexColors -> Green],     Point[{x12, y12}, VertexColors -> Green]}]]

1. Find two other points witth should have the same x-coordinates:
x21 = 926.9209508015505; y21 = 611.3228302929783; x22 = 938.2421227197373; y22 = 516.5080154781632; Show[notreDame,   Graphics[{Point[{x21, y21}, VertexColors -> Green],     Point[{x22, y22}, VertexColors -> Green]}]]

Now I use the projection formulas which map the homogenious (undeformed) to the inhomogenious (deformed) coordinates, to find the transformation matrix:

$x'=\frac{h00*x+h01*y+h02}{h20*x+h21*y+h22}$

$y'=\frac{h10*x+h11*y+h12}{h20*x+h21*y+h22}$

So we have found the inhomogenious coordinates of the points. (in distorted image) To find the corresponding homogenious coordinates (in undeformed image) let's choose the common x-Value in both sets of points. The inhomognious y-values are considered to be the same as the homogenious y-values (apporx.).

x11h = x11; y11h = y11; x12h = x11; y12h = y12; x21h = x21; y21h = y21; x22h = x21; y22h = y22;

Now we get a system of equation that we can solve for the matrix coefficient. We set h00=1, since the matrix needs only to be determined up to a insigniﬁcant multiplicative factor.

h00 = 1; coef = NSolve[{    x11 == (h00*x11h + h01*y11h + h02)/(h20*x11h + h21*y11h + h22),     y11 == (h10*x11h + h11*y11h + h12)/(h20*x11h + h21*y11h + h22),    x12 == (h00*x12h + h01*y12h + h02)/(h20*x12h + h21*y12h + h22),     y12 == (h10*x12h + h11*y12h + h12)/(h20*x12h + h21*y12h + h22),    x21 == (h00*x21h + h01*y21h + h02)/(h20*x21h + h21*y21h + h22),    y21 == (h10*x21h + h11*y21h + h12)/(h20*x21h + h21*y21h + h22),    x22 == (h00*x22h + h01*y22h + h02)/(h20*x22h + h21*y22h + h22),     y22 == (h10*x22h + h11*y22h + h12)/(h20*x22h + h21*y22h + h22)    },   {h01, h02, h10, h11, h12, h20, h21, h22}   ]  projeMat =    Flatten[{{h00, h01, h02}, {h10, h11, h12}, {h20, h21, h22}} /. coef,     1];

The output has imaginary values ??

To remove the perspective distortion, we need to inverse the transformation matrix and apply it to the image:

invProjeMat = Inverse[projeMat];  ImageTransformation[notreDame, TransformationFunction[invProjeMat]]

...but this is not working? HELP !!

Thanks for any help!!

Replay

Actually I think this post maybe duplicated with this.This is my current solution

verticalQ[{{x1_, y1_}, {x2_, y2_}}] :=
Abs[[email protected][Subtract @@@ [email protected]{{x1, y1}, {x2, y2}}]] > 5
lines = ImageLines[
Method -> {"Canny", "StraightEdges" -> 0.2}]];
verLine = Select[lines, verticalQ];
HighlightImage[img, {Orange, Line /@ verLine}]

Find the vanish point.

v = {vx, vy} =
[email protected]@
FindMinimum[
Total[RegionDistance[[email protected]#, {mx, my}] & /@
verLine], {mx, my}]

{743.061, 2161.01}

{k, g} = ImageDimensions[img];
ImageTransformation[img, {Times @@ (# - v)/g + vx, #[]} &,
DataRange -> Full] Of course you can get rid of the black part.I just show the method in this answer.

Category: image processing Time: 2016-07-30 Views: 0