# How to adjust a image as the empty image

As Vitaliy Kaurov's answer mentioned, anyone can use a method based on Neural Network (NN) to give a try? Then the bounty is deserved.

Suppose I have a empty paper like

Then I write some text on the paper,then the result paper have been distorted,rotated and translated.like

How to adjust the result papper according the original empty paper? As you see,some empty transverse line can align this two images. The result like following is expected.

Actually I think the ImageAlign can help me(it cannot align a distorted image as its documentation).

ImageAlign[template, img, TransformationClass -> "Similarity"]


But it is a very slow and give me a poor result.Can anybody give a better solution for this?

• Can you post images with clear external borders - this could help significantly. Aug 13, 2017 at 7:37
• @VitaliyKaurov But it don't have a clear external borders...The post have all information I have.
– yode
Aug 13, 2017 at 7:40
• ImageAlign works with the following transformations (as per the help): Translation, Rigid, Similarity, Affine, Perspective. The transformation of your paper looks to be nonlinear and/or spatially varying, so it is unlikely to work. Aug 13, 2017 at 14:13
• @bills Yes,I have read that before I post this question.
– yode
Aug 13, 2017 at 14:58
• "The result like following is expected." --- how did you get that result? Aug 13, 2017 at 22:07

I will give just a start, which I think is not bad already. First just for faster computing times I resize your images:

i1 = ImageResize[Import["https://i.sstatic.net/nerv4.jpg"], 400];
i2 = ImageResize[Import["https://i.sstatic.net/czNNK.jpg"], 400];


Next FindGeometricTransform

{e, t} = FindGeometricTransform[i1, i2]


Then you can go both ways which give you same result, but 1st is faster:

ImagePerspectiveTransformation[i2, t, DataRange -> Full]


or

ImageForwardTransformation[i2, t, DataRange -> Full]


The same result could be obtained as

pts = ImageCorrespondingPoints[i1, i2];
{cpe, cpt} = FindGeometricTransform @@ pts
ImagePerspectiveTransformation[i2, t, DataRange -> Full]


You can try playing with ImageFeatureTrack, ImageLines, and some manual manipulation of extracted features, for example manual specification or editing points/lines after ImageCorrespondingPoints/ImageLines before they go into FindGeometricTransform. You could also try training a Neural Network (NN) on a bunch if similar simulated transformations. Advantage of NN is it could potentially be very fast.

• As I know,those matrix just can process linear transformation..
– yode
Aug 14, 2017 at 1:37
• @yode, why do you believe the distortion in your images cannot be approximated by a linear fractional transformation? Aug 14, 2017 at 1:53
• @J.M. I just juess,I think that cannot be solved by a matrix transformation.I think we need a new solution. And I think this answer is a good start.
– yode
Aug 14, 2017 at 1:57
• I'm confused still.If we use a NN method. How to get those trianning image. I mean if I just trainnig the image posted in the question with different transform. Then we can deal with other image with different transform?
– yode
Sep 14, 2017 at 6:52
• I don't very familar thos NN thing..I have to give you still.
– yode
Sep 20, 2017 at 19:21