@@ -71,51 +71,75 @@ def extract_features(filepath: Union[Path, str], data: dict, margin_threshold: i
7171 area = width * height
7272 relative_area = area / im_area
7373
74- # if bbox corners in all four image quarters
75- in_center = 1 if all ([
76- xmin <= img_center_x <= xmax ,
77- ymin <= img_center_y <= ymax
78- ]) else 0
79- # if object on im_center_y coord but has right offset
80- in_right_side = 1 if all ([
81- ymin < img_center_y < ymax ,
82- xmin > img_center_x
83- ]) else 0
84- # if object on im_center_y coord but has left offset
85- in_left_side = 1 if all ([
86- ymin < img_center_y < ymax ,
87- xmax < img_center_x
88- ]) else 0
89- # if object on im_center_x coord but has top offset
90- in_top_side = 1 if all ([
91- xmin < img_center_x < xmax ,
92- ymax < img_center_y
93- ]) else 0
94- # if object on im_center_x coord but has bottom offset
95- in_bottom_side = 1 if all ([
96- xmin < img_center_x < xmax ,
97- ymin > img_center_y
98- ]) else 0
99- # object absolutely in top left quarter
100- in_left_top = 1 if all ([
101- xmax < img_center_x ,
102- ymax < img_center_y
103- ]) else 0
104- # object absolutely in top right quarter
105- in_right_top = 1 if all ([
106- xmin > img_center_x ,
107- ymax > img_center_y
108- ]) else 0
109- # object absolutely in left bottom quarter
110- in_left_bottom = 1 if all ([
111- xmax < img_center_x ,
112- ymin > img_center_y
113- ]) else 0
114- # object absolutely in right bottom quarter
115- in_right_bottom = 1 if all ([
116- xmin > img_center_x ,
117- ymin > img_center_y
118- ]) else 0
74+ # # if bbox corners in all four image quarters
75+ # in_center = 1 if all([
76+ # xmin <= img_center_x <= xmax,
77+ # ymin <= img_center_y <= ymax
78+ # ]) else 0
79+ # # if object on im_center_y coord but has right offset
80+ # in_right_side = 1 if all([
81+ # ymin < img_center_y < ymax,
82+ # xmin > img_center_x
83+ # ]) else 0
84+ # # if object on im_center_y coord but has left offset
85+ # in_left_side = 1 if all([
86+ # ymin < img_center_y < ymax,
87+ # xmax < img_center_x
88+ # ]) else 0
89+ # # if object on im_center_x coord but has top offset
90+ # in_top_side = 1 if all([
91+ # xmin < img_center_x < xmax,
92+ # ymax < img_center_y
93+ # ]) else 0
94+ # # if object on im_center_x coord but has bottom offset
95+ # in_bottom_side = 1 if all([
96+ # xmin < img_center_x < xmax,
97+ # ymin > img_center_y
98+ # ]) else 0
99+ # # object absolutely in top left quarter
100+ # in_left_top = 1 if all([
101+ # xmax < img_center_x,
102+ # ymax < img_center_y
103+ # ]) else 0
104+ # # object absolutely in top right quarter
105+ # in_right_top = 1 if all([
106+ # xmin > img_center_x,
107+ # ymax > img_center_y
108+ # ]) else 0
109+ # # object absolutely in left bottom quarter
110+ # in_left_bottom = 1 if all([
111+ # xmax < img_center_x,
112+ # ymin > img_center_y
113+ # ]) else 0
114+ # # object absolutely in right bottom quarter
115+ # in_right_bottom = 1 if all([
116+ # xmin > img_center_x,
117+ # ymin > img_center_y
118+ # ]) else 0
119+
120+ object_center_x = (xmin + xmax ) / 2
121+ object_center_y = (ymin + ymax ) / 2
122+
123+ bin_w = im_width / 3
124+ bin_h = im_height / 3
125+
126+ col_idx = int (object_center_x // bin_w )
127+ row_idx = int (object_center_y // bin_h )
128+
129+ col_idx = min (col_idx , 2 )
130+ row_idx = min (row_idx , 2 )
131+
132+ in_left_top = 1 if (row_idx == 0 and col_idx == 0 ) else 0
133+ in_top_side = 1 if (row_idx == 0 and col_idx == 1 ) else 0
134+ in_right_top = 1 if (row_idx == 0 and col_idx == 2 ) else 0
135+
136+ in_left_side = 1 if (row_idx == 1 and col_idx == 0 ) else 0
137+ in_center = 1 if (row_idx == 1 and col_idx == 1 ) else 0
138+ in_right_side = 1 if (row_idx == 1 and col_idx == 2 ) else 0
139+
140+ in_left_bottom = 1 if (row_idx == 2 and col_idx == 0 ) else 0
141+ in_bottom_side = 1 if (row_idx == 2 and col_idx == 1 ) else 0
142+ in_right_bottom = 1 if (row_idx == 2 and col_idx == 2 ) else 0
119143
120144 truncated_left = 1 if xmin < margin_threshold else 0
121145 truncated_right = 1 if xmax > (im_width - margin_threshold ) else 0
0 commit comments