Skip to main content

Minimal surface

minimal-surface is a Python package which can be utilized for the segmentation of objects in 3D images using as few as 2 points and a 2D slice! This algorithm uses energy minimization to estimate the surface of the object. To achieve fast execution the method was implemented in C++, but can be called from Python through a thin wrapper.

Installation

It can be installed from PyPI using pip:

python -m pip install minimal-surface

Note: This package is currently available only for Windows. In the future we plan to release it for Linux and Mac systems.

Usage

The easiest way to utilize our tool is by using Annotation Toolbox, a napari plugin created for fast 2 and 3D image annotation.

Example

import minimal_surface
from skimage.data import cells3d
from scipy import ndimage
import numpy as np
import matplotlib.pyplot as plt

import numpy as np

def calc_features(image):
    delta = 0.1
    max_ = np.quantile(image, .95)
    min_ = image.min()
    image = np.clip((image-min_)/(max_-min_), 0, 1)

    # This feature will consider both image gradient and intensity
    # (giving higher values when the gradient is high and the intensity is low)
    gradient = ndimage.gaussian_gradient_magnitude(image, (1., 1., 1.))
    weights = 1+(delta-1)*image**2
    phi = gradient*weights +delta*(1-image**2)
    phi = (phi-(min_:=phi.min()))/(phi.max()-min_)
    return phi

# Crop the part to the smallest size possible to prevent long computation
data = cells3d()[:, 1, 60:130, 130:190] 

# Two points on the surface of the nucleus
p1 = np.asarray([ 20., 60., 35.])
p2 = np.asarray([ 39., 12., 35.])

data = (data - (min_ := data.min())) / (data.max() - min_)
data = ndimage.gaussian_filter(data, 1.)

features = calc_features(data)
alpha = 3e-3
phi = alpha + (1-alpha)*np.exp(-5*features)
phi = phi/phi.max()

calculator = minimal_surface.MinimalSurfaceCalculator()
def segment_slice(image_slice, distance_map):
    # This function segments the input image slice.
    # Asking for user input is also possible for accurate segmentation.
    return image_slice >= 0.24

calculator.set_initial_plane_calculator(segment_slice)
# If you have multiple objects, you can run the first part separately. which requires user input,
# then finish the computationally expensive part together for the whole dataset. 
# calculator.calc_eikonal_and_transport_init(phi, data, p1, p2, True)

transport_function = calculator.calculate(phi, data, p1, p2)
print("calculated")
mask = transport_function >= 0.
plt.imshow(transport_function[35], cmap="plasma")
plt.show()

Metadata

Release files for minimal-surface 0.0.2

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 minimal-surface 0.0.2
File
minimal_surface-0.0.2-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
minimal_surface-0.0.2-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
minimal_surface-0.0.2-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
minimal_surface-0.0.2-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details

Total release size: 29.6 MB

Release files / minimal_surface-0.0.2-cp312-cp312-win_amd64.whl

Download URL minimal_surface-0.0.2-cp312-cp312-win_amd64.whl
Size 4.7 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
75594b425a66bf60992a3323ee2163530ad6deb7ea6d4a982d6c82a947459cd5
BLAKE2b-256 checksum
How to use checksums
dbbfb3b9e46cc1a912447e7ba7d638b26ffb8a530e789592b9e6222000da8446
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Release files / minimal_surface-0.0.2-cp311-cp311-win_amd64.whl

Download URL minimal_surface-0.0.2-cp311-cp311-win_amd64.whl
Size 4.7 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
8a78517760f594054900f917aedec2935d28c0483646f2b0962b6b82dea04944
BLAKE2b-256 checksum
How to use checksums
5c0f2155ac3f08dadcc7eb714a6cf312473aca2b397d76e34f70fa8cca3d8799
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Release files / minimal_surface-0.0.2-cp310-cp310-win_amd64.whl

Download URL minimal_surface-0.0.2-cp310-cp310-win_amd64.whl
Size 10.1 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
a28525c5dc7b1d17ceef212cc54bca356d7e13463383a99b8f0245b41ff59834
BLAKE2b-256 checksum
How to use checksums
4570d8d55195c2c194b86b8c79eb5abc91a25b2d481c6cde1fd28351f530f26f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Release files / minimal_surface-0.0.2-cp39-cp39-win_amd64.whl

Download URL minimal_surface-0.0.2-cp39-cp39-win_amd64.whl
Size 10.1 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
765bf4f584c5afaaea09016028a050536d2ac4515db72ae040093d49791a8bc4
BLAKE2b-256 checksum
How to use checksums
f2ed1a62122976315ecf62556f25e3bde73fb6d86d2233cf09db00f2ed5d422b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.10

Release history Release notifications | RSS feed

This release

0.0.2 This release

4 release files

0.0.1

4 release files

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