Skip to content

Commit ab4621b

Browse files
authored
Merge pull request #18 from SIPEC-Animal-Data-Analysis/improvements_after_review
bugfixing scripts from last PR
2 parents 5c3718a + b5b620a commit ab4621b

2 files changed

Lines changed: 22 additions & 24 deletions

File tree

SwissKnife/segmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ def train_on_data_once(
554554
species=None,
555555
fold=0,
556556
fraction=None,
557-
perform_evaluation=False,
557+
perform_evaluation=True,
558558
debug=0,
559559
):
560560

SwissKnife/utils.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -462,33 +462,31 @@ def extractCOM_only(image):
462462
return center_of_mass, weighted_center_of_mass
463463

464464

465-
# TODO: remove hack
466465
def mask_to_original_image(orig_shape, mask, center_of_mass, mask_size):
467466

468467
img = np.zeros((orig_shape, orig_shape))
469468

470-
if (
471-
np.min([img.shape[0], int(center_of_mass[0] + mask_size)])
472-
- np.max([0, int(center_of_mass[0] - mask_size)])
473-
< mask.shape[0]
474-
):
475-
img[
476-
np.max([0, int(center_of_mass[0] - mask_size)]) : np.min(
477-
[img.shape[0], int(center_of_mass[0] + mask_size)]
478-
),
479-
np.max([0, int(center_of_mass[1] - mask_size)]) : np.min(
480-
[img.shape[0], int(center_of_mass[1] + mask_size)]
481-
),
482-
] = mask[mask_size:, mask_size:]
483-
else:
484-
img[
485-
np.max([0, int(center_of_mass[0] - mask_size)]) : np.min(
486-
[img.shape[0], int(center_of_mass[0] + mask_size)]
487-
),
488-
np.max([0, int(center_of_mass[1] - mask_size)]) : np.min(
489-
[img.shape[0], int(center_of_mass[1] + mask_size)]
490-
),
491-
] = mask
469+
x_min = np.max([0, int(center_of_mass[0] - mask_size)])
470+
x_max = np.min([img.shape[0], int(center_of_mass[0] + mask_size)])
471+
y_min = np.max([0, int(center_of_mass[1] - mask_size)])
472+
y_max = np.min([img.shape[0], int(center_of_mass[1] + mask_size)])
473+
474+
x_dim = x_max - x_min
475+
y_dim = y_max - y_min
476+
477+
if int(center_of_mass[0] + mask_size) > img.shape[0]:
478+
mask = mask[-x_dim:,:]
479+
if int(center_of_mass[1] + mask_size) > img.shape[1]:
480+
mask = mask[:, -y_dim:]
481+
if 0 > int(center_of_mass[0] - mask_size):
482+
mask = mask[:x_dim,:]
483+
if 0 > int(center_of_mass[1] - mask_size):
484+
mask = mask[:, :y_dim]
485+
486+
img[
487+
x_min : x_max,
488+
y_min : y_max,
489+
] = mask
492490

493491
return img
494492

0 commit comments

Comments
 (0)