Skip to content

Commit

Permalink
Clip mtr map between -1 and 1
Browse files Browse the repository at this point in the history
Gets rid of the silly values caused by noise
  • Loading branch information
alexdaniel654 committed Jan 28, 2025
1 parent 100d65f commit c917c78
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions ukat/mapping/mtr.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def __init__(self, pixel_array, affine, mask=None, moco=False):
# The assumption is that MT_ON comes second in `pixel_array`
self.mt_on = np.squeeze(self.pixel_array[..., 1] * self.mask)
# Magnetisation Transfer Ratio calculation
self.mtr_map = np.squeeze(np.nan_to_num(((self.mt_off - self.mt_on) /
self.mt_off),
posinf=0, neginf=0))
self.mtr_map = np.squeeze(((self.mt_off - self.mt_on) /self.mt_off))
self.mtr_map = np.clip(np.nan_to_num(self.mtr_map, posinf=0,
neginf=0), -1, 1)

def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output',
maps='all'):
Expand Down
8 changes: 4 additions & 4 deletions ukat/mapping/tests/test_mtr.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def test_real_data(self):
images, affine = fetch.mtr_philips()

# Gold standard statistics
gold_standard_mtr_real = [0.1845690591, 0.6237606679, -73.0, 1.0]
gold_standard_mtr_real = [0.214016, 0.289071, -1.0, 1.0]
gold_standard_mtr_real_moco = [0.13357225589671437, 0.17257750673257655,
-1.7306390127939757, 1.0]
-1.0, 1.0]
# The minimum should be 0, but the MT_ON and MT_OFF of real data
# isn't perfectly aligned, which will result in outliers.

Expand All @@ -126,7 +126,7 @@ def test_real_data(self):
mtrmap_stats = arraystats.ArrayStats(mapper.mtr_map).calculate()
npt.assert_allclose([mtrmap_stats["mean"], mtrmap_stats["std"],
mtrmap_stats["min"], mtrmap_stats["max"]],
gold_standard_mtr_real, rtol=0.01, atol=0)
gold_standard_mtr_real, rtol=0.01, atol=1E-3)

# Test with moco
mask = images[..., 0] > 10000
Expand All @@ -136,7 +136,7 @@ def test_real_data(self):
mtrmap_moco_stats["std"],
mtrmap_moco_stats["min"],
mtrmap_moco_stats["max"]],
gold_standard_mtr_real_moco, rtol=0.1, atol=5)
gold_standard_mtr_real_moco, rtol=0.1, atol=1E-3)



Expand Down

0 comments on commit c917c78

Please sign in to comment.