How to find y-axis joint similarity in two pictures

image manipulationimagemagickimages

I want to merge two pictures but I do not know how to find the cut location in y-axis by any Linux/Unix tools, but here ImageMagick as the first idea.
Any approach is welcome: a programmatic solution or a method for solving the problem with manual assistance.
Two pictures have joint similarity in y-axis, which I want to minimise and then merge for output.
Pseudocode

  1. Find the y-axis location where the data is first time equal in both pictures.
  2. Minimise the y-axis equality of two pictures as long there is no equality between the pictures.
  3. Cut each picture by appropriate location. For top by percentages here, convert -gravity SouthWest -crop 100x70%x+0+0 infile.jpg outfile.jpg. For bottom similarly, convert -gravity NorthWest -crop 100x70%x+0+0 infile.jpg outfile.jpg.
  4. To merge correct parts of two images etc (here) by convert -append A-edit.jpg B-edit.jpg output.png

Fig. 1 Image A,
Fig. 2 Image B,
Fig. 3 Expected output

enter image description here
enter image description here
enter image description here

Best Answer

Hugin will stitch these images for you.

There's a script available within the tutorial for stitching scanned images called run-scan-pto_var.sh that will do exactly what you need.

On my Debian system I need to install two packages (and, of course, their dependencies):

apt-get install hugin hugin-tools

In the interests of question completeness I've included a slightly modified version here (this version accepts image filenames on the command line instead of them being hardcoded):

#! /bin/sh
# hugin command tools script to stitch scanned images, fov unknown
# use of fov >= 10 should be OK, could simply set FOV=10
# Terry Duell 2013, 2014

# usage...run-scan-pto_var.sh outputprefix fov

#get the output file prefix
Prefix=$1

# get the fov
FOV=$2

shift 2

pto_gen --projection=0 --fov=$FOV -o project.pto "$@"
pto_lensstack -o project1.pto --new-lens i1 project.pto
cpfind -o project1.pto --multirow project1.pto
cpclean -o project2.pto project1.pto
linefind -o project3.pto project2.pto
pto_var -o setoptim.pto --opt r,d,e,!r0,!d0,!e0 project3.pto
autooptimiser -n -o autoptim.pto setoptim.pto
pano_modify  --projection=0 --fov=AUTO --center --canvas=AUTO --crop=AUTO -o autoptim2.pto autoptim.pto
pto2mk -o project.mk -p $Prefix autoptim2.pto
make -j 2 -f project.mk all

# Clean up afterwards
rm -f project.pto project1.pto project2.pto project2.pto project.mk
rm -f "$Prefix"[0-9][0-9][0-9][0-9].tif
rm -f autoptim.pto autoptim2.pto autoptim2.pto_rsp.arg
rm -f setoptim.pto

If your images are called wIowW.jpg and orMDp.jpg - as yours are named - and you want the result in rsp.tif you can run the script like this:

./run-scan-pto_var.sh rsp 10 *.jpg

The output is always written to a TIFF file. However, this format is trivially converable to just about any other image format.

The result?

enter image description here

Related Question