Background
Phase contrast microscopy background generation.
This module provides functions to generate realistic synthetic backgrounds that mimic the appearance of phase contrast microscopy images.
- create_base_background(shape: Tuple[int, int], noise_scale: int = 20, base_brightness: float = 0.6, gradient_strength: float = 0.05, perlin_scale: int = 4, seed: int = None) ndarray
Create a base background with subtle gradients mimicking illumination variations.
- Parameters:
shape (Tuple[int, int]) – Shape of the background image (height, width).
noise_scale (int) – Factor controlling illumination variation scale.
base_brightness (float) – Base brightness level (0.0 to 1.0).
gradient_strength (float) – Strength of illumination gradients (0.0 to 1.0).
perlin_scale (int) – Number of octaves for Perlin-like noise.
seed (int) – Random seed for reproducibility. If None, uses random state.
- Returns:
Base background image with values between 0 and 1.
- Return type:
np.ndarray
- add_darker_spots(background: ndarray, num_spots_range: Tuple[int, int] = (0, 50), spot_intensity: float = 0.15, spot_size_range: Tuple[float, float] = (2.0, 8.0), seed: int = None) ndarray
Add randomly distributed darker spots to simulate debris or artifacts.
- Parameters:
background (np.ndarray) – Input background image.
num_spots_range (Tuple[int, int]) – Range for number of dark spots (min, max). When min == max, exactly that number of spots is created.
spot_intensity (float) – Intensity of dark spots (how much darker than background, 0.0 to 1.0).
spot_size_range (Tuple[float, float]) – Range of spot sizes (sigma values for Gaussian blobs).
seed (int) – Random seed for reproducibility. If None, uses random state.
- Returns:
Background with added dark spots.
- Return type:
np.ndarray
- add_lighter_spots(background: ndarray, num_spots_range: Tuple[int, int] = (0, 30), spot_intensity: float = 0.12, spot_size_range: Tuple[float, float] = (3.0, 12.0), seed: int = None) ndarray
Add randomly distributed lighter spots to simulate phase artifacts or bright debris.
- Parameters:
background (np.ndarray) – Input background image.
num_spots_range (Tuple[int, int]) – Range for number of light spots (min, max). When min == max, exactly that number of spots is created.
spot_intensity (float) – Intensity of light spots (how much brighter than background, 0.0 to 1.0).
spot_size_range (Tuple[float, float]) – Range of spot sizes (sigma values for Gaussian blobs).
seed (int) – Random seed for reproducibility. If None, uses random state.
- Returns:
Background with added light spots.
- Return type:
np.ndarray
- add_fine_texture(background: ndarray, texture_strength: float = 0.02, texture_scale: float = 1.5, seed: int = None) ndarray
Add fine texture to simulate microscopic surface variations and optical artifacts.
- Parameters:
background (np.ndarray) – Input background image.
texture_strength (float) – Strength of the texture (0.0 to 1.0).
texture_scale (float) – Smoothness of texture (higher = smoother).
seed (int) – Random seed for reproducibility. If None, uses random state.
- Returns:
Background with added fine texture.
- Return type:
np.ndarray
- add_gaussian_blur(background: ndarray, sigma: float = 1.0) ndarray
Apply Gaussian blur to the background.
- Parameters:
background (np.ndarray) – Input background image.
sigma (float) – Standard deviation for Gaussian kernel.
- Returns:
Blurred background image.
- Return type:
np.ndarray
- generate_phase_contrast_background(shape: Tuple[int, int] = (512, 512), noise_scale: int = 20, base_brightness: float = 0.6, gradient_strength: float = 0.05, perlin_scale: int = 4, num_dark_spots_range: Tuple[int, int] = (0, 50), dark_spot_intensity: float = 0.15, dark_spot_size_range: Tuple[float, float] = (2.0, 8.0), num_light_spots_range: Tuple[int, int] = (0, 30), light_spot_intensity: float = 0.12, light_spot_size_range: Tuple[float, float] = (3.0, 12.0), texture_strength: float = 0.02, texture_scale: float = 1.5, blur_sigma: float = 3.0, seed: int = None, return_uint8: bool = True) ndarray
Generate a complete phase contrast microscopy background with all features.
This is the main method that combines all steps to create a realistic phase contrast microscope background.
- Parameters:
shape (Tuple[int, int]) – Shape of the background image (height, width).
noise_scale (int) – Factor controlling illumination variation scale.
base_brightness (float) – Base brightness level (0.0=black to 1.0=white).
gradient_strength (float) – Strength of illumination gradients (0.0 to 1.0).
perlin_scale (int) – Number of octaves for Perlin-like noise.
num_dark_spots_range (Tuple[int, int]) – Range for number of dark spots (min, max). When min == max, exactly that number of spots is created.
dark_spot_intensity (float) – How much darker the dark spots are (0.0 to 1.0).
dark_spot_size_range (Tuple[float, float]) – Size range for dark spots.
num_light_spots_range (Tuple[int, int]) – Range for number of light spots (min, max). When min == max, exactly that number of spots is created.
light_spot_intensity (float) – How much brighter the light spots are (0.0 to 1.0).
light_spot_size_range (Tuple[float, float]) – Size range for light spots.
texture_strength (float) – Strength of fine texture (0.0 to 1.0).
texture_scale (float) – Smoothness of texture (higher = smoother).
blur_sigma (float) – Standard deviation for Gaussian blur to simulate optical effects.
seed (int) – Random seed for reproducibility. If None, uses random state.
return_uint8 (bool) – If True, return uint8 array (0-255), otherwise float (0.0-1.0).
- Returns:
Complete synthetic phase contrast background.
- Return type:
np.ndarray