Skip to main content

Python Package with minimalsurface C++ extension

Project description

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

minimal_surface-0.0.2-cp312-cp312-win_amd64.whl (4.7 MB view details)

Uploaded CPython 3.12 Windows x86-64

minimal_surface-0.0.2-cp311-cp311-win_amd64.whl (4.7 MB view details)

Uploaded CPython 3.11 Windows x86-64

minimal_surface-0.0.2-cp310-cp310-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.10 Windows x86-64

minimal_surface-0.0.2-cp39-cp39-win_amd64.whl (10.1 MB view details)

Uploaded CPython 3.9 Windows x86-64

File details

Details for the file minimal_surface-0.0.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for minimal_surface-0.0.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 75594b425a66bf60992a3323ee2163530ad6deb7ea6d4a982d6c82a947459cd5
MD5 8a2fee35a27fc783dfe9cc09e11c327e
BLAKE2b-256 dbbfb3b9e46cc1a912447e7ba7d638b26ffb8a530e789592b9e6222000da8446

See more details on using hashes here.

File details

Details for the file minimal_surface-0.0.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for minimal_surface-0.0.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8a78517760f594054900f917aedec2935d28c0483646f2b0962b6b82dea04944
MD5 08d0ad37166386dbf7649f6737dd21a1
BLAKE2b-256 5c0f2155ac3f08dadcc7eb714a6cf312473aca2b397d76e34f70fa8cca3d8799

See more details on using hashes here.

File details

Details for the file minimal_surface-0.0.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for minimal_surface-0.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a28525c5dc7b1d17ceef212cc54bca356d7e13463383a99b8f0245b41ff59834
MD5 e3430680ab467aa6dd5eaa2ad3b2a297
BLAKE2b-256 4570d8d55195c2c194b86b8c79eb5abc91a25b2d481c6cde1fd28351f530f26f

See more details on using hashes here.

File details

Details for the file minimal_surface-0.0.2-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for minimal_surface-0.0.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 765bf4f584c5afaaea09016028a050536d2ac4515db72ae040093d49791a8bc4
MD5 4a122f82457546f8bcc167c2fa51d032
BLAKE2b-256 f2ed1a62122976315ecf62556f25e3bde73fb6d86d2233cf09db00f2ed5d422b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page