-
Notifications
You must be signed in to change notification settings - Fork 7
/
split_images.py
31 lines (22 loc) · 1.06 KB
/
split_images.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import glob
import image_slicer
from PIL import Image
dataset_path = 'dataset/600_chloride/*.tif'
save_path_cropped_images = 'dataset/512X512_CROPPED_600_CHLORIDE/'
images = glob.glob(dataset_path)
for index,image in enumerate(images):
img = Image.open(image)
area = (0, 0, 512, 512)
cropped_img = img.crop(area).save(save_path_cropped_images+str(index)+'.tif',format=None)
cropped_images_path = 'dataset/512X512_CROPPED_600_CHLORIDE/*.tif'
cropped_images = glob.glob(cropped_images_path)
tiles_save_path = 'dataset/32x32_600_CHLORIDE/'
tiles_save_path_test = 'dataset/32x32_600_CHLORIDE_TEST/'
# for index,image in enumerate(cropped_images):
# tiles = image_slicer.slice(image, 16, save=False)
# image_slicer.save_tiles(tiles, directory=tiles_save_path,\
# prefix=str(index), format='png')
for index,image in enumerate(cropped_images):
tiles = image_slicer.slice(image, 16, save=False)
image_slicer.save_tiles(tiles, directory=tiles_save_path_test,\
prefix=str(index), format='png')