Crate meander or snake style montage

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?".
Locked
klequex
Posts: 2
Joined: 2020-03-09T09:39:49-07:00
Authentication code: 1152

Crate meander or snake style montage

Post by klequex »

I've been trying to combine multiple images a microscope took of steel samples into a montage. The files are not ordered left-to-right in every line, but switch between ltr and rtl like so:
Image

I've tried with the standard tile code, but it doesn't produce what I want:

Code: Select all

montage -density 600 -tile 8x0 -geometry +0+0 -border 0 -limit memory 0 *.bmp out.bmp
Thanks for your help.

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

Re: Crate meander or snake style montage

Post by fmw42 »

You have to montage or append one row at a time. In the even numbered row you should include -reverse after reading the images and it will then reverse the order. After you have each row, you can then append them to form the output. A script loop will do all this.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Crate meander or snake style montage

Post by snibgo »

I would do it by renaming files, or creating symbolic links to all the files. A fairly simple shell loop could do that.
snibgo's IM pages: im.snibgo.com

User avatar
GeeMack
Posts: 757
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Crate meander or snake style montage

Post by GeeMack »

klequex wrote:
2020-03-09T09:44:51-07:00
I've been trying to combine multiple images a microscope took of steel samples into a montage. The files are not ordered left-to-right in every line, but switch between ltr and rtl like so:
You can arrange the images into the correct order in a shell script or by renaming the files as snibgo and fmw42 mentioned. You can create the same sort of montage using "convert" with some "+append"s. A command like this is an example...

Code: Select all

convert *.bmp -write mpr:imgs -delete 0--1 \
   \( mpr:imgs[0-7] +append \) \
   \( mpr:imgs[15-8] +append \) \
   \( mpr:imgs[16-23] +append \) \
   \( mpr:imgs[31-24] +append \) \
   \( mpr:imgs[32-39] +append \) \
      -append +repage out.bmp
That command starts by reading the input images into a temporary memory register. Then inside the parentheses it essentially reverses the order of the images in every other row by reading those rows in reverse from the memory register like "mpr:imgs[31-24]". It appends the images in each row horizontally inside the parentheses, and finishes by appending all the rows vertically. It works with ImageMagick 6.8.9 in a bash shell. To make it work in Windows, change the continued-line backslashes "\" to carets "^", and get rid of the backslash escapes "\(...\)" around the parentheses "(...)".

klequex
Posts: 2
Joined: 2020-03-09T09:39:49-07:00
Authentication code: 1152

Re: Crate meander or snake style montage

Post by klequex »

GeeMack wrote:
2020-03-09T20:22:05-07:00
klequex wrote:
2020-03-09T09:44:51-07:00
I've been trying to combine multiple images a microscope took of steel samples into a montage. The files are not ordered left-to-right in every line, but switch between ltr and rtl like so:
You can arrange the images into the correct order in a shell script or by renaming the files as snibgo and fmw42 mentioned. You can create the same sort of montage using "convert" with some "+append"s. A command like this is an example...

Code: Select all

convert *.bmp -write mpr:imgs -delete 0--1 \
   \( mpr:imgs[0-7] +append \) \
   \( mpr:imgs[15-8] +append \) \
   \( mpr:imgs[16-23] +append \) \
   \( mpr:imgs[31-24] +append \) \
   \( mpr:imgs[32-39] +append \) \
      -append +repage out.bmp
That command starts by reading the input images into a temporary memory register. Then inside the parentheses it essentially reverses the order of the images in every other row by reading those rows in reverse from the memory register like "mpr:imgs[31-24]". It appends the images in each row horizontally inside the parentheses, and finishes by appending all the rows vertically. It works with ImageMagick 6.8.9 in a bash shell. To make it work in Windows, change the continued-line backslashes "\" to carets "^", and get rid of the backslash escapes "\(...\)" around the parentheses "(...)".
Wow thanks! That's exactly what I was searching for!

User avatar
GeeMack
Posts: 757
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Crate meander or snake style montage

Post by GeeMack »

klequex wrote:
2020-03-10T10:55:53-07:00
Wow thanks! That's exactly what I was searching for!
There are often several approaches to achieve the same result with ImageMagick. Here is another command that does the same thing. It uses "-clone" to re-order the input images, and "-append" to assemble them into a grid...

Code: Select all

convert *.bmp \( -clone 0-7,15-8,16-23,31-24,32-39 +append -crop 5x1@ -append -write out.bmp \) null:
First that reads in all the input images. Then inside the parentheses it uses "-clone" to make another list in the properly re-arranged order. It appends those into one long row, crops that into five short rows, and appends them vertically to finish the grid. Still inside the parentheses it writes the output file "out.bmp". Then after the parentheses it simply writes the original input images to nowhere, IM's built-in "null:".

Locked