Skip to content

ENH: Support singleton and short dimensions in SmoothingRecursiveGaussianImageFilter #6997

Open

Description

@sdiebolt

Description

SmoothingRecursiveGaussianImageFilter currently requires at least four pixels along every image dimension, even when smoothing along a particular dimension is unnecessary.

This prevents Gaussian smoothing of images containing singleton dimensions, such as 2D slices represented as 3D images (1 × Y × X). In particular, it prevents using these images with multi-resolution registration in ImageRegistrationMethodv4, unless smoothing is disabled entirely or the singleton dimension is artificially expanded.

Would it be possible to support images with dimensions smaller than four pixels, by skipping smoothing for these dimensions?

If that's something that would be interesting for ITK, I'd be up to trying my hands on a PR!

Expected behavior

  • Dimensions of size <4: Skip Gaussian smoothing along these dimensions while smoothing the remaining dimensions normally.
  • Preserve the original image dimensionality and physical geometry.
  • Preserve existing behavior and performance for images with at least four pixels along every dimension.

Actual behavior

SmoothingRecursiveGaussianImageFilter::GenerateData() currently throws an exception if any dimension contains fewer than four pixels, regardless of whether smoothing along that dimension is necessary.

This can be reproduced with the following minimal registration example using ITK Python:

import itk
import numpy as np

# Two 3D images with a singleton Z dimension.
y, x = np.mgrid[:64, :64]

fixed = itk.image_from_array(
    np.exp(-((x - 28)**2 + (y - 32)**2) / 100)[None].astype("float32")
)
moving = itk.image_from_array(
    np.exp(-((x - 32)**2 + (y - 32)**2) / 100)[None].astype("float32")
)

ImageType = type(fixed)
RegistrationType = itk.ImageRegistrationMethodv4[ImageType, ImageType]
MetricType = itk.MeanSquaresImageToImageMetricv4[ImageType, ImageType]


def register(sigma):
    metric = MetricType.New()

    # Avoid unrelated recursive Gaussian gradient filtering.
    metric.SetUseFixedImageGradientFilter(False)
    metric.SetUseMovingImageGradientFilter(False)

    registration = RegistrationType.New(
        FixedImage=fixed,
        MovingImage=moving,
        Metric=metric,
        Optimizer=itk.RegularStepGradientDescentOptimizerv4[itk.D].New(
            LearningRate=1.0,
            MinimumStepLength=0.001,
            NumberOfIterations=25,
        ),
        InitialTransform=itk.TranslationTransform[itk.D, 3].New(),
    )
    registration.SetNumberOfLevels(1)
    registration.SetShrinkFactorsPerLevel([1])
    registration.SetSmoothingSigmasPerLevel([sigma])

    registration.Update()
    return list(registration.GetTransform().GetParameters())


for sigma in (1.0, 0.0):
    try:
        print(f"sigma={sigma}: {register(sigma)}")
    except RuntimeError as error:
        print(f"sigma={sigma}: FAILED")
        print(error)

With sigma=1.0, registration fails:

ITK ERROR: SmoothingRecursiveGaussianImageFilter:
The number of pixels along dimension 2 is less than 4.
This filter requires a minimum of four pixels
along the dimension to be processed.

With sigma=0.0, registration completes successfully.

Disabling smoothing avoids the error, but also prevents Gaussian smoothing along the non-singleton dimensions, which is undesirable for multi-resolution registration.

Additional Information

This issue isn't new at all, I found several discussions on this topic:

Interestingly, elastix's MultiResolutionGaussianSmoothingPyramidImageFilter already handles singleton dimensions:

When either a shrink factor is set to zero for a particular dimension, or when the dimension itself is 1, or both, no smoothing is performed along that dimension.

This filter uses recursive Gaussian smoothing internally but explicitly skips singleton dimensions. A similar approach in SmoothingRecursiveGaussianImageFilter could address the singleton-dimension case without requiring changes to the registration framework.

Activity

  1. sdiebolt commented on Oct 23, 2026

    @sdiebolt
    Author

    A related follow-up worth tracking: if #6997 is addressed, recursive Gaussian gradient filtering should also support short dimensions so registration can work without disabling the metric gradient filters. The example above disables both filters, so smoothing support alone should address that reproducer.

    Would it make sense to handle gradients in a separate issue and PR? Singleton-axis derivatives should be zero, while dimensions of length two or three need a suitable derivative treatment rather than simply skipping the axis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:EnhancementImprovement of existing methods or implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions