Home > other >  Python code how to realize the folder pictures in order every two transverse splices together? Seek
Python code how to realize the folder pictures in order every two transverse splices together? Seek

Time:09-26

Python code to read how to implement in the folder pictures, and according to the order of the transverse splices together every 2 picture?

Such as folder pictures in this way, each picture size is, wide, 2048, 1024, how to implement in order to cross stitching every two pictures? Seek guidance

CodePudding user response:

Refer to this thread, the original is all stitching, into two splicing,

https://blog.csdn.net/ahaotata/article/details/84027000

CodePudding user response:

reference 1/f, old coconut response:
refer to this thread, the original is all stitching, into two splicing,

https://blog.csdn.net/ahaotata/article/details/84027000

Thank you, I change the path, image size, number, but there is an error operation, I won't change, can you tell me the need to change?

CodePudding user response:

The Windows directory name change, do not have space to try, or change a space to underline,

CodePudding user response:

reference 1/f, old coconut response:
refer to this thread, the original is all stitching, into two splicing,

https://blog.csdn.net/ahaotata/article/details/84027000

Thank you, I change the path and the image size and number of sheets, but running there is an error, I will not change, the error is: OSE rror: [123] WinError filename, directory name, or volume slogan method is not correct, : "G: \ \ data \ two image \ \
My address is in the code: G: \ data \ two image \ \
Could you tell me how to change is needed here?

CodePudding user response:

So try


You two new directory
G: \ data \ test1
G: \ data \ test2

Copy the image to g: \ data \ test1

Code change directory,


IMAGES_PATH='g: \ \ data \ \ test1 \ \' # photo collections address

IMAGE_SAVE_PATH='g: \ \ data \ \ test1 \ \ final JPG' # image converted address


CodePudding user response:

IMAGE_SAVE_PATH='g: \ \ data \ \ test2 \ \ final JPG' # image converted address

CodePudding user response:

Verify the success, and then change back to your target path

CodePudding user response:

Ok ok, I try, thank you

CodePudding user response:

Is, the original image size wide high is 256 in the program, I image size is 2048 wide, high is 1024, here is not the same?

CodePudding user response:

 import PIL. Image as Image # PIP install -i pillow https://pypi.tuna.tsinghua.edu.cn/simple 
The import OS

Download IMAGES_PATH='E: \ \ \ \ idm \ \ img \ \' # photo collections address
IMAGES_FORMAT=[' JPG ', 'JPG'] # image format
IMAGE_SIZE=256 # each picture of small size
IMAGE_ROW=4 # image interval, which is merged into one picture, there are a few lines
IMAGE_COLUMN=4 # image interval, which is merged into one picture, there are a few columns
Download IMAGE_SAVE_PATH='E: \ \ \ \ idm \ \ img \ \ final' # image converted address
Start=1
# get all the pictures of photo collections address under the name
Image_names=[name for the name in OS. Listdir (IMAGES_PATH) for the item in IMAGES_FORMAT if
OS. Path. Splitext (name) [1]==item]
Print (image_names)
# simple for parameter setting and the size of the actual images of the number of
# if len (image_names)!=IMAGE_ROW * IMAGE_COLUMN:
# -raise ValueError (" the number of parameters and requirement of synthetic images can't match!" )

# define image matching function
Def image_compose (start) :
While the int (start) * * IMAGE_ROW IMAGE_COLUMN & lt;=len (image_names) :
To_image=Image. The new (RGB, (IMAGE_COLUMN * IMAGE_SIZE, IMAGE_ROW * IMAGE_SIZE)) # to create a new
# to iterate over, stick each image in order to the corresponding position
IMAGE_ROW for y in range (1, + 1) :
For x in range (1, IMAGE_COLUMN + 1) :
Try:
From_image=Image. Open (IMAGES_PATH + image_names IMAGE_COLUMN [(start - 1) * * IMAGE_ROW + IMAGE_COLUMN * (y - 1) + x - 1]). The resize ((IMAGE_SIZE, IMAGE_SIZE), Image. ANTIALIAS)
To_image. Paste (from_image, (* IMAGE_SIZE (x - 1), (1) y * IMAGE_SIZE))

Except the Exception as e:
Pass
Raise e
To_image. Save (IMAGE_SAVE_PATH + STR (start) + 'JPG')
Start +=1
Return # save new
Image_compose (start) # function call

CodePudding user response:

 import PIL. Image as Image # PIP install -i pillow https://pypi.tuna.tsinghua.edu.cn/simple 
The import OS

Download IMAGES_PATH='E: \ \ \ \ idm \ \ img \ \' # photo collections address
IMAGES_FORMAT=[' JPG ', 'JPG'] # image format
IMAGE_VSIZE=118 # each picture of small size
IMAGE_HSIZE=256 # each picture of small size
IMAGE_ROW=4 # image interval, which is merged into one picture, there are a few lines
IMAGE_COLUMN=4 # image interval, which is merged into one picture, there are a few columns
Download IMAGE_SAVE_PATH='E: \ \ \ \ idm \ \ img \ \ final' # image converted address
Start=1
# get all the pictures of photo collections address under the name
Image_names=[name for the name in OS. Listdir (IMAGES_PATH) for the item in IMAGES_FORMAT if
OS. Path. Splitext (name) [1]==item]
Print (image_names)
# simple for parameter setting and the size of the actual images of the number of
# if len (image_names)!=IMAGE_ROW * IMAGE_COLUMN:
# -raise ValueError (" the number of parameters and requirement of synthetic images can't match!" )

# define image matching function
Def image_compose (start) :
While the int (start) * * IMAGE_ROW IMAGE_COLUMN & lt;=len (image_names) :
To_image=Image. The new (RGB, (IMAGE_COLUMN * IMAGE_HSIZE, IMAGE_ROW * IMAGE_VSIZE)) # to create a new
# to iterate over, stick each image in order to the corresponding position
IMAGE_ROW for y in range (1, + 1) :
For x in range (1, IMAGE_COLUMN + 1) :
Try:
From_image=Image. Open (IMAGES_PATH + image_names IMAGE_COLUMN [(start - 1) * * IMAGE_ROW + IMAGE_COLUMN * (y - 1) + x - 1]). The resize ((IMAGE_HSIZE, IMAGE_VSIZE), Image. ANTIALIAS)
To_image. Paste (from_image, (* IMAGE_HSIZE (x - 1), (1) y * IMAGE_VSIZE))

Except the Exception as e:
Pass
Raise e
To_image. Save (IMAGE_SAVE_PATH + STR (start) + 'JPG')
Start +=1
nullnullnull
  • Related