-
Notifications
You must be signed in to change notification settings - Fork 1
/
crop_images.py
42 lines (32 loc) · 1.09 KB
/
crop_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
31
32
33
34
35
36
37
38
39
40
41
42
import sys
from PIL import Image
from os import listdir
from os.path import isfile, join
src_path = "../katkam-scaled/"
dest_path = "../cropped_images/"
dest_path2 = "../uncropped_images/"
def crop_save_image(filename):
""" crop the images to only capture the sky """
img = Image.open(filename)
area = (0, 0, 256, 129)
cropped_img = img.crop(area)
# to be used as index for next steps
new_filename = filename[24:36]
cropped_img.save(dest_path + new_filename + ".jpg")
def save_original_image(filename):
""" crop the images to only capture the sky """
img = Image.open(filename)
# to be used as index for next steps
new_filename = filename[24:36]
img.save(dest_path2 + new_filename + ".jpg")
def get_all_image_filenames():
image_files = [f for f in listdir(src_path) if isfile(join(src_path, f))]
return image_files
def main():
""" Main function """
image_files = get_all_image_filenames()
for img in image_files:
crop_save_image(src_path + img)
save_original_image(src_path + img)
if __name__ == '__main__':
main()