Repository navigation
Conversation
vjaganat90
approved these changes
Nov 18, 2026
vjaganat90
left a comment
Member
There was a problem hiding this comment.
LGTM. I built the head and its base and read 8 x 8 x 8 NIfTI volumes made from ct3d_int16.nii's header:
- float32 in [0, 1]:
3MIN,3MAX,3MEANare 0, 0, 0 on the base and 0.0011, 0.9998, 0.4966 on the head (numpy: 0.0011, 0.9998, 0.4967). - float64 in [0, 1000]: the head's
3MEANis 493.084 against numpy's 493.135, within one quantization step (0.1); the base gave 492.637. - Whole-valued float32 and int16 volumes give the same 52 intensity and GLSZM values as the base.
- The floored
ut_inten.niion the head against the old file on the base: of 52 values only3COVERED_IMAGE_INTENSITY_RANGEmoves.
…ad of truncating them A FLOAT32/FLOAT64 NIfTI volume was never reported as real-valued, so the scan put it on the offset map, where every voxel was truncated to a whole unit. A volume normalised to [0, 1] read back as all zeros and a [0, 1000] volume reported its mean about half a unit low. min_intensity, max_intensity and dynamic_range did nothing for NIfTI. RawNiftiLoader now reports a float volume as real-valued when a finite voxel's header-rescaled value carries a fraction. The scan then records the quantized map a float TIFF or OME-Zarr takes, and NiftiLoader applies it after the scl_slope/scl_inter rescale. A float volume holding whole values only (a CT saved as float, a label-like phantom) keeps one grey level per unit, so its texture features stay binned in its own units. ut_inten.nii is replaced by the floor of its values: every golden and every MATLAB, MIRP and PyRadiomics oracle on it was computed on the truncated volume, so they all hold unchanged. 3COVERED_IMAGE_INTENSITY_RANGE on it is now exactly 1, no longer above its bound. The two MIRP fixed_bin_number comparison tables, which fed MIRP the fractional values, are refreshed. Tests that fail without the fix: TEST_3D_NIFTI_FLOAT_REPORTS_REAL_VALUED_ VOXELS, _UNIT_RANGE_QUANTIZED, _SLOPE_QUANTIZED, _FPIMAGE_WINDOW (gtest) and test_3d_nifti_float_keeps_fraction_mechanics (float32/float64, [0, 1) and [0, 1000)). TEST_3D_NIFTI_FLOAT_NOT_QUANTIZED pins the paths that must not quantize: preserve_hu, a whole-valued float volume, an integer volume and a float mask. Closes PN-302; settles question 1 of PN-262.
darkclad
force-pushed
the
main-nifti-float
branch
from
November 23, 2026 14:48
fd84f8a to
6b91930
Compare
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.
Problem
Reported on an MRI dataset: a NIfTI intensity volume stored as FLOAT32 or FLOAT64 lost the fractional part of every voxel. Each value was truncated to a whole grey level, and the intensity features were reported from those integers. The docstrings say a floating-point image is rescaled to
dynamic_rangegrey levels usingmin_intensityandmax_intensity, but that never happened for NIfTI. A volume normalised to [0, 1] came out as all zeros, and a [0, 1000] volume reported its mean about 0.5 low.Cause:
RawNiftiLoadernever setfp_pixels_for the float datatypes, which TIFF and OME-Zarr do. The scan therefore recorded the offset map (1 grey level = 1 unit) andNiftiLoadertruncated each voxel.NiftiLoaderalso had no quantized branch at all.Change
RawNiftiLoaderreports a FLOAT32/FLOAT64 volume as real-valued when any finite voxel's header-rescaled value carries a fraction. The scan then records the quantized map, the same map a floating-point TIFF or OME-Zarr takes.NiftiLoadertakes the quantized map fromImageLoader::open, as the TIFF and Zarr loaders do. It appliesscl_slope/scl_interfirst and then clamps to [fpmin, fpmax] spread overdynamic_rangelevels.preserve_hu=True, integer NIfTI (stored map) and mask volumes are unchanged.Fixture and vetting
tests/data/nifti/phantoms/ut_inten.niiheld continuous fractions that no test ever saw, because the loader truncated them. Every golden on it, and every MATLAB, MIRP and PyRadiomics oracle, was computed on the truncated volume; the generators floor it explicitly as fixture setup. The fixture is nowfloor(ut_inten)(still float32), so all of those values hold unchanged under the new rule. Two follow-on changes:3COVERED_IMAGE_INTENSITY_RANGEon it is exactly 1. The old pin, 1.0002, exceeded the feature's bound (not_covered.md§F, flaggedbound-violation). The flag and the §F entry are removed.ngldm3d.mirp_fbn64andgldzm3d.mirp_fbn64comparison tables are refreshed: these "measured only" tables fed MIRP the raw fractional values.gen_ngldm3d_mirp.pyverifies 115/115 andgen_gldzm3d_mirp.py --check96/96.Tests
These fail without the fix:
TEST_3D_NIFTI_FLOAT_REPORTS_REAL_VALUED_VOXELS_MECHANICS: float with fractions reports real-valued; whole-valued float32/float64, int16 and uint8 do not.TEST_3D_NIFTI_FLOAT_UNIT_RANGE_QUANTIZED_MECHANICS: a [0, 1] volume lands on 512 distinct levels over 0..10000, each reading back to within 1e-4.TEST_3D_NIFTI_FLOAT_SLOPE_QUANTIZED_MECHANICS:scl_slope2 is applied before quantizing over the physical window.TEST_3D_NIFTI_FLOAT_FPIMAGE_WINDOW_MECHANICS:--fpimgmin/--fpimgmax/--fpimgdrset the window.test_3d_nifti_float_keeps_fraction_mechanics: the reporter's script as a test, with random float32/float64 volumes over [0, 1) and [0, 1000), checking 3MIN/3MAX/3MEAN against numpy to within one quantization step.Negative test:
TEST_3D_NIFTI_FLOAT_NOT_QUANTIZED_MECHANICScovers what must not quantize:preserve_hu, a whole-valued float volume, an integer volume with a rescale, and a float volume read as a mask.New fixtures:
ct3d_unit.niiandct3d_float_slope.nii, documented intests/data/hounsfield/README.md.Docs:
supported_formats.rst(intensity units) andf_intensity_3d.rstnow describe the rule.Closes PN-302. Settles question 1 of PN-262 (truncating float NIfTI was a defect).