-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcrop.py
More file actions
40 lines (30 loc) · 937 Bytes
/
crop.py
File metadata and controls
40 lines (30 loc) · 937 Bytes
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
from PIL import Image
import glob
import os
import numpy as np
import cv2
#files = glob.glob("./training_dataset/*.png")
def cropp(imageFile, rect):
filepath,filename = os.path.split(imageFile)
filtername,exts = os.path.splitext(filename)
im = Image.open(imageFile).convert("L")
GoldenRto = 1.418
#print im.size
#Address blackboxing at bottom
bottom = rect[3]
top = rect[1]
left = rect[0]
right = rect[2]
if bottom > im.size[1]:
delta = bottom - im.size[1]
top -= delta
bottom = im.size[1]
box = (rect[0], top, rect[2], bottom)
# print box
cropped_im = im.crop(box)
fixedW = 160
fixedH = int(fixedW * GoldenRto)
return cropped_im.resize((fixedW,fixedH),Image.ANTIALIAS)
# print filtername
# plt.imshow(cropped_im)
#(cropped_im.resize((fixedW,fixedH),Image.ANTIALIAS)).save("./OurTeam_edited/" +filtername+"_edited.bmp",'BMP')