File tree 1 file changed +35
-0
lines changed
1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ import PIL .Image as Image
3
+ import os
4
+
5
+ IMAGES_PATH = r'D:\\GraduationProjectBackUp\\TestImg\\result\\X4\\patch\\'
6
+ IMAGES_FORMAT = ['.jpg' , '.tif' ]
7
+ IMAGE_SIZE = 512
8
+ IMAGE_ROW = 4
9
+ IMAGE_COLUMN = 4
10
+ IMAGE_SAVE_PATH = r'D:\\GraduationProjectBackUp\\TestImg\\result\\X4\\merged1.tif'
11
+
12
+
13
+ image_names = [name for name in os .listdir (IMAGES_PATH ) for item in IMAGES_FORMAT if
14
+ os .path .splitext (name )[1 ] == item ]
15
+
16
+ print (image_names )
17
+ if len (image_names ) != IMAGE_ROW * IMAGE_COLUMN :
18
+ raise ValueError ("合成图片的参数和要求的数量不能匹配!" )
19
+
20
+
21
+
22
+ def image_compose ():
23
+ to_image = Image .new ('RGB' , (IMAGE_COLUMN * IMAGE_SIZE , IMAGE_ROW * IMAGE_SIZE ))
24
+
25
+ i = 1
26
+ for x in range (1 , IMAGE_COLUMN + 1 ):
27
+ for y in range (1 , IMAGE_ROW + 1 ):
28
+ from_image = Image .open (IMAGES_PATH + str (i ) + '.tif' ).resize (
29
+ (IMAGE_SIZE , IMAGE_SIZE ), Image .ANTIALIAS )
30
+ to_image .paste (from_image , ((x - 1 ) * IMAGE_SIZE , (y - 1 ) * IMAGE_SIZE ))
31
+ i = i + 1
32
+ return to_image .save (IMAGE_SAVE_PATH )
33
+
34
+
35
+ image_compose ()
You can’t perform that action at this time.
0 commit comments