'Are there any ways to put a tiff next to another tiff using software or python code?

Now I'm dealing with many satellite images and the format of them are tiff The image are separate and I want to put them next to each other.

eg. I have two images and they are 2*2 pixels, ImageA lower left is (0, 0) and upper right is (2, 2) of imageA on the Cartesian coordinate system; the lower left is (10, 10) and upper right is (12, 12) of imageB.

Then I want to put imageB next to imageA which means the imageB will be relocated to lower left: (3, 3) upper right: (5,5) However, I only have the idea but don't know which functions or skills to realize it. I searched the net and always get a way named mosaic, but that doesn't meet my needs.

Does anybody know how to do that with software (Arcgis or etc.) or python code

Software will be better but python code is ok too.



Solution 1:[1]

You can do it with ImageMagick just in your Terminal on macOS, Linux or Windows like this:

magick background.tif -colorspace rgb red.tif -geometry +10+30  -composite blue.tif -geometry +50+70 -composite result.tif

enter image description here

The -geometry +X+Y specifies the x and y coordinates of where the image will be composited onto the background.


Here are the input images and how I made them:

Background

magick -size 100x100 xc:gray background.tif

enter image description here

Red

magick -size 10x10 xc:red red.tif

enter image description here

Blue

magick -size 20x20 xc:blue blue.tif

enter image description here


You can do the same thing with PIL/Pillow in Python using:

from PIL import Image
# Create background image and open two overlay images
bg   = Image.new("RGB", (100,100))
red  = Image.open('red.tif')
blue = Image.open('blue.tif')

# Paste the overlays at same positions as ImageMagick code
bg.paste(red, (10,30))
bg.paste(blue, (50,70))

# Save the result
bg.save('result.tif')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1