Frame helpers

This module contains a helper class for frame operations.

class mio.process.frame_helper.BaseSingleFrameHelper

Base class for single frame operations.

abstractmethod find_invalid_area(frame: ndarray) Tuple[bool, ndarray]

Find the invalid area in a single frame.

Parameters:

frame (np.ndarray) – The frame to process.

Returns:

A boolean indicating if the frame is invalid and the processed frame.

Return type:

Tuple[bool, np.ndarray]

abstractmethod process_frame(frame: ndarray) ndarray

Process a single frame.

Parameters:

frame (np.ndarray) – The frame to process.

Returns:

The processed frame.

Return type:

np.ndarray

class mio.process.frame_helper.BlackAreaDetector(config: BlackAreaDetectorConfig)

Helper class for black area detection.

_detect_black_pixels(current_frame: ndarray) Tuple[bool, ndarray]

Detect black-out noise by checking for black pixels (value 0) over rows of pixels.

Returns:

A boolean indicating if the frame is corrupted and noise mask.

Return type:

Tuple[bool, np.ndarray]

find_invalid_area(frame: ndarray) Tuple[bool, ndarray]

Process a single frame and verify if it is valid.

Parameters:

frame (np.ndarray) – The frame to process.

Returns:

A boolean indicating if the frame is valid and the processed frame.

Return type:

Tuple[bool, np.ndarray]

class mio.process.frame_helper.FrameSplitter

Helper class for splitting frames into buffers. Currently only for getting the buffer shape from pixel count.

get_buffer_shape(frame_height: int, px_per_buffer: int) list[int]

Get the shape of each buffer in a frame.

Parameters:
  • frame_width (int) – The width of the frame.

  • frame_height (int) – The height of the frame.

  • px_per_buffer (int) – The number of pixels per buffer.

Returns:

The shape of each buffer in the frame.

Return type:

list[int]

class mio.process.frame_helper.FrequencyMaskHelper(height: int, width: int, freq_mask_config: FreqencyMaskingConfig)

Helper class for frequency masking operations.

_gen_freq_mask() ndarray

Generate a mask to filter out horizontal and vertical frequencies. A central circular region can be removed to allow low frequencies to pass.

freq_domain(img: ndarray) ndarray

Compute the frequency spectrum of an image.

Parameters:

img (np.ndarray) – The image to process.

Returns:

The frequency spectrum of the image.

Return type:

np.ndarray

property freq_mask: ndarray

Get the frequency mask.

Returns:

The frequency mask.

Return type:

np.ndarray

process_frame(img: ndarray) ndarray

Perform FFT/IFFT to remove horizontal stripes from a single frame.

Parameters:
  • img (np.ndarray) – The image to process.

  • cast_f32 (bool) – Cast the image to float32 before processing.

Returns:

The filtered image

Return type:

np.ndarray

Todo

Confirm if the option for casting to float32 is necessary. See issue #104.

class mio.process.frame_helper.GradientNoiseDetector(config: GradientDetectorConfig)

Helper class for gradient noise detection.

_detect_with_gradient(current_frame: ndarray) Tuple[bool, ndarray]

Detect noise using local contrast (second derivative) in the x-dimension (along rows, across columns)

Returns:

A boolean indicating if the frame is noisy and the noise mask.

Return type:

Tuple[bool, np.ndarray]

find_invalid_area(frame: ndarray) Tuple[bool, ndarray]

Process a single frame and verify if it is valid.

Parameters:

frame (np.ndarray) – The frame to process.

Returns:

A boolean indicating if the frame is valid and the processed frame.

Return type:

Tuple[bool, np.ndarray]

class mio.process.frame_helper.InvalidFrameDetector(noise_patch_config: NoisePatchConfig)

Helper class for combined invalid frame detection.

find_invalid_area(frame: ndarray) Tuple[bool, ndarray]

Process a single frame and verify if it is valid.

Parameters:

frame (np.ndarray) – The frame to process.

Returns:

A boolean indicating invalid frames and the invalid area.

Return type:

Tuple[bool, np.ndarray]

class mio.process.frame_helper.MSENoiseDetector(config: MSEDetectorConfig)

Helper class for mean squared error noise detection.

_detect_with_mean_error(current_frame: ndarray) Tuple[bool, ndarray]

Detect noise using mean error between current and previous frames.

Returns:

A boolean indicating if the frame is noisy and the noise mask.

Return type:

Tuple[bool, np.ndarray]

find_invalid_area(frame: ndarray) Tuple[bool, ndarray]

Process a single frame and verify if it is valid.

Parameters:

frame (np.ndarray) – The frame to process.

Returns:

A boolean indicating if the frame is valid and the processed frame.

Return type:

Tuple[bool, np.ndarray]

register_previous_frame(previous_frame: ndarray) None

Register the previous frame for mean error calculation.

Parameters:

previous_frame (np.ndarray) – The previous frame to compare against.

mio.process.frame_helper.mean_intensity(frame: ndarray) float

Calculate the mean pixel intensity for a frame.

Parameters:

frame (np.ndarray) – The frame whose mean intensity is to be calculated on filtered data (broken frames replaced, spatial mask filter).

Returns:

The mean intensity of the frame.

Return type:

float