diff --git a/get_train_annot.py b/get_train_annot.py
index 3f556fa4b351c816f12a53b6707682aa0f143491..731cc9d2da61f7dde115cdc47c3c08a67d7f8c28 100755
--- a/get_train_annot.py
+++ b/get_train_annot.py
@@ -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]],
diff --git a/utils.py b/utils.py
index 412072869876859348a46f8dfaaa1dc3d50481f8..d2b50a912fa6e88cf7d9bdf5a5336afccbd29dcb 100755
--- a/utils.py
+++ b/utils.py
@@ -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