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 ran 2D and 3D GLCM on random ROIs, some using every bin and some leaving bins empty, against PyRadiomics 3.0.1 (binCount 20, symmetric):
- With
coarse_gray_depth=-20and empty bins, the base misses PyRadiomics on 13 features (DIFVAR0.852 against 15.603 on one ROI). The head matches it on every non-logarithmic feature in 2D and 3D;INFOMEAS1andINFOMEAS2keep thefast_log10gap they had before. - MATLAB and IBSI binning, and PyRadiomics binning with every bin used, give exactly the base values.
#552 also edits glcm.cpp, 3d_glcm.cpp and the GLCM docs, and #544 f_glcm.rst, so whichever merges later rebases.
added 3 commits
November 20, 2026 12:37
… leaves bins empty
With a negative coarse_gray_depth the 2D and 3D co-occurrence matrices hold a
row only for the binned levels present in the ROI, so row x stands for level
I[x]. When a bin is empty the two differ, and several features read x where
they meant I[x]:
- calculatePxpmy bucketed p_{x+y} and p_{x-y} by row sum and difference, and
kValuesSum / kValuesDiff kept the level of whichever pair was written last.
DIFAVE, DIFVAR, IV and SUMAVERAGE were far off; DIFENTRO, SUMENTROPY, ID,
IDM, IDN and IDMN read the same distributions.
- IDN and IDMN divided by the number of levels present, not the highest level.
- DIS, HOM1 and HOM2 used the row distance |x-y|, and JVAR used x+1 against the
level-based JAVE.
p_{x+y} and p_{x-y} are now distributions over level sums and differences,
0..2Ng and 0..Ng-1 with Ng the highest level, as in PyRadiomics, and every
feature above works on I[x]. f_dvar is one sum over k. MATLAB and IBSI binning
are unchanged: there I[x] == x+1. Both out-of-core paths share this code.
On a 3D CT validation set (5 volumes x 2 labels, binCount 20) the three ROIs
that leave bins empty were off by up to 22x in DIFVAR; 30 2D slices of the same
data failed 13 features. Both now match PyRadiomics to <= 6e-14 on every
non-logarithmic feature, twins included.
Tests: TEST_2D_GLCM_GAP_LEVELS_PYRADIOMICS and
TEST_3D_GLCM_GAP_LEVELS_PYRADIOMICS pin every GLCM feature on a 12x12 slice
crop and a 9x9x5 volume crop of that CT data, whose levels leave interior bins
empty and put a few voxels alone in the top bin. Goldens come from
tests/vetting/oracles/gen_glcm_gap_levels_pyradiomics.py (PyRadiomics 3.0.1),
which reads the crops from the test headers. Both tests fail on the previous
code (13 features each) and pass with this change. The existing PyRadiomics
fixtures could not see it: the 3D phantom occupies all 20 bins and the 2D ones
run the IBSI identity recipe, where every level keeps a row.
Docs: f_glcm.rst and f_glcm_3d.rst state the level convention and the new
fixture; the 2D PyRadiomics vetting report and config_recipes.md record it.
Closes PolusAI#510
…levels recipe - glcm.cpp, 3d_glcm.cpp: kValuesSum and kValuesDiff held k at index k, so SUMAVERAGE, DIFAVE, DIFVAR and IV now use k directly and both members are gone. f_dvar and f_dentropy no longer take the matrix they did not read. Values are unchanged. - The comments on calculatePxpmy, IDN and IDMN, and the N_g row of f_glcm.rst, say what N_g is in each binning mode: the highest level present under PyRadiomics-style binning, the bin count under MATLAB and IBSI binning. - oracle_coverage.csv: one vetted pyradiomics row per feature pinned by TEST_2D_GLCM_GAP_LEVELS_PYRADIOMICS and TEST_3D_GLCM_GAP_LEVELS_PYRADIOMICS, recipe glcm.pyradiomics_gap_levels_bincount20, with the bands those tests apply. coverage_report.md and report_output.* regenerated. - The 2D gap-levels test restores GLCMFeature::angles on every exit path, test_3d_glcm_pyradiomics.h no longer repeats includes test_main_nyxus.h provides, and the generator keeps a single tolerance.
… tests The gap-levels tests assert GLCM features against PyRadiomics, so the generated oracle column now lists PyRadiomics next to MIRP for those rows.
darkclad
force-pushed
the
main-glcm-gap-levels
branch
from
November 23, 2026 14:48
5340dc0 to
6371abc
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.
Summary
With PyRadiomics binning (
coarse_gray_depth< 0), 2D and 3D GLCM features now match PyRadiomics when the ROI leaves some bins empty. In this mode the co-occurrence matrix has a row only for the binned levels present in the ROI, so rowxstands for levelI[x]. Several features used the row index where they meant the level. The two agree only when every bin between 1 and the highest level is occupied, so ROIs that use every bin gave the right values and the existing fixtures passed.calculatePxpmybucketed p_{x+y} and p_{x−y} by row sum and row difference, andkValuesSum/kValuesDiffheld the level of whichever pair was written last.DIFAVE,DIFVAR,IVandSUMAVERAGEwere far off. A dense block of low bins with a few voxels alone in the top bin makes this worst: one CT ROI hadDIFVAR8.86 against 0.392.DIFENTRO,SUMENTROPY,ID,IDM,IDNandIDMNread the same distributions.IDNandIDMNdivided by the number of levels present, not by the highest level.DIS,HOM1andHOM2used the row distance|x−y|, andJVARusedx+1against the level-basedJAVE.p_{x+y} and p_{x−y} are now distributions over level sums
0..2Ngand level differences0..Ng−1, withNgthe highest level present, as in PyRadiomics. Every feature above works onI[x]. MATLAB and IBSI binning do not change, because thereI[x] == x+1. The out-of-core paths share this code.Reported by @ndonyapour from a 3D CT validation against PyRadiomics (5 volumes × 2 labels,
binCount20). Closes #510.Change
Two commits:
fix(glcm): use grey levels, not matrix rows, when PyRadiomics binning leaves bins empty: the fix, the tests, the generator and the docs.refactor(glcm): drop the identity k-value vectors and record the gap-levels recipe: no value changes. It is cleanup plus the registry rows for the new recipe.src/nyx/features/glcm.cpp,src/nyx/features/3d_glcm.cpp: the same changes in both files.calculatePxpmybuilds the distributions by level.f_dvaris now a single sum overk.IDM,ID,IDN,IDMNandDIFENTROiterate overPxmy.size().DIS,HOM1,HOM2andJVARuseI[x].SUMAVERAGE,DIFAVE,DIFVARandIVusekdirectly.src/nyx/features/glcm.h,src/nyx/features/3d_glcm.h:kValuesSumandkValuesDiff, which heldkat indexk, are gone.f_dvarandf_dentropyno longer take the matrix they did not read.tests/test_2d_glcm_pyradiomics.h,tests/test_3d_glcm_pyradiomics.h,tests/test_all.cc:TEST_2D_GLCM_GAP_LEVELS_PYRADIOMICSandTEST_3D_GLCM_GAP_LEVELS_PYRADIOMICSpin every GLCM feature on two crops of that CT data. The 2D crop is a 12 × 12 slice with levels {1..8, 11, 13, 20}. The 3D crop is a 9 × 9 × 5 box with levels {1..7, 9, 10, 12, 20}.tests/vetting/oracles/gen_glcm_gap_levels_pyradiomics.py: reads the crops from the test headers, runs PyRadiomics (binCount20, symmetrical, distance 1,force2Dfor the slice), and checks the pins in both directions at 1e-12.tests/vetting/oracle_coverage.csv: one vettedpyradiomicsrow per feature the two new tests pin, 59 in 2D and 59 in 3D, under recipeglcm.pyradiomics_gap_levels_bincount20. Each row carries the band its test applies.report_output.csvandreport_output.mdare regenerated.f_glcm.rstandf_glcm_3d.rstsay whatN_gis in each binning mode: the highest level present under PyRadiomics-style binning, and the bin count under MATLAB and IBSI binning.glcm.pyradiomics_gap_levels_bincount20recipe inconfig_recipes.mdrecord the same.Changed values
These change only under PyRadiomics binning, and only for ROIs that leave a bin below their highest level empty. 3D, the three affected ROIs of the CT set,
binCount20:3GLCM_DIFAVE3GLCM_DIFVAR3GLCM_IV3GLCM_SUMAVERAGE3GLCM_IDN3GLCM_IDMN3GLCM_DIFAVE3GLCM_SUMAVERAGE3GLCM_IV3GLCM_DIFAVE3GLCM_IVAfter this change, every non-logarithmic GLCM feature of all 10 ROIs, twins included, matches PyRadiomics to ≤ 6e-14. On the 7 ROIs that use all 20 bins, the values did not change. The entropy features and
IMC1/IMC2keep the documentedfast_log10band, and their values did not change.In 2D, 30 slices of the same data (10 of them leave bins empty) failed 13 features before this change,
DIS,HOM1,HOM2andJVARamong them. All 30 match after it.Testing
The tests below ran on each commit.
pytest tests/python/on the whole directory: 346 passed, 4 skipped.pytest tests/python/through the bindings (327 passed). 0 sanitizer diagnostics.check_coverage.py,check_test_names.py,run_scanners.py,report_features.py --check,gen_feature_reference.py --check,gen_cli_reference.py --checkandsphinx-build -W: clean.gen_glcm_gap_levels_pyradiomics.pyre-verifies every pin.Not in this PR, filed on Axle's PN Jira board (https://labshare.atlassian.net/jira/software/projects/PN/boards/851):