.merge()
Published Mar 26, 2025
Contribute to Docs
The .merge()
function in Pillow combines multiple single-band images into a new multi-band image. This is particularly useful when working with multispectral or multichannel images, such as RGB or CMYK images, where individual channels can be processed separately before merging them into a final image.
Syntax
Image.merge(mode, bands)
mode
: The mode of the new multi-band image (e.g.,"RGB"
,"CMYK"
, etc.).bands
: A tuple containing the individual image bands to be merged. Each band should be a single-channel (grayscale) image.
Example
The image to be used for this example is:
The code below splits the above image into its individual bands and then merges them in a different order:
from PIL import Image# Open the imageimage1= Image.open('media/Boston.jpg')im = image1.resize((400,400))# Split the image into its RGB channelsr,g,b = im.split()# Merge the bands in a different ordernew_image= Image.merge('RGB', (b,r,g))new_image.show()
The output will be:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Pillow on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours