Skip to main content

Now function returns both result image and subtracted background

Project description

A numpy implementation of the Rolling ball and sliding paraboloid background subtraction algorithms based on https://github.com/mbalatsko/opencv-rolling-ball transcription

License: MIT

Fully Ported to Python from ImageJ's Background Subtractor. Only works for 8-bit greyscale images currently. Based on the concept of the rolling ball algorithm described in Stanley Sternberg's article, "Biomedical Image Processing", IEEE Computer, January 1983. Imagine that the 2D grayscale image has a third (height) dimension by the image value at every point in the image, creating a surface. A ball of given radius is rolled over the bottom side of this surface; the hull of the volume reachable by the ball is the background. https://imagej.net/ij/developer/source/ij/plugin/filter/BackgroundSubtracter.java.html

This algorithms are perfect for microscope images, to distinguish particles from background.

Installation

pip install numpy-rolling-ball

Usage

# Ejemplo A: usando PIL (Pillow)
from PIL import Image
import numpy as np
from numpy_rolling_ball import subtract_background_rolling_ball

img = np.array(Image.open('path/to/img.tif').convert('L'))  # uint8 2D
img, background = subtract_background_rolling_ball(
    img, 30, light_background=True, use_paraboloid=False, do_presmooth=True
)

# Ejemplo B: usando un array NumPy ya existente
# (cualquier método que te entregue un array uint8 2D es válido:
# imageio, tifffile, OpenSlide, capturas de cámara, etc.)
import numpy as np
from numpy_rolling_ball import subtract_background_rolling_ball

img = np.asarray(your_uint8_grayscale_array)  # shape (H, W), dtype uint8
img, background = subtract_background_rolling_ball(
    img, 30, light_background=True, use_paraboloid=False, do_presmooth=True
)

Example outputs

Input

Input

Subtracted background

Background

Without background

Without background

Project details


Download files

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

Source Distribution

numpy_rolling_ball-1.0.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numpy_rolling_ball-1.0.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file numpy_rolling_ball-1.0.1.tar.gz.

File metadata

  • Download URL: numpy_rolling_ball-1.0.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for numpy_rolling_ball-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e61adb628defb856634483e602d2166bb8a3b96909e37965a9dae8895825d684
MD5 ffe0669ef33dced9ea44d21a593ead87
BLAKE2b-256 d9251de8cc61025d5a08859aff98cbd73db7cb4bd7efb4b0262431422e31e5b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for numpy_rolling_ball-1.0.1.tar.gz:

Publisher: python-publish.yml on alencina-faa/numpy-rolling-ball

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file numpy_rolling_ball-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for numpy_rolling_ball-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bde4affc3bced545081177f05f90bf8c338c0508a46a45d33317de110c92a81a
MD5 35a63609f3a7e7ebf2c9c278fd937898
BLAKE2b-256 262b95ca785b67f36bd82f5b7da66ddc3f04e0362c70b221ad1c8efcd1a8e38a

See more details on using hashes here.

Provenance

The following attestation bundles were made for numpy_rolling_ball-1.0.1-py3-none-any.whl:

Publisher: python-publish.yml on alencina-faa/numpy-rolling-ball

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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