Video preprocessor

This module contains functions for pre-processing video data.

class mio.process.video.BaseVideoProcessor(name: str, output_dir: Path)

Base class for defining an abstract video processor.

Attributes: name (str): The name of the video processor. output_frames (list): A list of output frames. named_frame (NamedFrame): A NamedFrame object.

append_output_frame(input_frame: ndarray) None

Append a frame to the output_frames list.

Parameters: frame (np.ndarray): The frame to append.

batch_export_videos() None

Batch export the videos to a file. This method should be overridden in the subclass.

export_output_video() None

Export the video to a file.

property output_named_video: NamedVideo

Get the output NamedFrame object.

Returns: NamedVideo: The output NamedVideo object.

process_frame() None

Process a single frame. This method should be implemented in the subclass.

Parameters: frame (np.ndarray): The frame to process.

class mio.process.video.ButterworthProcessor(name: str, butter_config: ButterworthFilterConfig, output_dir: Path)

Processor for applying a Butterworth filter to video frames.

This class applies a Butterworth filter to each frame in the video, using the specified Butterworth filter configuration.

apply_filter() ndarray

Apply the Butterworth filter to the collected intensity data.

apply_filter_to_frames(filtered_data: ndarray) list[ndarray]

Apply the filtered intensity values to scale the frames.

batch_export_videos() None

Export the filtered data and plot if enabled.

butter_lowpass_filter(data: ndarray, cutoff: float, fs: float, order: int) ndarray

Apply a Butterworth lowpass filter to the data.

plot_filtered_data(filtered_data: ndarray) None

Plot the original and filtered intensity data.

process_frame(input_frame: ndarray) ndarray

Process a single frame using Butterworth filter.

class mio.process.video.FreqencyMaskProcessor(name: str, freq_mask_config: FreqencyMaskingConfig, width: int, height: int, output_dir: Path)

A class to apply frequency masking to a video.

batch_export_videos() None

Batch export the videos to a file. Whether to export or not is controlled in each method.

export_freq_domain_frames() None

Export the frequency domain to a file.

export_freq_mask() None

Export the frequency mask to a file.

property freq_domain_named_video: NamedVideo

Get the NamedFrame object for the frequency domain.

property freq_mask: ndarray

Get the frequency mask.

property freq_mask_named_frame: NamedFrame

Get the NamedFrame object for the frequency mask.

process_frame(input_frame: ndarray) ndarray | None

Process a single frame.

Parameters: frame (np.ndarray): The frame to process.

Returns: Optional[np.ndarray]: The processed frame. If the input is none, a None is returned.

class mio.process.video.MinProjSubtractProcessor(name: str, minimum_projection_config: MinimumProjectionConfig, output_dir: Path, video_frames: list[ndarray])

A class to apply minimum projection to a video.

batch_export_videos() None

Batch export the videos to a file. Whether to export or not is controlled in each method.

export_minimum_projection() None

Export the minimum projection to a file.

property min_proj_named_frame: NamedFrame

Get the NamedFrame object for the minimum projection.

normalize_stack() None

Normalize the stack of images.

class mio.process.video.NoisePatchProcessor(name: str, noise_patch_config: NoisePatchConfig, output_dir: Path)

A class to apply noise patching to a video.

batch_export_videos() None

Batch export the videos to a file. Whether to export or not is controlled in each method.

property diff_frames_named_video: NamedVideo

Get the NamedFrame object for the difference frames.

export_diff_frames() None

Export the difference frames to a file.

export_noise_patch() None

Export the noise patch to a file.

export_noisy_video() None

Export the noisy frames to a file.

property noise_patch_named_video: NamedVideo

Get the NamedFrame object for the noise patch.

property noisy_frames_named_video: NamedVideo

Get the NamedFrame object for the noisy frames.

process_frame(input_frame: ndarray) ndarray | None

Process a single frame.

Parameters: raw_frame (np.ndarray): The raw frame to process.

Returns: Optional[np.ndarray]: The processed frame. If the frame is noisy, a None is returned.

class mio.process.video.PassThroughProcessor(name: str, output_dir: Path)

A class to pass through a video.

batch_export_videos() None

Batch export the videos to a file. Whether to export or not is controlled in each method.

property pass_through_named_video: NamedVideo

Get the NamedFrame object for the pass through.

process_frame(input_frame: ndarray) ndarray

Process a single frame.

Parameters: frame (np.ndarray): The frame to process.

Returns: np.ndarray: The processed frame.

mio.process.video.denoise_run(video_path: str, config: DenoiseConfig) None

Preprocess a video file and display the results.

Parameters: video_path (str): The path to the video file. config (DenoiseConfig): The denoise configuration.

mio.process.video.log_processing_metadata(output_dir: Path, video_path: str, config: DenoiseConfig, pathstem: str) None

Log processing metadata to a JSON file.