Reads an SER file and extracts its metadata, frames, and optional timestamps.
- Parameters:
input_path(str): Path to the.serfile to be read.
- Returns:
metadata(dict): Contains metadata such as image dimensions, pixel depth, frame count, observer, and instrument details.frames(list of NumPy arrays): A list of 2D arrays representing individual frames in the.serfile.timestamps(list of int or None): A list of timestamps corresponding to each frame, orNoneif no timestamps are available.
- Usage:
metadata, frames, timestamps = read_ser("example.ser")
Writes an SER file using the provided metadata, frames, and optional timestamps.
- Parameters:
output_path(str): Path where the.serfile will be saved.metadata(dict): Metadata describing the.serfile, including dimensions, pixel depth, and more.frames(list of NumPy arrays): A list of 2D arrays representing the frames to be saved.timestamps(list of int, optional): Optional timestamps for each frame.
- Returns:
- None
- Usage:
write_ser("output.ser", metadata, frames, timestamps)
Saves a single frame as a PNG image with optional RGB channel alignment.
- Parameters:
frame(np.ndarray): A 2D Bayer-encoded or grayscale image frame.output_path(str): Path where the PNG file will be saved.color_id(int): The SER color identifier describing the Bayer pattern.align_rgb(bool, optional): Align Red and Blue channels to Green. Defaults toTrue.
- Returns:
- None
- Usage:
save_frame_as_png(frame, "frame_output.png", color_id=8, align_rgb=False)
Converts an SER timestamp (8-byte integer) into a readable date-time string.
- Parameters:
timestamp(int): An SER timestamp, representing 100-nanosecond intervals since midnight, January 1, 0001.
- Returns:
str: A readable date-time string in ISO 8601 format.
- Usage:
readable_time = ser_timestamp_to_datetime(637738597820000000)
These functions work together to:
- Read
.serfiles. - Extract and manipulate frames and metadata.
- Save frames as PNG images.
- Convert timestamps to human-readable formats.
- Write
.serfiles with the desired frames, metadata, and timestamps.
See examples/extract_frames_example.py for a walkthrough of selecting a
subset of frames from an existing SER file and saving them to a new file.
-
Install the project dependencies:
pip install -r requirements.txt
Using
opencv-python-headlessinstead ofopencv-pythonavoids needing system libraries such aslibGL1:pip install opencv-python-headless
-
Run the tests with pytest:
pytest