Refactor NIfTI preview picture to support RGB images - #1496
Open
MaximeBICMTL wants to merge 1 commit into
Open
Conversation
MaximeBICMTL
marked this pull request as ready for review
August 24, 2026 11:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disclaimer: The nibabel/numpy code in this PR has been written with AI assistance.
Description
While trying to implement MRI derivatives import in the LORIS BIDS importer (see #1392 for the data that we use in our integration tests, note that derivatives are currently not imported 🙀 !). I stumbled upon an error while creating the NIfTI preview picture for a certain derivative, which happened to contain an RGB NIfTI.
This PR refactors the NIfTI preview picture creation for RGB support, better overall images, and better memory efficiency.
Note that the imaging browser does not seem to be able to display the RGB picture (at least with its current integration into LORIS), but at least we still have a preview now!
CLI output
Main
Notice (very obviously) that the NIfTI preview picture generation fails for the last image 🙀 !
This PR
Notice that in addition to the error being gone, the time taken by the NIfTI preview picture generation is also much faster! This is not just because the exception is gone but also because the new script is generally faster and more memory-efficient for all pictures.
Visual inspection
Main
Notice that one picture is missing! (makes sense since there was an error during picture creation).
This PR
Notice that in addition to a new fancy✨ RGB preview picture, the contrast is generally much clearer, the ratio seems more in line with the acquisitions, and the previously kinda unreadable scale is gone.