Repository navigation
Conversation
added 3 commits
December 2, 2026 11:35
A direction along which a ROI is one pixel or voxel thin has no pairs, and its matrix is empty. Such a direction reported the --noval substitute, and the _AVE codes averaged that substitute with the directions that have pairs. On a 3D ROI one plane deep, 9 of the 13 directions are empty, so every 3GLCM_*_AVE value was 4/13 of the IBSI value: 3GLCM_CONTRAST_AVE 1.775 where MIRP and PyRadiomics give 5.769. A 2D ROI one pixel tall has pairs at 0 degrees only, and every GLCM_*_AVE value was a quarter of it. The _AVE codes now average the directions that have pairs, as IBSI, MIRP and PyRadiomics do, and report the substitute when none has. The angled columns are unchanged: an empty direction still reports the substitute. The 2D path, the 3D in-memory path and the 3D out-of-core path share the rule through TextureFeature::calc_ave_populated(). A 3D ROI of one grey level after binning now reports the substitute in every 3D GLCM column, as a 2D ROI does, instead of limiting values (3GLCM_ASM 1, 3GLCM_JAVE the level) next to substitute correlations. Tests: MIRP 3d_average on a one-plane ROI and a three-plane control, MIRP 2d_average on a one-row ROI, the constant-ROI and no-pairs substitutes in 2D and 3D, and the 3D out-of-core path against the in-memory path on the gap-levels CT crop and the one-plane ROI. Refs: PN-229, PN-304
…he mixed case calc_ave_populated() took the plain mean of every value whenever its flags held no false, which included a flag list shorter than the values or empty. A value recorded without a flag now counts as a direction with no pairs and stays out of the average. The no-pairs mechanics tests have every direction at the substitute, so the old mean of substitutes passed them too. New mechanics tests cover the mixed case: a 2D row and a 3D row with pairs along one direction only, where every _AVE code must equal that direction's value on both 3D paths, and a direct test of the unflagged-direction rule. All three fail without the change they guard. The glcm and glcm_3d family notes in feature_descriptions.toml now say the mean is over the directions that have pairs; featurelist.rst is regenerated from them. A test comment drops a board reference.
…filtered averaging The _AVE codes now keep one has-pairs flag per direction and average only the flagged values, which adds about 2,660 instructions to each 2D GLCM kernel (1.000x); the feature values are unchanged. The two kernels/glcm entries take the counts of the instruction-count job on dac1779; no other kernel's count changed.
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
A user comparing Nyxus 3D features with PyRadiomics on CT lung lobes found that one lobe, cut to a single slice by the scan's field of view, gave 3D GLCM averages far below PyRadiomics.
A direction along which a ROI is one pixel or voxel thin has no pairs, so its co-occurrence matrix is empty. Such a direction reported the
--novalsubstitute (0 by default), and the_AVEcodes averaged that substitute together with the directions that have pairs:3GLCM_*_AVEvalue was 4/13 of the IBSI value. On the test fixture,3GLCM_CONTRAST_AVEwas 1.775, where MIRP3d_averageand PyRadiomics give 5.769.GLCM_*_AVEvalue was a quarter of the 0-degree value.GLCM_CONTRAST_AVEwas 1.833, where MIRP2d_averagegives 7.333.A 3D ROI of one grey level was also computed:
3GLCM_ASM1,3GLCM_JAVEthe level, and the substitute for correlation. A 2D ROI of one grey level reports the substitute in every column.Change
_AVEcodes, 2D and 3D: the average is taken over the directions that have pairs, as IBSI, MIRP and PyRadiomics take it. When no direction has pairs, the average is the substitute. The per-direction columns are unchanged: an empty direction still reports the substitute. When every direction has pairs, the average is the samestd::reduceas before, so values on such ROIs are bit-identical.finalize_angle()with the in-memory path, so it follows both rules, and its "nothing to featurize" branch now covers the one-level ROI too.The rule lives in one place,
TextureFeature::calc_ave_populated().GLCMFeatureandD3_GLCM_featurerecord, per direction, whether the matrix has pairs.Values that change
A value diff of
*ALL*(2D) and*3D_ALL*(3D) betweenmainand this branch, at the default settings:tests/python/data,p0_y1_r1_c0.ome.tifut_inten.nii+ut_mask57.nii,volmin_inten.nii+volmin_mask.niiThe change affects only ROIs that are one pixel or voxel thin along some direction, and 3D ROIs of one grey level:
3GLCM_*_AVEGLCM_*_AVE3GLCM_*and3GLCM_*_AVE3GLCM_ASM1,3GLCM_CONTRAST0,3GLCM_JAVEthe level)--novalsubstituteThe 3D worked example on the docs page changes
3GLCM_CONTRAST_AVEon its one-plane ROI from 0.673 to 2.1875.Tests
These fail on
main:TEST_3D_GLCM_ONE_PLANE_AVE_MIRP: every3GLCM_*_AVEcode onbench_plane9x8_thin, one plane deep, against MIRP 2.6.03d_average(IBSI mode, no discretisation). PyRadiomics 3.0.1 gives the same values on this fixture.TEST_2D_GLCM_ONE_ROW_AVE_MIRP: everyGLCM_*_AVEfeature onbench_row10_thin, one pixel tall, against MIRP2d_average.TEST_3D_GLCM_CONSTANT_ROI_REPORTS_NOVAL_MECHANICS: a constant 3D ROI reports the substitute in every column, under IBSI, MATLAB-style and PyRadiomics-style binning, in memory and out of core.These pass on
mainand guard what must not change:TEST_3D_GLCM_THREE_PLANE_AVE_MIRP: the control, three planes with all 13 directions populated, against MIRP.TEST_2D_GLCM_NO_PAIRS_REPORTS_NOVAL_MECHANICSandTEST_3D_GLCM_NO_PAIRS_REPORTS_NOVAL_MECHANICS: a two-level ROI with no pair in any direction reports the substitute in every column, the_AVEcodes included.TEST_3D_GLCM_OOC_GAP_LEVELS_INVARIANTandTEST_3D_GLCM_OOC_ONE_PLANE_INVARIANT: the 3D out-of-core path equals the in-memory path, every value of every direction, on the gap-levels CT crop at PyRadiomics binCount 20 and on the one-plane ROI.The three-plane control has a level-shifted middle plane. On three identical planes, the z direction pairs only equal levels, and MIRP then leaves that direction out of inverse variance, where the definition, PyRadiomics and Nyxus give it 0. The shift keeps the control off that difference between the tools.
Goldens come from
tests/vetting/oracles/gen_glcm3d_mirp.py(new) andgen_glcm_mirp.py(extended). Both read the fixtures from the test headers and re-verify every pin.Vetting registry
vetted/mirprows for the3GLCM_*_AVEcodes (recipeglcm3d.mirp_ibsi_3d_average).vetted/mirprows for the 2DGLCM_*_AVEfeatures (recipeglcm.ibsi_identity_one_row).invariantrows for the 3D out-of-core comparison (recipeglcm3d.ooc_parity).benchmarks.mdand the 3D IBSI cell is inmatrix/glcm.md.scan_glcm3d_coverage.pyreads the new MIRP and invariant files.scan_glcm_coverage.pycredits the one-row table.report_output.*andfeaturelist.rstare regenerated.Docs
f_glcm_3d.rst: the_AVEdefinition is now the mean over the directions that have pairs, and the constant-ROI entry follows 2D. The validation section names the MIRP checks.3GLCM_HOM2has no_AVEcolumn; it has one.f_glcm.rst: the_AVEdefinition and validation section follow.conventions.rst: the 2D/3D constant-ROI difference is removed from both tables.docs/examples/glcm_3d_worked_example.py: the one-plane check expects 2.1875.Benchmark instruction counts
The 2D GLCM kernel records one flag per angle and takes the
_AVEcodes throughcalc_ave_populated(). Its output value is unchanged on the benchmark fixture, which populates every angle, but its instruction count may move. If the job reports a change, the updatedinstructions.jsonfollows in its owntest(benchmarks):commit.Phase-0 files touched
glcm.cpp,glcm.h,3d_glcm.cppand3d_glcm.h. The change is limited to the averaging and the constant-ROI check, so the GLCM settings work planned for phase 0 can be written on top of it.Closes PN-229, PN-304.