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:
- At the default settings, the head matches PyRadiomics 3.0.1 run with
symmetricalGLCM=Falseon the same 64 MATLAB levels forCLUPROM,CLUSHADE,CLUTENDandINFOMEAS1, in 2D and 3D, andJVARmatchesSumSquaresin 2D. On the base the cluster features miss it. - The 0-degree
CLUPROM,CLUSHADEandINFOMEAS1no longer change under a left-right mirror; on the base they changed on all 12 images. - IBSI mode gives exactly the base values.
Nits
- PR description, Summary: "IBSI mode and PyRadiomics-style binning ... none of their values change" does not hold for
JVARunder PyRadiomics binning when a bin is empty. Withcoarse_gray_depth=-20on such ROIs,GLCM_JVAR_135went from 0.655 to 10.66 and3GLCM_JVARfrom 0.755 to 11.92, which is PyRadiomics'SumSquares, as yourJVARparagraph says. The release-note list under "For the maintainers" should name that case as well.
With the default MATLAB-style binning each ordered pair is counted once, so the co-occurrence matrix is not symmetric and its two marginals differ. Six features mixed them up, in 2D and in 3D: - GLCM_CLUPROM, GLCM_CLUSHADE, GLCM_CLUTEND and GLCM_SUMVARIANCE centred i + j on twice the neighbour mean; they now centre on mu_x + mu_y. SUMVARIANCE stays the CLUTEND sum, which IBSI sum variance equals on every matrix. - GLCM_JVAR took the neighbour's grey level around the reference mean; it is now the variance of the reference level, the value GLCM_VARIANCE reports. - GLCM_INFOMEAS1 divided by the neighbour-marginal entropy; it now divides by max(HX, HY). In 3D a direction where both entropies are 0 reports the --noval substitute instead of NaN, as 2D does. IBSI mode and PyRadiomics-style binning count both orders, so their values do not change. A 2D ROI whose binned minimum and maximum share a grey level reports the --noval substitute in every GLCM column, the _AVE ones included, instead of 0. GLCM_HOM2_AVE and 3GLCM_HOM2_AVE are added: the angle average of HOM2, equal to GLCM_IDM_AVE. BREAKING CHANGE: with the default binning GLCM_CLUPROM, GLCM_CLUSHADE, GLCM_CLUTEND, GLCM_SUMVARIANCE, GLCM_JVAR and GLCM_INFOMEAS1, their _AVE columns and their 3GLCM_ twins take new values; a constant 2D ROI reports --noval in its GLCM columns; and the output gains GLCM_HOM2_AVE and 3GLCM_HOM2_AVE. Refs PN-148, PN-144, PN-145, PN-267, PN-146
darkclad
force-pushed
the
main-glcm-formulas
branch
from
November 23, 2026 14:48
866341d to
f9ca192
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 the default settings (MATLAB-style binning, a positive
--coarseGrayDepth, 64 by default) Nyxus counts each ordered pair of pixels once, so the GLCM is not symmetric and its two marginals, the reference pixel'sp_xand the neighbour'sp_y, differ. Six 2D and 3D GLCM features mixed the two up and changed value when the image was mirrored. They now follow the IBSI definitions on the matrix as it is. The PR also makes a constant 2D ROI report--novalin its GLCM columns, and adds the missingGLCM_HOM2_AVEand3GLCM_HOM2_AVE.IBSI mode and PyRadiomics-style binning (negative or zero grey depth) count both orders, so the matrix is symmetric there and none of their values change: every IBSI, MIRP and PyRadiomics oracle test passes unchanged.
Changes
CLUPROM,CLUSHADE,CLUTENDi + jcentred on2 mu_y, twice the neighbour meanmu_x + mu_y(AE86, 7NFM, DG8W)SUMVARIANCEmu_x + mu_yJVARsum (j - mu_x)^2 p_ij: the neighbour's level around the reference meansum (i - mu_x)^2 p_ij(UR99), the valueVARIANCEreports; both columns now take it from one computationINFOMEAS1(HXY - HXY1) / HY, the neighbour-marginal entropy(HXY - HXY1) / max(HX, HY)(R8DG). In 3D, a direction where both entropies are 0 reports the--novalsubstitute instead of NaN, as 2D already didOther changes:
_AVEones included, reports the--novalsubstitute. It used to write the substitute and then overwrite it with empty per-angle buffers, so the output showed 0 whatever--novalwas. The substitute now goes through the same per-angle buffers as an empty matrix does, sosave_valuewrites and averages it like any other value. From Python the substitute is 0, as before.GLCM_HOM2_AVE,3GLCM_HOM2_AVE. These are new columns: the mean of the per-angleHOM2values, equal toGLCM_IDM_AVE/3GLCM_IDM_AVE. They are added to the feature enums, the user-facing names, the class feature sets, the non-angled lists andsave_value.*ALL_GLCM*now has 150 columns and the 3D GLCM family 60. The feature totals are now 760, 540 in 2D and 214 in 3D.save_value(2D) no longer copiesGLCM_ACORtwice or assignsGLCM_VARIANCE_AVEtwice.JVARnow reads the grey levelI[r]of each matrix row, asJAVEandVARIANCEdo, rather than the row position plus 1. The two agree with the default binning and in IBSI mode. With PyRadiomics-style binning and an empty bin they do not, andJVARnow equalsVARIANCEthere too. The other features affected by that position-versus-level question (#510) are left to that issue.Changed values
At the default settings, on the 5 x 5 worked example of the GLCM documentation page (2D, the
_0column and the angle average). For 3D, the 3 x 4 x 4 worked example of the 3D GLCM page (the plain code, direction (1,1,1), and the 13-direction average):GLCM_CLUPROM_0GLCM_CLUPROM_AVEGLCM_CLUSHADE_0GLCM_CLUSHADE_AVEGLCM_CLUTEND_0,GLCM_SUMVARIANCE_0GLCM_CLUTEND_AVE,GLCM_SUMVARIANCE_AVEGLCM_JVAR_0GLCM_VARIANCE_0)GLCM_JVAR_AVEGLCM_INFOMEAS1_0, same image mirrored left-rightGLCM_HOM2_AVEGLCM_IDM_AVE)3GLCM_CLUPROM/_AVE3GLCM_CLUSHADE/_AVE3GLCM_CLUTEND,3GLCM_SUMVARIANCE/_AVE3GLCM_JVAR/_AVE3GLCM_VARIANCE)3GLCM_INFOMEAS1/_AVE3GLCM_HOM2_AVE3GLCM_IDM_AVE)On the unmirrored 2D image
INFOMEAS1does not change, because the neighbour-marginal entropy happens to be the larger one there. On the mirror it was 4.3 % off and is now the same as on the original image.A 4 x 4 constant ROI run from the command line with
--noval=-999reported 0 in all 149 GLCM columns. It now reports -999 in all 150, in both default and IBSI mode, like the GLRLM columns of the same run.Validation
PyRadiomics with
symmetricalGLCM=Falsecounts one order per pair, as Nyxus does by default. On the binned levels of the 2D and 3D fixtures below it agrees with the in-test IBSI reference to 3e-15 for cluster tendency, shade, prominence,SumSquaresandImc1. The tests therefore compute their reference from the definitions rather than pinning a tool run.tests/test_2d_glcm_analytic.handtests/test_3d_glcm_analytic.h. The reference counts the co-occurrence matrix from the fixture without Nyxus, at 64 MATLAB-style levels, and evaluates the IBSI expressions on it, per angle (2D) and per direction (all 13 in 3D). The fixture is the 5 x 5 example image and its left-right mirror; in 3D, a 5 x 5 x 3 box of the image, its mirror and its transpose, and the box's mirror.rel=1e-9.JVARagainst the IBSI joint variance atrel=1e-9; it also equalsVARIANCE.INFOMEAS1within the band of Nyxus' fast logarithm. The worst measured residual is 7.0e-3 in 2D and 1.4e-2 in 3D; the bands are 1.5e-2 and 2e-2, below the 4.2-4.3 % that a divisor taken from one fixed marginal is off. A second check is orientation invariance with no band: the mirror's 0-degree value (2D), and each mirrored direction (1, dy, dz) against (1, -dy, -dz) (3D), equal the original to 1e-12.tests/test_2d_glcm_mechanics.h:_AVE;GLCM_HOM2_AVEexists, is the mean of the fourGLCM_HOM2angles, and equalsGLCM_IDM_AVE;INFOMEAS1reports the substitute on a ROI whose 0-degree pairs share one level.tests/test_3d_glcm_mechanics.h: the sameINFOMEAS1guard in 3D (it returned NaN before).GLCM_HOM2_AVEis also asserted against the IBSI consensus for IDM, and against PyRadiomicsIdmand MIRPcm_inv_diff_mom.3GLCM_HOM2_AVEis asserted against PyRadiomicsIdm, and in the_AVEequivalence test.The new tests were run against the previous code first, and 9 of the 11 new analytic and mechanics cases failed there. The two that pass are the two-level negative case and the 2D
INFOMEAS1guard, which 2D already had. TheHOM2_AVEcases do not compile without the new codes. The 2D regression goldens of the six changed features are regenerated;JVAR's now equalsVARIANCE's. The 3D regression tables did not move. The -100 profile is symmetric, and on the grey64 phantom every direction's matrix happens to be symmetric too, so those tables cannot see this change; the analytic test covers it.The vetting registry has new
vetted/analyticrows for the seven features in 2D and 3D, under the recipesglcm.analytic_default_asymmetricandglcm3d.analytic_default_asymmetric, and rows for the two_AVEcodes. It has two new benchmarks, and the GLCM scanners now read the new test files.Docs
conventions.rstandibsi_mode.rst: the constant-ROI rows.CLAUDE.md.Overlap
GLCMFeature::calculate(the IBSI allocation refusal), so whichever PR merges second rebases.JVARloop and the cluster andINFOMEAS1code in both files; this PR already makesJVARreadI[r], so whichever merges second rebases.For the maintainers
This is a breaking change in values at the default settings, and it adds two columns. The release notes should list
GLCM_CLUPROM,GLCM_CLUSHADE,GLCM_CLUTEND,GLCM_SUMVARIANCE,GLCM_JVARandGLCM_INFOMEAS1, their_AVEcolumns and their3GLCM_twins.