Skip to content

Commit

Permalink
Change phase range in field mapping calculations (#499)
Browse files Browse the repository at this point in the history
* Change from 0 to 2pi to -pi to pi

* small fixes

---------

Co-authored-by: Alexandre D'Astous <po09i@hotmail.com>
  • Loading branch information
4rnaudB and po09i committed Jan 4, 2024
1 parent 67c4cf1 commit d86c825
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions shimmingtoolbox/load_nifti.py
Expand Up @@ -181,13 +181,11 @@ def read_nii(fname_nifti, auto_scale=True):
extent = (np.amax(image) - np.amin(image))

if np.amin(image) < 0 and (0.95 * 2 * PHASE_SCALING_SIEMENS < extent < 2 * PHASE_SCALING_SIEMENS * 1.05):
# Siemens' scaling: [-4096, 4095] --> [-pi, pi)
image = image * math.pi / PHASE_SCALING_SIEMENS
# Siemens' scaling: [-4096, 4095] --> [-pi, pi[
image = (image * math.pi / PHASE_SCALING_SIEMENS)
elif np.amin(image) >= 0 and (0.95 * PHASE_SCALING_SIEMENS < extent < PHASE_SCALING_SIEMENS * 1.05):
# Siemens' scaling [0, 4095] --> [0, 2pi)
# We want: [-pi, pi]
image = image * 2 * math.pi / PHASE_SCALING_SIEMENS
image = np.angle(np.exp(1j * image))
# Siemens' scaling [0, 4095] --> [-pi, pi[
image = (image * 2 * math.pi / PHASE_SCALING_SIEMENS) - math.pi
else:
logger.info("Could not scale phase data")

Expand Down

0 comments on commit d86c825

Please sign in to comment.