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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

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

Post by FrereTuck » 2018-01-27T13:10:42-07:00

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.

User avatar
fmw42
Posts: 23618
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 » 2018-01-27T14:32:56-07:00

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.

FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

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

Post by FrereTuck » 2018-01-28T03:02:02-07:00

Thanks a lot Fred, I will do it.

FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

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

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


User avatar
fmw42
Posts: 23618
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 » 2018-01-28T15:24:35-07:00

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

FrereTuck
Posts: 19
Joined: 2017-10-13T02:50:15-07:00
Authentication code: 1151

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

Post by FrereTuck » 2018-01-29T06:44:11-07:00

Thanks a lot, Fred, I do appreciate your help.
I will make some tests with your proposal.

Post Reply