Skip to content

fix(glcm)!: follow the IBSI definitions on the default one-order matrix - #552

Open
darkclad wants to merge 2 commits into
PolusAI:mainfrom
darkclad:main-glcm-formulas
Open

darkclad wants to merge 2 commits into
PolusAI:mainfrom
darkclad:main-glcm-formulas

Conversation

@darkclad

Copy link
Copy Markdown

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's p_x and the neighbour's p_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 --noval in its GLCM columns, and adds the missing GLCM_HOM2_AVE and 3GLCM_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

Feature (2D and 3D) Before Now (IBSI)
CLUPROM, CLUSHADE, CLUTEND i + j centred on 2 mu_y, twice the neighbour mean centred on mu_x + mu_y (AE86, 7NFM, DG8W)
SUMVARIANCE the cluster tendency value above still the cluster tendency sum, which is IBSI sum variance (OEEB) on every matrix, since the IBSI sum average is mu_x + mu_y
JVAR sum (j - mu_x)^2 p_ij: the neighbour's level around the reference mean sum (i - mu_x)^2 p_ij (UR99), the value VARIANCE reports; both columns now take it from one computation
INFOMEAS1 (HXY - HXY1) / HY, the neighbour-marginal entropy (HXY - HXY1) / max(HX, HY) (R8DG). In 3D, a direction where both entropies are 0 reports the --noval substitute instead of NaN, as 2D already did

Other changes:

  • Constant 2D ROI. When the ROI's binned minimum and maximum share a grey level, every GLCM column, the _AVE ones included, reports the --noval substitute. It used to write the substitute and then overwrite it with empty per-angle buffers, so the output showed 0 whatever --noval was. The substitute now goes through the same per-angle buffers as an empty matrix does, so save_value writes 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-angle HOM2 values, equal to GLCM_IDM_AVE / 3GLCM_IDM_AVE. They are added to the feature enums, the user-facing names, the class feature sets, the non-angled lists and save_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 copies GLCM_ACOR twice or assigns GLCM_VARIANCE_AVE twice.

JVAR now reads the grey level I[r] of each matrix row, as JAVE and VARIANCE do, 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, and JVAR now equals VARIANCE there 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 _0 column 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):

Column Before After
GLCM_CLUPROM_0 1465591.86 1534376.44
GLCM_CLUPROM_AVE 682771.57 691436.43
GLCM_CLUSHADE_0 -585.66 9490.19
GLCM_CLUSHADE_AVE -325.07 3245.88
GLCM_CLUTEND_0, GLCM_SUMVARIANCE_0 882.25 867.43
GLCM_CLUTEND_AVE, GLCM_SUMVARIANCE_AVE 551.07 543.69
GLCM_JVAR_0 345.41 332.44 (= GLCM_VARIANCE_0)
GLCM_JVAR_AVE 340.68 331.80
GLCM_INFOMEAS1_0, same image mirrored left-right -0.33891 -0.32600 (the unmirrored value, unchanged)
GLCM_HOM2_AVE absent 0.16484 (= GLCM_IDM_AVE)
3GLCM_CLUPROM / _AVE 979322.69 / 800828.03 940651.22 / 785518.35
3GLCM_CLUSHADE / _AVE -6414.10 / -2489.76 -698.91 / -646.28
3GLCM_CLUTEND, 3GLCM_SUMVARIANCE / _AVE 704.76 / 577.59 697.35 / 575.61
3GLCM_JVAR / _AVE 257.66 / 291.31 334.03 / 307.68 (= 3GLCM_VARIANCE)
3GLCM_INFOMEAS1 / _AVE -0.23829 / -0.20209 -0.23642 / -0.20152
3GLCM_HOM2_AVE absent 0.22839 (= 3GLCM_IDM_AVE)

On the unmirrored 2D image INFOMEAS1 does 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=-999 reported 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=False counts 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, SumSquares and Imc1. The tests therefore compute their reference from the definitions rather than pinning a tool run.

  • tests/test_2d_glcm_analytic.h and tests/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.
    • Cluster prominence, shade, tendency and sum variance at rel=1e-9.
    • JVAR against the IBSI joint variance at rel=1e-9; it also equals VARIANCE.
    • INFOMEAS1 within 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:
    • a constant ROI reports a -999 substitute in every angle of every GLCM feature and in every _AVE;
    • a two-level ROI reports no substitute anywhere, the negative case;
    • GLCM_HOM2_AVE exists, is the mean of the four GLCM_HOM2 angles, and equals GLCM_IDM_AVE;
    • INFOMEAS1 reports the substitute on a ROI whose 0-degree pairs share one level.
  • tests/test_3d_glcm_mechanics.h: the same INFOMEAS1 guard in 3D (it returned NaN before).
  • GLCM_HOM2_AVE is also asserted against the IBSI consensus for IDM, and against PyRadiomics Idm and MIRP cm_inv_diff_mom. 3GLCM_HOM2_AVE is asserted against PyRadiomics Idm, and in the _AVE equivalence 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 INFOMEAS1 guard, which 2D already had. The HOM2_AVE cases do not compile without the new codes. The 2D regression goldens of the six changed features are regenerated; JVAR's now equals VARIANCE'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/analytic rows for the seven features in 2D and 3D, under the recipes glcm.analytic_default_asymmetric and glcm3d.analytic_default_asymmetric, and rows for the two _AVE codes. It has two new benchmarks, and the GLCM scanners now read the new test files.

Docs

  • The 2D and 3D GLCM pages: formulas, relations, version notes, the constant-ROI paragraph, the asymmetric-matrix section and the validation section.
  • conventions.rst and ibsi_mode.rst: the constant-ROI rows.
  • The feature descriptions, and the regenerated feature list, group page and GLCM indexes.
  • The feature totals in the README, the docs index and CLAUDE.md.
  • The worked-example scripts, which pin the new default-settings values.

Overlap

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_JVAR and GLCM_INFOMEAS1, their _AVE columns and their 3GLCM_ twins.

@vjaganat90 vjaganat90 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I built the head and its base:

  • At the default settings, the head matches PyRadiomics 3.0.1 run with symmetricalGLCM=False on the same 64 MATLAB levels for CLUPROM, CLUSHADE, CLUTEND and INFOMEAS1, in 2D and 3D, and JVAR matches SumSquares in 2D. On the base the cluster features miss it.
  • The 0-degree CLUPROM, CLUSHADE and INFOMEAS1 no 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 JVAR under PyRadiomics binning when a bin is empty. With coarse_gray_depth=-20 on such ROIs, GLCM_JVAR_135 went from 0.655 to 10.66 and 3GLCM_JVAR from 0.755 to 11.92, which is PyRadiomics' SumSquares, as your JVAR paragraph 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants