Skip to main content

Morphocore

Morph### Installation from Source

git clone git@gitlab.lre.epita.fr:aurelien.hurand/morphocore.git
cd morphocore
pip install . --no-build-isolation

CPU-Only Installation (without CUDA):

MORPHO_WITH_CUDA=0 pip install . --no-build-isolation

This is useful when:

  • You don't have an NVIDIA GPU
  • CUDA Toolkit is not installed
  • You want faster compilation times
  • You're deploying on CPU-only serverss a Python library designed to integrate mathematical morphology into neural networks. It provides differentiable (float and double) and optimized morphological operations, enabling deep learning architectures to leverage powerful image processing tools from mathematical morphology.

Main Features

Installation

Installation from PyPi:

pip install morphocore

❗If you have compatibility issue with the version compile on Pypi please compile the library from source like below !

Installation from source:

git clone git@gitlab.lre.epita.fr:aurelien.hurand/morphocore.git
cd morphocore
pip install . --no-build-isolation

Requirements for Pre-compiled Package (PyPI)

If you install from PyPI using pip install morphocore, you'll need:

  • Python >= 3.11
  • PyTorch >= 2.6
  • CUDA >= 12.3

If your environment doesn't meet these requirements, please compile from source instead.

API Reference

Functional Interface

dilation(input, weight, channel_merge_mode="max")

Performs morphological dilation on the input tensor.

Parameters:

  • input (Tensor): Input tensor of shape (B, C, H, W)
  • weight (Tensor): Structuring element of shape (out_channels, in_channels, kH, kW)
  • channel_merge_mode (str): Channel combination method - "max", "min", "sum", "mean", or "identity"

Returns:

  • output (Tensor): Dilated tensor of shape (B, out_channels, H, W)
from morphocore.functional import dilation

# Basic usage
result = dilation(image, structuring_element, "sum")

# With different merge modes
max_result = dilation(image, kernel, "max")    # Maximum across channels
sum_result = dilation(image, kernel, "sum")    # Sum across channels
mean_result = dilation(image, kernel, "mean")  # Average across channels
identity_result = dilation(image, kernel, "identity")  # No channel merging, keeping all channels linear in_channels = out_channels

erosion(input, weight, channel_merge_mode="max")

Performs morphological erosion on the input tensor.

Parameters: Same as dilation() Returns: Same as dilation()

from morphocore.functional import erosion

result = erosion(image, structuring_element, "sum")

smorph(input, weight, channel_merge_mode="max", alpha=0.0)

Smooth approximation of morphological operations using softmax.

Parameters:

  • Same as dilation() plus:
  • alpha (float): Control parameter for either dilation or erosion behaviour
    • When alpha is large -> smorph behaves like dilation
    • When alpha is very negative -> smorph behaves like erosion
    • When alpha is close to 0 -> then smorph is something between an erosion and a dilation.
from morphocore.functional import smorph

# Soft approximation of morphological operations
result = smorph(image, kernel, "sum", alpha=0.0)

Neural Network Modules

Mnn.Dilation(in_channels, out_channels, kernel_size, channel_merge_mode="max")

Learnable dilation layer for neural networks.

Parameters:

  • in_channels (int): Number of input channels
  • out_channels (int): Number of output channels
  • kernel_size (int or tuple): Size of the morphological kernel
  • channel_merge_mode (str): Channel merge strategy
import morphocore.nn as Mnn

# Create a learnable dilation layer
dilation_layer = Mnn.Dilation(
    in_channels=3, 
    out_channels=16, 
    kernel_size=(3, 3), 
    channel_merge_mode="sum"
)
output = dilation_layer(input_tensor)

Mnn.Erosion(in_channels, out_channels, kernel_size, channel_merge_mode="max")

Learnable erosion layer for neural networks.

erosion_layer = Mnn.Erosion(
    in_channels=3, 
    out_channels=16, 
    kernel_size=(5, 5), 
    channel_merge_mode="mean"
)
output = erosion_layer(input_tensor)

Mnn.SMorph(in_channels, out_channels, kernel_size, channel_merge_mode="max", alpha=1.0)

Smooth morphological layer using softmax approximation.

smorph_layer = Mnn.SMorph(
    in_channels=3, 
    out_channels=8, 
    kernel_size=(3, 3), 
    channel_merge_mode="sum",
    alpha=2.0
)
output = smorph_layer(input_tensor)

Channel Merge Modes Explained

  • "sum": Sums values across input channels
  • "mean": Averages values across input channels

Project Structure

  • morphocore/functional/: Basic morphological functions
  • morphocore/nn/: PyTorch modules for neural networks
  • morphocore/functional/csrc/: C++/CUDA source code for acceleration
  • tests/: Unit, functional and benchmark tests

Dependencies

  • Python >= 3.8
  • PyTorch
  • NumPy

Contributing

Contributions are welcome! Please submit issues and pull requests.

License

This project is licensed under the MIT License.

Metadata

Release files for morphocore 0.11.0.213

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for morphocore 0.11.0.213
File Actions
morphocore-0.11.0.213-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for morphocore-0.11.0.213-cp313-cp313-win_amd64.whl
morphocore-0.11.0.213-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for morphocore-0.11.0.213-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
morphocore-0.11.0.213-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for morphocore-0.11.0.213-cp312-cp312-win_amd64.whl
morphocore-0.11.0.213-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for morphocore-0.11.0.213-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
morphocore-0.11.0.213-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for morphocore-0.11.0.213-cp311-cp311-win_amd64.whl
morphocore-0.11.0.213-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for morphocore-0.11.0.213-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Total release size: 11.2 MB

Release files / morphocore-0.11.0.213-cp313-cp313-win_amd64.whl

Download URL morphocore-0.11.0.213-cp313-cp313-win_amd64.whl
Size 1.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
2cf4481c2767ef148dc8460d5d9145d844c3b9e2911d90afa7117a354b308900
BLAKE2b-256 checksum
How to use checksums
e13529358a623a5e4c44175665a60a78f042253c854562de7af7c39aa6e86093
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / morphocore-0.11.0.213-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL morphocore-0.11.0.213-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 2.6 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
2eb9dcf82fd83874dba9265714d7ca78e124fddaf7ba35adb026e1c3aa1bd9d4
BLAKE2b-256 checksum
How to use checksums
5d1512c6512cc8835c9fc19a7af6d39dc9481bbd907de3b76a11cb6b63e43aba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / morphocore-0.11.0.213-cp312-cp312-win_amd64.whl

Download URL morphocore-0.11.0.213-cp312-cp312-win_amd64.whl
Size 1.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
bdb29cbb1e639d6aaf59ef86dba5ede4b42323fd6f8846399220c7833a5363de
BLAKE2b-256 checksum
How to use checksums
5a418125b6d254d84c9b8117d62f00e927e01aab82ea7226661f48463c2ce0fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / morphocore-0.11.0.213-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL morphocore-0.11.0.213-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 2.6 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
242a3a8433afc853839734183f0a63e40f1205ed1848378a57a103948f812a4d
BLAKE2b-256 checksum
How to use checksums
860997be1fbf2ae4234b9cc8a5425eddfb3e3b48b76dfde5f16038094dc2b8fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / morphocore-0.11.0.213-cp311-cp311-win_amd64.whl

Download URL morphocore-0.11.0.213-cp311-cp311-win_amd64.whl
Size 1.1 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
bd9ff4219f2395f9893d22e366fa3b5068ad954bcda1bdcdec0447d2ee5bbe60
BLAKE2b-256 checksum
How to use checksums
f47bc8c3818221530566850b315dc56156b9bf4c97f75407c7fb6d1c426879d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / morphocore-0.11.0.213-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL morphocore-0.11.0.213-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 2.6 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
5dc81df2a791c08ed296ceab02aecf84ad0e183cdd706efda06151da4b260c51
BLAKE2b-256 checksum
How to use checksums
b8363d8ee25a8ce9290dbd7c20b73e72961e3914c0925769f1cbd1ae870d569e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for morphocore 0.11.0.213

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.11.0.213 This release

6 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page