TorchMorph: CUDA-accelerated Morphological Transforms

Hugging Face Daily Papers Papers

Summary

TorchMorph is a CUDA-accelerated PyTorch extension that provides GPU-optimized morphological and distance transform operators, achieving significant speed-ups over CPU implementations like SciPy with a compatible API.

Morphological transforms are long-standing tools for shape and mask processing, but the de facto reference implementation in the Python ecosystem, i.e. scipy.ndimage, is CPU-only, single-array, and therefore unusable inside a GPU training loop without an expensive device-to-host round trip. GPU vision libraries built on PyTorch cover a narrow subset of these operators, typically restricted to two spatial dimensions and flat structuring elements. We present TorchMorph, a lightweight PyTorch extension that closes this gap. TorchMorph exposes 22 public operators covering binary morphology, greyscale morphology, exact and approximate distance transforms, and entropy-regularised optimal transport, all implemented as fused CUDA kernels that operate directly on (B, C, Spatial...) CUDA tensors with up to eight spatial dimensions. The API deliberately mirrors scipy.ndimage argument-for-argument, including border modes, structuring-element origins and pre-allocated outputs, so that existing pipelines port with a change of import. We describe the layered architecture and the kernel designs behind each operator family. Against single-threaded CPU references, batched execution reaches up to 1.1e3 times the throughput of scipy.ndimage on greyscale morphology and up to 350x on exact Euclidean distance transforms, while the Sinkhorn solver runs up to 42x faster than POT. Binary and chamfer operators reproduce their SciPy counterparts exactly, and every float-valued operator agrees with the CPU reference to within 1.8e-6 absolute error. TorchMorph is released under the MIT licence at https://intcomp.github.io/tm.
Original Article
View Cached Full Text

Cached at: 08/26/26, 03:14 AM

Paper page - TorchMorph: CUDA-accelerated Morphological Transforms

Source: https://huggingface.co/papers/2608.24738

Abstract

TorchMorph is a PyTorch extension providing GPU-accelerated morphological and distance-transform operators across up to eight dimensions with a SciPy-compatible API.

Morphological transformsare long-standing tools for shape and mask processing, but the de facto reference implementation in the Python ecosystem, i.e. scipy.ndimage, is CPU-only, single-array, and therefore unusable inside a GPU training loop without an expensive device-to-host round trip. GPU vision libraries built on PyTorch cover a narrow subset of these operators, typically restricted to two spatial dimensions and flat structuring elements. We presentTorchMorph, a lightweight PyTorch extension that closes this gap.TorchMorphexposes 22 public operators coveringbinary morphology,greyscale morphology, exact and approximatedistance transforms, andentropy-regularised optimal transport, all implemented as fusedCUDA kernelsthat operate directly on (B, C, Spatial...) CUDA tensors with up to eight spatial dimensions. The API deliberately mirrors scipy.ndimage argument-for-argument, including border modes, structuring-element origins and pre-allocated outputs, so that existing pipelines port with a change of import. We describe the layered architecture and the kernel designs behind each operator family. Against single-threaded CPU references, batched execution reaches up to 1.1e3 times the throughput of scipy.ndimage ongreyscale morphologyand up to 350x on exact Euclideandistance transforms, while theSinkhorn solverruns up to 42x faster than POT. Binary and chamfer operators reproduce their SciPy counterparts exactly, and every float-valued operator agrees with the CPU reference to within 1.8e-6 absolute error.TorchMorphis released under the MIT licence at https://intcomp.github.io/tm.

View arXiv pageView PDFProject pageGitHubAdd to collection

Get this paper in your agent:

hf papers read 2608\.24738

Don’t have the latest CLI?curl \-LsSf https://hf\.co/cli/install\.sh \| bash

Models citing this paper0

No model linking this paper

Cite arxiv.org/abs/2608.24738 in a model README.md to link it from this page.

Datasets citing this paper0

No dataset linking this paper

Cite arxiv.org/abs/2608.24738 in a dataset README.md to link it from this page.

Spaces citing this paper0

No Space linking this paper

Cite arxiv.org/abs/2608.24738 in a Space README.md to link it from this page.

Collections including this paper0

No Collection including this paper

Add this paper to acollectionto link it from this page.

Similar Articles

TorchKM: A GPU-Oriented Library for Kernel Learning and Model Selection

arXiv cs.LG

TorchKM is an open-source GPU-accelerated library for kernel machines (SVMs, kernel logistic regression, etc.) with a scikit-learn-style API. It accelerates training and model selection by reusing matrix operations, offering substantial speedups over standard baselines.

@FeitengLi: Open-source Flash-SoftDTW provides an ultra-fast, low-memory soft-DTW operator for PyTorch training. It can be used to compute alignment losses for sequences of different lengths, train TTS models, and more. Substantially optimized: compared with a row-by-row sequential CUDA baseline, the forward pass is up to 365× faster, for…

X AI KOLs Timeline

The open-source Flash-SoftDTW project has released an ultra-fast, low-memory soft-DTW operator supporting PyTorch training, delivering up to 365× faster forward passes and up to 98× faster forward-plus-backward passes compared with a row-by-row sequential CUDA baseline. It can be used for alignment losses between sequences of unequal lengths and for training TTS models.