I have 2 images of the same size, called image1.png
and image2.png
. In ImageMagick, is there any way to merge the two images by taking the odd lines from image1.png
and merge with the even line from image2.png
?
Sure, make alternate rows transparent:
# Make red test image
convert -size 300x200 xc:red red.png
# Make blue test image
convert -size 300x200 xc:blue blue.png
# Merge with alternate lines made transparent
convert red.png \( blue.png -alpha on -channel A -fx 'j%2' \) -composite result.png
Or, an alternative way of thinking about it is to load both images and then choose pixels from either the first (u
) or the second (v
) depending on the row:
convert red.png blue.png -fx 'j%2 ? u : v' result.png
On Windows, these two come out as:
REM Do Windows style commands
convert red.png ^( blue.png -alpha on -channel A -fx "j%2" ^) -composite result.png
and
REM Windows style
convert red.png blue.png -fx "j%2 ? u:v" result.png
If you want vertical interlace instead of horizontal interlace, just change the j
to i
in all above examples.