Search code examples
imagemagickimagemagick-convert

How to merge list of images using ImageMagic convert tool


I'm completely new to ImageMagic. Now I try to follow this tutorial. I was able to create three separate images using gdalwarp tool. I did it like so:

$ gdalwarp -t_srs EPSG:3857 LC80120542013154LGN00_B4.TIF 4-projected.tif
$ gdalwarp -t_srs EPSG:3857 LC80120542013154LGN00_B3.TIF 3-projected.tif
$ gdalwarp -t_srs EPSG:3857 LC80120542013154LGN00_B2.TIF 2-projected.tif

So, at this moment I have three separate images - 4-projected.tif, 3-projected.tif and 2-projected.tif and want to combine them, but I do not know how should I interpret this command from the tutorial:

$ convert -combine {4,3,2}-projected.tif RGB.tif

I'm not sure whether I should run them one by one, or should I use some one-line command. I tried it just as it is, but got the error message:

Unable to open {4,3,2}-projected.tif image

I also tried to run this command one by one, like:

$ convert -combine 4-projected.tif RGB.tif
$ convert -combine 3-projected.tif RGB.tif
$ convert -combine 2-projected.tif RGB.tif

But it seems like each following command just rewrites the previous one and instead of combination I just have RGB.tif which is totally identical to 2-projected.tif. So, I need some help.


Solution

  • Assuming each of those is a single band (greyscale) image and that you want to use 4.tif as your red channel, 3.tif as your green and 2.tif as your blue channel:

    convert 4.tif 3.tif 2.tif -combine result.tif
    

    Also, I would generally recommend lossless compression, else TIF files tend to end up excessively large for no benefit:

    convert 4.tif 3.tif 2.tif -combine -compress lzw result.tif