diff --git a/modules/masking.py b/modules/masking.py index 69ed467a6..40d7f811e 100644 --- a/modules/masking.py +++ b/modules/masking.py @@ -89,6 +89,10 @@ def expand_too_small_crop_region(crop_region, processing_width, processing_heigh diff_w_r = diff_w - diff_w_l x1 -= diff_w_l x2 += diff_w_r + if x2 >= image_width: + diff = x2 - image_width + x2 -= diff + x1 -= diff if x1 < 0: x2 -= x1 x1 -= x1 @@ -102,6 +106,10 @@ def expand_too_small_crop_region(crop_region, processing_width, processing_heigh diff_h_d = diff_h - diff_h_u y1 -= diff_h_u y2 += diff_h_d + if y2 >= image_height: + diff = y2 - image_height + y2 -= diff + y1 -= diff if y1 < 0: y2 -= y1 y1 -= y1