Skip to content
Snippets Groups Projects
Commit 854c810c authored by Stephane Chavin's avatar Stephane Chavin
Browse files

add boxes correction if overflow

parent 3a2e7371
No related branches found
No related tags found
No related merge requests found
......@@ -81,10 +81,11 @@ def main(entry, arguments, species_list):
y_pxl = 1 - (row.midl_y / (arguments.rf / 2))
height_pxl = (row.max_freq - row.min_freq) / \
(arguments.rf / 2) # take height value in pixels
if height_pxl > 1:
height_pxl = 1
elif height_pxl > y_pxl * 2:
y_pxl = y_pxl + 0.5 * (height_pxl - y_pxl * 2)
# Correction if the boxes are corrupted (> 1 or < 0)
x_pxl, width_pxl = correct_box(x_pxl, width_pxl)
y_pxl, height_pxl = correct_box(y_pxl, height_pxl)
# Store the annotation in a DataFrame
new_table = pd.DataFrame([[str(species_list[species_list.species == specie].index[0]),
x_pxl, y_pxl, width_pxl, height_pxl]],
......
......@@ -569,3 +569,27 @@ def get_set_info(entry):
state = 'balanced'
proposition = '\u2705 this is good'
return state, proposition
def correct_box(x,w):
"""
Apply correction if there is an overflow on the annotation box
:param x (float): Ratio of the center of the box
:return w (float): Ratio of the size of the box
:return x,w (float): Corrected values
"""
# Get the beggining and the end of the box
x0, x1 = (x - (w / 2)), (x + (w / 2))
# Check the overflow
if x1 > 1 and x0 > 0:
w = 1 - x0
x = x0 + w/2
elif x0 < 0 and x1 < 1 :
w = x1
x = w/2
elif x0 < 0 and x1 > 1:
w = 1
x = 0.5
return x,w
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment