You must use
+distort so that that distort will calculate an appropriate canvas size and virtual offset for the distorted image.
Hmmm... lit looks to me like the actual location specified by the transformat matrix may also be given as pixel coodinates.
Try adding 0.5 to the matrix values of index 2 and 5 (the big values which are pixel coodinates)
Also save to PNG if you want to preserve the transparency!!! otherwise you get a un-aliased edges on the JPEG image!
To overlay with a different background color change the
-background setting before the
-layers merge
Code: Select all
convert rd2.jpg -alpha set -virtual-pixel transparent \
+distort PerspectiveProjection \
"0.7635364058950651, 0.3438769700704157, 56.6722052397604020,
-0.4476195206801218, 0.8427856192168595, 79.6955261689579830,
-0.0003992035432886, -0.0000913103642461" \
rd1.jpg +swap -background black -layers merge +repage result.jpg
That seems to line up better, and now matches the previous results.
I think the images still contain some lens distortion as well, as the join is worst in the very corner. That hat will need to be corrected, generally before doing the image registration and matrix determination, for the perspective distortion.
Note if you plan on overlaying more images, leave the background transparent, and remove the +repage (remove virtual canvas offsets from save to intermediate results, then repeat with the next image. A non-lossy PNG or MIFF image file format is a must for repeated processing!
However you can distort each image, and overlay them all in the one command...
Code: Select all
convert rd1.jpg +alpha set \
\( rd2.jpg ... +distort .... \) \
\( rd3.jpg ... +distort .... \) \
\( rd4.jpg ... +distort .... \) \
-background {color} -layers merge +repage \
result.png