How to improve image output from montage in ImageMagick?
Asked Answered
S

3

21

I joined images using montage, but the resolution of the image output is less than that of the image's input.

My image's input have dimensions of 640x480 each

But the output that I get was 256x378

I was searching in the web and couldn't find a solution to improve the output's image quality.

The montage command that I'm using

montage -tile 2x3 1.png 2.png 3.png 4.png 5.png 6.png -resize 1024x1024  montage_png.png

Anyone know how can I get better output resolution?

Swaim answered 17/1, 2016 at 1:46 Comment(0)
A
8

Suggestion 1

Try it this way... let montage organise the images into a montage and then pass the result on to convert to do the resizing of the result.

montage -tile 2x3 1.png 2.png 3.png 4.png 5.png 6.png miff:- | convert miff:- -resize 1024x1024 montage.png

The intermediate image is passed as a MIFF (Magick Image File Format) which preserves all detail and metadata and quality.

Suggestion 2

If it is always just 5 or 6 images and not hundreds, you can also do it all in one go with convert like this. All you need to know is that +append joins images in a row and -append joins images in a column. So I am joining 1&2 in a row, 3&4 in a row, 5 & 6 in a row and then putting the three rows in a stack and resizing the result.

convert [12].png +append \( [34].png +append \) \( [56].png +append \) -append -resize 1024x1024 result.png

enter image description here

Alainealair answered 18/1, 2016 at 8:0 Comment(2)
Lot of thanks! The first method produce the same problem, but the second work perfectly...Swaim
Need -mode concatenate in the first approach or the OP's attempt.Dellinger
G
26

Set the mode of operation style (-mode) to the concatenate value (as in the documentation).

For example:

montage -mode concatenate file1.jpg file2.jpg output.jpg
Grind answered 18/4, 2017 at 13:32 Comment(2)
worked just fine for me! montage *.jpg -mode concatenate -tile 4x5 MONTAGE.jpgPoliard
But if you run it a second time, what happens? See my answer below:Carbon
A
8

Suggestion 1

Try it this way... let montage organise the images into a montage and then pass the result on to convert to do the resizing of the result.

montage -tile 2x3 1.png 2.png 3.png 4.png 5.png 6.png miff:- | convert miff:- -resize 1024x1024 montage.png

The intermediate image is passed as a MIFF (Magick Image File Format) which preserves all detail and metadata and quality.

Suggestion 2

If it is always just 5 or 6 images and not hundreds, you can also do it all in one go with convert like this. All you need to know is that +append joins images in a row and -append joins images in a column. So I am joining 1&2 in a row, 3&4 in a row, 5 & 6 in a row and then putting the three rows in a stack and resizing the result.

convert [12].png +append \( [34].png +append \) \( [56].png +append \) -append -resize 1024x1024 result.png

enter image description here

Alainealair answered 18/1, 2016 at 8:0 Comment(2)
Lot of thanks! The first method produce the same problem, but the second work perfectly...Swaim
Need -mode concatenate in the first approach or the OP's attempt.Dellinger
C
6

Montage is simple to use like so:

montage -mode concatenate -tile 2x3 *.png -resize 1024x1024 outfile.png

But if you run it a second time this command will also include outfile.png as part of the new montage, of course.


Montage is smart enough to change formats properly, so the command can be changed to:

montage -mode concatenate -tile 2x3 *.png -resize 1024x1024 outfile.jpg

Which results in a file that is 2048 pixels wide.


If the input files are they are all of uniform size, the simplest way is to use it like so:

montage -mode concatenate -tile 2x3 *.jpg outfile.jpg

To the point of the question:

In gnuplot with the png terminal the default canvas size is 640x480, so a 2x3 montage to a proper JPG results in a file that is 1280 pixels wide.

Displayed on a web page that is too wide to print. Print boundaries are roughly 640 pixels wide (depending on how the margins are set), so it will usually work well with:

montage -mode concatenate -tile 2x3 -resize 320x240 *.png outfile.jpg

Using 320x240 preserves the aspect ratio of the original plot.

Forcing it to be square should be done in the set terminal command inside gnuplot if that is the desired outcome.

Best practice for image post-processing is to avoid distorting the image beyond the intent of the program which generates the originals.

Carbon answered 4/10, 2017 at 4:56 Comment(1)
This was the best solution for me. montage -mode concatenate -tile 3x2 *.jpg -transpose -resize 1920x1080 montage.jpgCalves

© 2022 - 2024 — McMap. All rights reserved.