Python implements image stitching function

Use Python to stitch the segmented image of Market1501 and the original image into a left and right image, and adjust the pixel value of the image to 256*128.
All folders:

All original images in the folder:

All split pictures in the folder:

code show as below:

import PIL.Image as Image
import os
 
IMAGES_PATH ='E:/gyx/Learning/Practice/4/data/market1501_seg_1/test/ori_img/' #Original photo gallery address
IMAGES_PATH_1 ='E:/gyx/Learning/Practice/4/data/market1501_seg_1/test/seg_img/' #Split picture set address
IMAGE_SAVE_PATH ='E:/gyx/Learning/Practice/4/data/market1501_seg_1/test/new/' #Save new picture address
IMAGES_FORMAT =['.jpg','.JPG'] #Image Format
list_n =[]
w =256 #The size of each small picture
h =128
 
# Get all the picture names under the picture collection address
image_names =[name for name in os.listdir(IMAGES_PATH)for item in IMAGES_FORMAT if
 os.path.splitext(name)[1]== item]
 
image_names_1 =[name for name in os.listdir(IMAGES_PATH_1)for item in IMAGES_FORMAT if
 os.path.splitext(name)[1]== item]
 
# Define image stitching function
def image_compose(imag,imag_1):
 src = os.path.join(os.path.abspath(IMAGE_SAVE_PATH), img)
 to_image = Image.new('RGB',(2* h,1* w)) #Create a new graph
 # Paste the two pictures to the corresponding positions in order
 rom_image = Image.open(IMAGES_PATH + imag).resize((h,w), Image.ANTIALIAS)
 rom_image_1 = Image.open(IMAGES_PATH_1 + imag_1).resize((h, w), Image.ANTIALIAS)
 to_image.paste(rom_image,(0,0))
 to_image.paste(rom_image_1,(h,0))
 to_image.save(src) #Save the new image with the original name
 
# Call the splicing function if the file name is the same
for img in image_names:for img_1 in image_names_1:if img == img_1:image_compose(img,img_1)

Stitching effect of separate pictures:

The effect of the picture in the new folder new:

This article has been included in the topic "Python Image Processing Operations", welcome to click to learn more exciting content.

The above is the whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Python implements image stitching function
Python implements image stitching
Python implements panoramic image stitching
How Python implements FTP function
python opencv for image stitching
How Python implements the mail function
Python realizes image recognition car function
Python implements ftp file transfer function
How Python implements the timer function
Python implements horizontal stitching of pictures
Python dry goods | remote sensing image stitching
Python enumerate() function
Python function buffer
Python implements image outer boundary tracking operation
Python implements tic-tac-toe game
Python custom function basics
Python implements tic-tac-toe game
Join function in Python
Python built-in function -compile()
Python image recognition OCR
Python implements man-machine gobang
Python function basic learning
Python implements Tetris game
Python data analysis-apply function
python PIL open\display\save image
Python implements minesweeper game
Python realizes stitching pictures
Python3 built-in function table.md
Python implements scanning tools
python+OpenCV realizes image stitching
Python implements threshold regression
Python implements minesweeper games
Python implements electronic dictionary
Python implements guessing game
Python defines a function method
Python implements simple tank battle
Python high-order function usage summary!
Python implements udp chat window
Python implements WeChat airplane game
Python realizes online translation function
Python implements word guessing game
Python on image processing PIL
Python implements parking management system
Python implements digital bomb game
Python implements TCP file transfer
Python numpy implements rolling case
OpenCV Python implements puzzle games
Python implements simple tic-tac-toe game
Python implements password strength verification
Python implements car management system
Python tornado upload file function
Python implements code block folding
Python magic function eval () learning
Python implements multi-dimensional array sorting
Python implements verification code recognition
Python implements gradient descent method
Python implements text version minesweeper
Python high-order function usage summary!
Python implements the brick-and-mortar game
Python reads .nii format image examples
Python telnet login function implementation code