pyfli.io.hotpixel#

Hot-pixel masks for gated/SPAD cameras: generate a mask from a dark or background acquisition, save/load it as an image, and replace flagged pixels by the median of their non-hot neighbours.

Functions

generate_hotpixel_mask(data[, fraction, ...])

Boolean hot-pixel mask (H, W) from a dark/background acquisition (image, cube or stack, summed to per-pixel counts).

hotpixel_counts(data)

Per-pixel total counts (H, W) of an image, an (H, W, T) cube or an (N, H, W, T) stack.

load_hotpixel_mask(path[, shape])

Boolean mask from an image (PNG/JPEG/TIFF; first channel of a colour image, nonzero = hot).

remove_hotpixels(data, mask[, max_radius])

Replace every flagged pixel of an (H, W) image or (H, W, T) cube by the median of its non-hot neighbours in the 3x3 window (per time gate), widening the window up to max_radius when all neighbours are hot; a pixel with no valid neighbour keeps its value.

save_hotpixel_mask(mask, path)

Write a boolean mask as a grayscale image (hot = white), readable by load_hotpixel_mask().

hotpixel_counts(data)[source]#

Per-pixel total counts (H, W) of an image, an (H, W, T) cube or an (N, H, W, T) stack.

Parameters:

data (Any)

Return type:

ndarray

generate_hotpixel_mask(data, fraction=0.05, threshold_sigma=None, save_path=None)[source]#

Boolean hot-pixel mask (H, W) from a dark/background acquisition (image, cube or stack, summed to per-pixel counts).

With threshold_sigma a pixel is hot when its counts exceed median + threshold_sigma * 1.4826 * MAD (as DataIOUtils.hot_pixels()); otherwise the round(fraction * n_pixels) pixels with the most counts are flagged (fraction=0.05 gives a “5 per 100” mask). Ties at the cut are broken by pixel order, so the count is exact. save_path writes the mask as an image (save_hotpixel_mask()).

Parameters:
  • data (Any)

  • fraction (float | None)

  • threshold_sigma (float | None)

  • save_path (str | None)

Return type:

ndarray

save_hotpixel_mask(mask, path)[source]#

Write a boolean mask as a grayscale image (hot = white), readable by load_hotpixel_mask().

Parameters:
Return type:

None

load_hotpixel_mask(path, shape=None)[source]#

Boolean mask from an image (PNG/JPEG/TIFF; first channel of a colour image, nonzero = hot). With shape (H, W) a transposed mask is turned to match, otherwise a mismatch raises.

Parameters:
Return type:

ndarray

remove_hotpixels(data, mask, max_radius=2)[source]#

Replace every flagged pixel of an (H, W) image or (H, W, T) cube by the median of its non-hot neighbours in the 3x3 window (per time gate), widening the window up to max_radius when all neighbours are hot; a pixel with no valid neighbour keeps its value. Uses only unflagged pixels, so the result does not depend on processing order. Returns float32.

Parameters:
Return type:

ndarray