Skip to content

Commit e02743b

Browse files
fedorovclaude
andcommitted
ENH: switch slice spacing tolerance from absolute to relative
Replace absolute sliceIntervalTolerance (0.2mm) with a relative relativeSliceTolerance (2% of expected spacing). The absolute threshold was inappropriate for preclinical/small-animal imaging in IDC (~1,400 mouse MR series with ~0.1mm spacing), where 0.2mm is 2x the actual spacing. Empirical analysis confirmed floating-point jitter is sub-micrometer, so no absolute floor is needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b20d7c4 commit e02743b

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

scripts/sql/volume_geometry_index.sql

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
# is computed from the full span (first-to-last slice position divided by
3030
# N-1), and each adjacent pair is compared against it — an approach that
3131
# minimizes floating-point accumulation errors (see 3D Slicer reference
32-
# below).
32+
# below). The slice spacing tolerance is relative (a fraction of expected
33+
# spacing) rather than absolute, so it scales correctly for both human
34+
# imaging (~1-5mm spacing) and preclinical/small-animal imaging (~0.1mm).
3335
#
3436
# Similarly, projecting IPP onto the row and column directions gives
3537
# in-plane coordinates that should be constant across all slices if the
@@ -71,9 +73,10 @@
7173
# `bigquery-public-data.idc_current.dicom_all` with e.g. `bigquery-public-data.idc_v18.dicom_all`
7274

7375
# Configurable parameters
74-
DECLARE sliceIntervalTolerance FLOAT64 DEFAULT 0.2; # max allowed variation in slice spacing (mm);
75-
# matches kSliceTolerance in dcm2niix
76-
# (https://github.com/rordenlab/dcm2niix/blob/f6d7a001/console/nii_dicom_batch.cpp#L64)
76+
DECLARE relativeSliceTolerance FLOAT64 DEFAULT 0.02; # max allowed variation in slice spacing as a fraction
77+
# of expected spacing (2%); relative tolerance scales
78+
# correctly for both human imaging (~1-5mm spacing)
79+
# and preclinical/small-animal imaging (~0.1mm spacing)
7780
DECLARE inPlaneTolerance FLOAT64 DEFAULT 0.1; # max in-plane position jitter (mm)
7881
DECLARE orientationTolerance FLOAT64 DEFAULT 0.01; # cross-product magnitude deviation from 1.0
7982

@@ -275,11 +278,15 @@ geometryChecks AS (
275278
MAX(inPlaneCol) - MIN(inPlaneCol) < inPlaneTolerance AS consistent_in_plane_col,
276279

277280
# uniform_slice_spacing: TRUE if every adjacent slice interval is
278-
# within sliceIntervalTolerance of the expected uniform spacing.
281+
# within relativeSliceTolerance of the expected uniform spacing.
282+
# The tolerance is relative (a fraction of expected_spacing) so it
283+
# scales correctly for both human imaging (~1-5mm spacing) and
284+
# preclinical/small-animal imaging (~0.1mm spacing).
279285
# The expected spacing is derived from the full first-to-last span
280286
# (see CTE 3 above). MAX ignores NULLs, so the last slice (which has
281287
# NULL slice_interval from LEAD) is automatically excluded.
282-
MAX(ABS(slice_interval - expected_spacing)) < sliceIntervalTolerance AS uniform_slice_spacing
288+
MAX(ABS(slice_interval - expected_spacing))
289+
< relativeSliceTolerance * ABS(ANY_VALUE(expected_spacing)) AS uniform_slice_spacing
283290

284291
FROM sliceProjection
285292
GROUP BY
@@ -320,7 +327,7 @@ SELECT
320327
consistent_image_dimensions,
321328
# description:
322329
# TRUE if the spacing between consecutive slices is constant
323-
# (within sliceIntervalTolerance)
330+
# (within relativeSliceTolerance, a relative fraction of expected spacing)
324331
uniform_slice_spacing,
325332
# description:
326333
# TRUE if all individual checks pass, indicating the series forms a regularly-spaced

0 commit comments

Comments
 (0)