Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mri brightness contrast #746

Merged
merged 2 commits into from
Apr 18, 2024
Merged
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: 17 additions & 2 deletions invesalius/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,23 @@ def OpenOtherFiles(self, group):
hdr = group.header
hdr.set_data_dtype('int16')

wl = float((scalar_range[0] + scalar_range[1]) * 0.5)
ww = float((scalar_range[1] - scalar_range[0]))
# Calculate the 2% and 98% percentile
percentile_2 = np.percentile(self.matrix, 2)
percentile_98 = np.percentile(self.matrix, 98)

# define ww and wl based on 2-98 percentiles saturates
# the high pixel intensities that usually cause the image to
# and makes the brightness and contrast more similar across
# different types of scanners
# this solves the visualization issue only for MRIs imported with NIfTI, but not
# with DICOM
wl = float((percentile_2 + percentile_98) * 0.5)
ww = float((percentile_98 - percentile_2))

# Set wl and ww based on full scalar range. This causes some mri to be visualized
# very dark due to presence of high pixel intensities
# wl = float((scalar_range[0] + scalar_range[1]) * 0.5)
# ww = float((scalar_range[1] - scalar_range[0]))

self.Slice = sl.Slice()
self.Slice.matrix = self.matrix
Expand Down