Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/icon_registration/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,16 +592,17 @@ def __call__(self, image_A, image_B, mask_B=None):
I = image_A
J = image_B
assert I.shape == J.shape, "The shape of image I and J should be the same."

if mask_B is not None:
assert mask_B.shape == J.shape, "The shape of mask and J should be the same."

lncc = self.calculate_lncc(I, J)

if mask_B is not None:
mask = mask_B.clone()
mask[mask != 0] = 1
lncc = lncc * mask
return 1 - torch.sum(lncc) / torch.clamp(torch.sum(mask), min=1)

return 1 - torch.mean(lncc)

Expand All @@ -610,17 +611,18 @@ def __call__(self, image_A, image_B, mask_B=None):
I = image_A
J = image_B
assert I.shape == J.shape, "The shape of image I and J should be the same."

if mask_B is not None:
assert mask_B.shape == J.shape, "The shape of mask and J should be the same."

lncc = self.calculate_lncc(I, J)

if mask_B is not None:
mask = mask_B.clone()
mask[mask != 0] = 1
lncc = lncc * mask

return 1 - torch.sum(lncc**2) / torch.clamp(torch.sum(mask), min=1)

return 1 - torch.mean(lncc**2)

class LNCCOnlyInterpolated(SimilarityBase):
Expand Down Expand Up @@ -824,7 +826,8 @@ def __call__(self, image_A, image_B, mask_B=None):

mask = mask.expand(-1, difference.shape[1], -1, -1, -1)
difference = difference * mask

return torch.sum(difference ** 2) / torch.clamp(torch.sum(mask), min=1)

return torch.mean(difference ** 2)

def flips(phi, in_percentage=False):
Expand Down
Loading