Page 1 of 1

Matching two images (an original and a scanned & modified one)

Posted: 2018-01-27T13:10:42-07:00
by FrereTuck
Hi,

I have a use case of an image (a drawing) I am producing with Gimp that I have to modify once printed and then create a new layer with the modifications I have made by hand (once scanned).
For the time being, that has proved pretty difficult and not very precise I may say.
The original image is 4960x3508px and the printed/scanned one is 9930x7040.
Just resizing it doesn't quite make the trick.
I know imagemagick is able to get the differences between the two images, but would it be possible for it to rescale the scan precisely so that the drawings are the same size as the original ones, and then find the differences between the original and the resulting image so that we can create a new image with the difference?
Thanks a lot.

Re: Matching two images (an original and a scanned & modified one)

Posted: 2018-01-27T14:32:56-07:00
by fmw42
You would have to pick at least 3 control points on each image. Then use +distort Affine to warp the one to match the other. Then do the difference processing with either -compose difference -composite or with compare.

ImageMagick does not have any method of automatically aligning the two images. If these are line drawings, then the alignment needs to be very precise otherwise you would get almost everything as different due to shifts between the lines.

Perhaps you might upload your two images to some free hosting service that won't change your images, such as dropbox.com and put the URLs here, so we can see your problem.

Re: Matching two images (an original and a scanned & modified one)

Posted: 2018-01-28T03:02:02-07:00
by FrereTuck
Thanks a lot Fred, I will do it.

Re: Matching two images (an original and a scanned & modified one)

Posted: 2018-01-28T13:54:34-07:00
by FrereTuck

Re: Matching two images (an original and a scanned & modified one)

Posted: 2018-01-28T15:24:35-07:00
by fmw42
Pick 3 or more corresponding corner on each image and get their coordinates. The do an affine transformation to align them. See
https://www.imagemagick.org/Usage/disto ... ol_leastsq
https://www.imagemagick.org/Usage/distorts/#affine

This will give you some idea how. I did not pick enough control points nor probably accurately enough.

convert modifs_de_janvier_scannées.png -define distort:viewport=4960x3508+0+0 \
+distort Affine "357,2012 218,1008 8683,1716 4273,865 5844,5543 2958,2673 398,5415 234,2703" \
modifs_de_janvier_scannées_affine.png

The viewport size is the size of the sectors_diagram_A3.png image. The coordinates are X1,Y1 x1,y1 X2,Y2 x2,y2 ..., where X,Y are from the modifs_de_janvier_scannées.png and x,y are from sectors_diagram_A3.png

Re: Matching two images (an original and a scanned & modified one)

Posted: 2018-01-29T06:44:11-07:00
by FrereTuck
Thanks a lot, Fred, I do appreciate your help.
I will make some tests with your proposal.