Repository navigation
Conversation
…squares in double COVERED_IMAGE_INTENSITY_RANGE is the ROI's intensity range over the image's, so it lies in [0, 1]. Three things broke that: - The slide range it divided by came from the masked pixels only, so on a segmented image it was the ROIs' own range, and a single ROI divided its range by itself. The 2D and 3D scans now also record the extrema of every pixel (max_allpix_inten joins min_allpix_inten), and the feature divides by those. The masked range still sets the quantized map of a real-valued image, so no other feature moves. - The ROI's range was taken in the loader's grey levels, which truncate, round or quantize fractions, and the image's range in its own units. On the preserve_hu offset map a ROI spanning a fractional image read 1.004975. Both ranges are now grey-level counts on the image's own map: SlideProps::covered_intensity_range puts the image's ends through the forward map without its range clamps, so the ratio is unitless and the inverse map no longer rescales it. A non-finite sample, stored at grey level 0 but left out of the extrema, cannot take it above 1. - With no slide properties, the 2D in-memory site left 0 while the other three wrote 1. Dataset::covered_intensity_range answers 1 on every path, as does an image whose range is zero: a ROI is then taken as its own image, which it covers whole. Nyxus.featurize now measures each array's ranges itself, so in-memory input reports the real value instead of 0. ENERGY, ROOT_MEAN_SQUARED, 3ENERGY and 3ROOT_MEAN_SQUARED squared each grey level as a 32-bit unsigned product, which wraps above 65535. The four sums (2D and 3D, in memory and out of core) square in double. Values that change: COVERED_IMAGE_INTENSITY_RANGE and 3COVERED_IMAGE_INTENSITY_RANGE on segmented images whose background reaches beyond the ROIs' range (ut_inten.nii ROI 57: 1 to 2000/3024, volmin: 1 to 0.8457), on fractional images under preserve_hu, and in memory (0 to the real value); ENERGY and ROOT_MEAN_SQUARED (2D and 3D) wherever a grey level exceeds 65535. Tests that fail without the fix: test_2d/3d_firstorder_analytic.py (covered range 0.5 against 1 on segmented fractional slides with and without preserve_hu, NIfTI and OME-TIFF, in RAM and out of core; 1 against 1.004975 on whole slides and volumes; 0.5 against 0 in memory; ENERGY exact above 65535), TEST_2D/3D_FIRSTORDER_ENERGY_WIDE_ANALYTIC, _COVERED_RANGE_ANALYTIC, _COVERED_RANGE_FLAT_SLIDE_MECHANICS, TEST_2D_FIRSTORDER_COVERED_RANGE_NO_SLIDE_MECHANICS, _NONFINITE_SAMPLE_MECHANICS, _SATURATED_SLIDE_MECHANICS and the 3COVERED regression pin. The 16-bit ENERGY cases are the negative tests. Closes PN-26, PN-61, PN-78, PN-226 and PolusAI#490.
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
COVERED_IMAGE_INTENSITY_RANGE(and3COVERED_IMAGE_INTENSITY_RANGE) is the ROI's intensity range over the image's, so it lies in [0, 1]. It did not:ut_inten.nii+ut_mask57.niithe value was 1 where ROI 57 spans [0, 2000] of the volume's [-1024, 2000].--preserve-hugave 1.004975, 2D and 3D: rounding stores the ends 101 levels apart for a span of 100.5.Nyxus.featurizeno image range was recorded at all, and the value was 0.Separately (PN-226),
ENERGY,ROOT_MEAN_SQUARED,3ENERGYand3ROOT_MEAN_SQUAREDsquared each grey level as a 32-bit unsigned product, which wraps above 65535: on{100000, 70000, 65536, 3, 3000000}ENERGYwas 4058613001 where the sum of squares is 9019194967305.Change
max_allpix_intenjoins the existingmin_allpix_inten, both carried byinherit_intensity_domainand written byrecord_scanned_intensity_range. The masked range (min/max_preroi_inten) is unchanged and still sets the quantized map of a real-valued image, so no other feature moves.SlideProps::covered_intensity_range(lo, hi)divides the ROI's stored grey-level range by the image's ends put through the same forward map, without its range clamps (grey_coordinate()), since the quantized map of a segmented image spans the masked pixels only. Both sides are counts of grey levels on one map, so the ratio has no unit andreport_in_source_domainno longer multiplies it by the map's scale. A stored level is that map clamped and the map is monotone, so a ROI of finite samples never spans more levels than the image. A non-finite sample is stored at level 0 but left out of the extrema, so the ratio is capped at 1;grey_coordinate()saturates at the grey type's maximum, as every narrowing does.Dataset::covered_intensity_range(slide_idx, lo, hi)answers 1 when the ROI names no scanned image, andSlideProps::covered_intensity_rangeanswers 1 when the image's range is zero. All four sites call it. 1 rather than 0: with no image to compare with, the ROI is taken as its own image, which it covers whole; a constant image is covered whole by any ROI of it; and 0 would say the ROI covers none of the image, which is false whenever the ROI has a range. 1 is also what three of the four sites already wrote.processMontagemeasures each array's masked and all-pixel ranges, as the scan measures a file's, soNyxus.featurizereports the real value.test_featurize_montagenow compares this column between the montage and directory runs too.double.Every copy, all changed in this PR:
PixelIntensityFeatures::calculate_grey_levelsandosized_calculate_grey_levels(2D in memory and out of core),D3_VoxelIntensityFeatures::calculate_grey_levelsandosized_calculate_grey_levels(3D),gatherRoisMetrics_2_slideprops_2D,_3Dand_2D_montage, andprocessMontage. Other first-order sums of squares or powers were checked:Moments4and the dispersion, skewness and hyper-moment sums already work indouble.Values that change
A value diff of
*ALL*(2D) and*3D_ALL*(3D) betweenmainand this branch, at the default settings:tests/python/datap0_y1_r1_c0.ome.tif, segmentedhounsfield/ct_float.tif+mask.tifut_inten.nii+ut_mask57.nii3COVERED_IMAGE_INTENSITY_RANGE1 → 0.66138 (2000/3024)volmin_inten.nii+volmin_mask.nii3COVERED_IMAGE_INTENSITY_RANGE1 → 0.84567hounsfield/ct3d_float_slope.nii+mask3d.niiThe 2D corpus images' ROIs reach the images' own extremes, so their values hold. On the test fixtures:
main--preserve-hu(2D, 3D)COVERED_IMAGE_INTENSITY_RANGE,3COVERED_…--preserve-hu(2D, 3D)Nyxus.featurizeCOVERED_IMAGE_INTENSITY_RANGENyxus.featurizeCOVERED_IMAGE_INTENSITY_RANGE3COVERED_IMAGE_INTENSITY_RANGE{100000, 70000, 65536, 3, 3000000}(2D, 3D)ENERGY,3ENERGYENERGY/ROOT_MEAN_SQUARED3ENERGY/3ROOT_MEAN_SQUAREDTests
These fail on
main:tests/python/test_2d_firstorder_analytic.py,test_3d_firstorder_analytic.py: the covered range at most 1 and equal to its closed form on images with off-mask pixels darker and brighter than the ROI, segmented (TIFF in RAM and out of core; NIfTI in RAM with and without the Hounsfield offset; OME-TIFF in RAM and out of core) and whole slide or volume, plusNyxus.featurize;ENERGY/3ENERGYexact on uint32 data above 65535, in memory, in RAM and out of core.TEST_2D_FIRSTORDER_ENERGY_WIDE_ANALYTIC,TEST_3D_FIRSTORDER_ENERGY_WIDE_ANALYTIC: exact sums of squares in RAM and out of core.TEST_2D_FIRSTORDER_COVERED_RANGE_ANALYTIC,TEST_3D_FIRSTORDER_COVERED_RANGE_ANALYTIC: an offset-mapped slide off the map's grid, and a segmented quantized slide whose ends lie past the map's clamps, in RAM and out of core.TEST_2D_FIRSTORDER_COVERED_RANGE_NO_SLIDE_MECHANICS(0 in RAM onmain),TEST_2D/3D_FIRSTORDER_COVERED_RANGE_FLAT_SLIDE_MECHANICS(NaN onmain).TEST_2D_FIRSTORDER_COVERED_RANGE_NONFINITE_SAMPLE_MECHANICS(2 without the cap) and_SATURATED_SLIDE_MECHANICS(0.2147 without the saturation).TEST_3D_FIRSTORDER_COVERED_IMAGE_INTENSITY_RANGE_REGRESSION: the ut phantom pin, now 2000/3024.These pass on
mainand guard what must not change: the 16-bitENERGYcases (TEST_2D/3D_FIRSTORDER_ENERGY_16BIT_ANALYTIC,top=65535in the Python files), the quantized whole-slide cases, andTEST_3D_FIRSTORDER_COVERED_RANGE_NO_SLIDE_MECHANICS(3D already wrote 1).Vetting registry
vetted/analyticrows:COVERED_IMAGE_INTENSITY_RANGE,ENERGY,ROOT_MEAN_SQUARED(2D) and their 3D codes, recipesfirstorder2d/3d.covered_range_analyticand.wide_levels_analytic, fixturesbench_covered_range_slidesandbench_wide_grey_levels.3COVERED_IMAGE_INTENSITY_RANGEregression row pins 2000/3024;not_covered.md§F and both first-order matrices follow.report_output.*,coverage_report.mdandfeaturelist.rstare regenerated.Docs
f_pixel_intensity.rst,f_intensity_3d.rst: the covered range is defined over every pixel or voxel of the image (every channel and timepoint in 3D) and does not change under the intensity map; the in-memory and 32-bit known-defect entries are replaced by the current behaviour; the Validation sections name the closed-form checks.conventions.rst: the constant-ROI entry.feature_descriptions.toml,feature_extras.toml, and the two worked-example scripts, which pin the new values.benchmarks/perf: the numpy exemption for this column is removed from the digest comparison, with its mechanics test.Benchmark instruction counts
No counted kernel runs
PixelIntensityFeatures(theimomentskernel is the intensity moments), so no count should move. If the job reports a change, the updatedinstructions.jsonfollows in its owntest(benchmarks):commit.Phase-0 files touched
None.
Found and filed separately
UNIFORMITY_PIUadds the two extrema in 32 bits, which wraps once their sum reaches 2^32.Closes PN-26, PN-61, PN-78, PN-226. Closes #490.