How to combine pairs of images to single images?

convert -quality 50 Image_L.jpg Image_R.jpg +append Result.jpg

Gives this:

Are all images mirrored? Than it could be done easier :grinning:.

I found that out on my own, and I’ve got a working code that uses adjoin instead of tile

Now I’m trying to get it to work in a “for” statement

Question - I’m almost there but I can’t seem to get the for statement working as I want it to

This is what I had written

for index in $(seq 1 2 10)
do
montage -adjoin -quality 100 -background none -geometry +0+0 $index.jpg
done

Now what happens is that if there are more than 2 images, the combined image keeps on combining the other pairs so that it has 4 images combined, and then 8 and then 12 and keeps on getting bigger and bigger

@Chintan_Gohel The best place to ask your ImageMagick questions is on its forum: http://www.imagemagick.org/discourse-server/viewforum.php?f=1

Like @Thomas_Do, I would use +append. Also, height won’t matter if you resized the images. Try doing

magick rose: logo: -resize x400 +append result.png

As for the for statement, what you are currently doing is repeating the montage action and adding your output file in every next iteration. This will gobble up your memory and disk space fast. Instead, the image pairs should be replacing rose: and logo: in my example and the result filename should also be changing. My bash is a little rusty so I will let someone else help you with that.

PS magick is IM7’s convert, so if you are using IM6, do

convert rose: logo: -resize x400 +append result.png

I’ve noticed that the bash console would hang and now 6Gb have been used up - how can I clear that?

You missed my new post just now :slight_smile:. Please read it.

If your files are in alphabetical order and you want then to join successive pairs, this should work:

array=($(find . -name "*.jpg"| sort)); for (( i=0; i<${#array[@]}/2; i++ )); do convert -quality 100 ${array[i*2]} ${array[i*2+1]} +append Result$i.jpg; done

However, the files are not allowed to contain whitespaces.

Edit: changed to formatted code with backticks

  1. Please see Format your code to make it more readable
  2. The way you used $index makes montage only use it as a target, meaning you did not specify the source files, so montage uses all the files it finds as source and explodes when you run out of RAM. Instead, if you refer to the ridiculously long documentation I linked to in my previous post, you should specify the source files first, and the target file last. So change:
for index in $(seq 1 2 10); do
    montage -adjoin -quality 100 -background none -geometry +0+0 $index.jpg
done

to

for i in {1..100..2}; do
    montage -quality 92 -background white -tile 2x1 -geometry +0+0 "${i}.jpg" "$((i+1)).jpg" "output_${i}-$((i+1)).jpg"
done

To help you understand the code:

1 Like

I read it but I haven’t tried the rose logo code yet
And yes, a lot of space has been used up and I also have to worry about getting that space back

I tried this but nothing seems to happen - I don’t see any output or new files

I’m getting a bad substitution error

There was a formatting error, you have to format code here as preformatted text. I edited the post. Please try again. You have first to “cd” into the right directory.

Fixed, I changed ${001..100..2} to {1..100..2}

Sorry, I wasn’t being clear. What you were doing was

1st iteration: Montage of Image 1 + 2
2nd iteration: Montage of Image 3 + 4 + Montage of Image 1 + 2

As you can see, things would get out of hand very quickly, resulting in memory and disk overload! I suggest that you test your commands/scripts using dummy images like rose: or logo: that are smaller in size and therefore quicker to process and detect your mistakes. I have generated some images for you to use while determining your workflow:


Edit #1: I zipped the files to make it easier to download: color_blocks.zip (764 Bytes).

So, my new command would be

for i in {1..100..2}; do
    magick "${i}.png" "$((i+1)).png" +append "output_${i}-$((i+1)).jpg"
done

I am using Win7 ATM, so I will let you give the command a whirl.


Edit #2: I changed the first jpgs to pngs since that is what the color blocks are. If you are using tifs, then change them to tif, etc.

IT’S WORKING I’m almost crying here, it’s working!

It’s running through the whole set now, completed 150, 664 to go

Edit: all images have been combined, I’m going to post my video here once I’ve finished all the other processing

4 Likes

Good morning,

My video is almost ready - so I’ll be uploading it soon. In the meantime, can I acknowledge you in the video caption when I upload it on Youtube?

1 Like

Why not :slight_smile: Maybe better to mention this forum.

2 Likes

So here is my video: Nairobi Night timelapse version 2

4 Likes

@Chintan_Gohel That was interesting! Look forward to seeing more time lapses from you :slight_smile:.

Very cool! Special shout out to @Morgan_Hardwood