Mosaic Images with Python

Source: Internet
Author: User

Problem Description: Stitching 16 images into a 4x4 image without changing the pixel value of each individual picture.

The code is as follows:

1 ImportOS2  fromPILImportImage3Path ='/share1/home/cong/datasets/resized_polyvore/pair1/pair1'4Imglist =os.listdir (path)5 Imglist.sort ()6Imglist = imglist[:16]7Images = []8  forIteminchimglist:9Images.append (Image.open (path +'/'+item))Ten  OneH, W = 128, 128 Atarget = Image.new ('RGBA', (W * 4, H * 4)) -  forIDX, imginchEnumerate (IMAGES): -i = idx% 4 thej = IDX//4 -Target.paste (IMG, (i * W, J * H, I * W + W, J * H +h)) -  -Target.save ('.'+'/'+'Real.png')

The effect is as follows:

Mosaic Images with Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.