Skip to main content

Numbers and brightness analysis for microscopic image analysis implemented in python.

Project description

Numbers-and-brightness

Numbers and brightness analysis for microscopic image analysis with automatic segmentation and interactive data visualisation implemented in python.

Functions as a Python package and Application.

Installation

Numbers and brightness is available on PyPi and can be installed as follows:

pip install numbers_and_brightness

Examples

Automatic batch processing

Interactive data inspection

Core calculations

All calculations are derived from Digman et al., 2008.

Here img represents a numpy array of shape (t, y, x).

Intensity

Intensity is calculated as:

$$\langle k \rangle = \frac{\sum_i k_i}{K}$$

In python:

average_intensity = np.mean(img, axis=0)

Variance

Variance is calculated as:

$$\sigma^2 = \frac{\sum_i (k_i - \langle k \rangle)^2}{K}$$

In python:

variance = np.var(img, axis=0)

Apparent brightness

Apparent brightness is calculated as:

$$B = \frac{\sigma^2}{\langle k \rangle}$$

In python:

apparent_brightness = variance / average_intensity

Apparent number

Apparent number is calculated as:

$$N = \frac{\langle k \rangle^2}{\sigma^2}$$

In python:

apparent_number = average_intensity**2 / variance

Brightness

Brightness is calculated as:

$$\varepsilon = \frac{\sigma^2 - \langle k \rangle}{\langle k \rangle - k_0}$$

In python:

brightness = (variance - average_intensity) / (average_intensity - background)

Number

Number is calculated as:

$$n = \frac{(\langle k \rangle - k_0)^2}{\sigma^2 - \langle k \rangle}$$

In python:

number = ((average_intensity-background)**2) / np.clip((variance - average_intensity), 1e-6, None)

Here the denominator is clipped (limited) to a value of 1e-6 to prevent extremely high number values.

Usage

Numbers and Brightness functionality

Graphical user interface

The package contains a GUI that can be accessed as follows:

Python

from numbers_and_brightness.gui import nb_gui
nb_gui()

Command line

C:\Users\User> numbers_and_brightness
C:\Users\User> python -m numbers_and_brightness.gui

Desktop shortcut

Additionally, a desktop (and start menu) shortcut can be created using the following command:

C:\Users\User> numbers_and_brightness --shortcut

Python package

Numbers and brightness can be used as follows:

from numbers_and_brightness.numbers_and_brightness import numbers_and_brightness_analysis
numbers_and_brightness_analysis(file = "./Images/image.tif")

Or in batch processing mode:

from numbers_and_brightness.numbers_and_brightness import numbers_and_brightness_batch
numbers_and_brightness_batch(folder = "./Images")

Command line

The package can also be accessed using the command line:

C:\Users\User> numbers_and_brightness --file "Images/image.tif"
C:\Users\User> numbers_and_brightness --folder "Images"

Parameters

The package contains the following parameters. These parameters can be altered by passing the parameter to the function, or to the cli as '--parameter'

  • background : int, default = 0
    • background noise in the signal. Will be included in the calculations as $k_0$ as described by Digman et al., 2008.
  • segment : bool, default = False
    • perform automatic segmentation of the cells using cellpose
    • cellpose will use a cuda device if available
  • diameter : int, default = 75
    • expected diameter of the cell, passed to cellpose model
  • flow_threshold : float, default = 0.4
    • flow threshold, passed to cellpose model
  • cellprob_threshold : float, default = 4
    • cellprob threshold, passed to cellpose model
  • analysis : bool, default = False
    • perform analysis by plotting intensity of cell against apparent brightness
  • erode : int, default = 2
    • erode the edges of the cell mask to ensure only pixels inside the cell are used for the analysis
  • bleach_corr : bool, default = False
    • perform bleaching correction on the input image before analysis
    • bleach correction is performed by fitting a linear formula to the intensity over time, which is then used to correct the intensity
  • use_existing_mask : bool, default = False
    • whether to use already present masks in an outputfolder when extracting numbers and brightness values
  • create_overviews : bool, default = False
    • whether to collect the apparent brightness/masks of all files in a folder in a specific folder

Examples:

C:\Users\User> numbers_and_brightness --folder "Images" --analysis true
from numbers_and_brightness.numbers_and_brightness import numbers_and_brightness_batch
numbers_and_brightness_batch(folder = "./Images", analysis = True)

Step-by-step guides

Process folder

Interactive data-inspection

Use custom segmentation for analysis

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

numbers_and_brightness-0.1.7.tar.gz (284.7 kB view details)

Uploaded Source

Built Distribution

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

numbers_and_brightness-0.1.7-py3-none-any.whl (330.9 kB view details)

Uploaded Python 3

File details

Details for the file numbers_and_brightness-0.1.7.tar.gz.

File metadata

  • Download URL: numbers_and_brightness-0.1.7.tar.gz
  • Upload date:
  • Size: 284.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for numbers_and_brightness-0.1.7.tar.gz
Algorithm Hash digest
SHA256 e8a047451fb2201e1b9599b89f09a58f606a0fb88beb393b3797aed9a8033444
MD5 83b32dc391184c9ff778a2b8db09082a
BLAKE2b-256 bd8b0881ccdd442b279af1e34c0f1ac8adb7b30d721bf23efd7848f2107d51b1

See more details on using hashes here.

File details

Details for the file numbers_and_brightness-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for numbers_and_brightness-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b843321cafdce21fef72ed67b578fcae4fa768098405abdd6a7db5b2e8048e1b
MD5 0952bf2ad39be9fecbdbcfaa593a693c
BLAKE2b-256 2a4a99f47a08df46a216a81df1f828d6961e46e8279e808973ad4020626b7d57

See more details on using hashes here.

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