13
13
14
14
# number of colors per image
15
15
COLOR_DEPTH = conf .COLOR_DEPTH
16
+ # image scale
17
+ IMAGE_SCALE = conf .IMAGE_SCALE
16
18
# tiles scales
17
19
RESIZING_SCALES = conf .RESIZING_SCALES
18
20
# number of pixels shifted to create each box (x,y)
@@ -29,11 +31,14 @@ def color_quantization(img, n_colors):
29
31
30
32
31
33
# returns an image given its path
32
- def read_image (path ):
34
+ def read_image (path , mainImage = False ):
33
35
img = cv2 .imread (path , cv2 .IMREAD_UNCHANGED )
34
36
if img .shape [2 ] == 3 :
35
37
img = cv2 .cvtColor (img , cv2 .COLOR_BGR2BGRA )
36
38
img = color_quantization (img .astype ('float' ), COLOR_DEPTH )
39
+ # scale the image according to IMAGE_SCALE, if this is the main image
40
+ if mainImage :
41
+ img = cv2 .resize (img , (0 , 0 ), fx = IMAGE_SCALE , fy = IMAGE_SCALE )
37
42
return img .astype ('uint8' )
38
43
39
44
@@ -148,7 +153,7 @@ def most_similar_tile(box_mode_freq, tiles):
148
153
# builds the boxes and finds the best tile for each one
149
154
def get_processed_image_boxes (image_path , tiles ):
150
155
print ('Getting and processing boxes' )
151
- img = read_image (image_path )
156
+ img = read_image (image_path , mainImage = True )
152
157
pool = Pool (POOL_SIZE )
153
158
all_boxes = []
154
159
0 commit comments