Cross-platform Python reader for Vision Research Phantom .cine files
Project description
cine-handler
cine-handler is the PyPI distribution for the cine_reader Python package,
which reads Vision Research Phantom .cine files on macOS, Linux, and
Windows.
The PyPI distribution contains only the Python package. The repository also includes a separate MATLAB implementation that stays in GitHub:
- Repository: https://github.com/rverleur/cine-reader
- MATLAB implementation: https://github.com/rverleur/cine-reader/tree/main/Matlab
- Python examples: https://github.com/rverleur/cine-reader/tree/main/python/examples
- Python API notes: https://github.com/rverleur/cine-reader/blob/main/python/API.md
Installation
Install from PyPI:
pip install cine-handler
Development install from GitHub:
pip install "git+https://github.com/rverleur/cine-reader.git"
Editable install from a local checkout:
pip install -e .[dev]
What The Package Provides
- High-level
Cinereader for file metadata, frame access, frame iteration, trimming, and simple processing. - Packed 10-bit decode with bundled native helpers and a NumPy fallback.
- Dead-pixel repair helpers for mono, Bayer/CFA, and RGB image arrays.
- Bilinear Bayer demosaic for raw color sensor frames.
- Low-memory frame statistics helpers for averaging and robust background estimation.
Quick Start
from pathlib import Path
from cine_reader import Cine
cine_path = Path("my_capture.cine")
with Cine(cine_path) as cine:
print("frames:", cine.total_frames)
print("range:", cine.first_frame_number, cine.last_frame_number)
print("frame rate:", cine.frame_rate)
print("exposure (s):", cine.exposure_time_seconds)
cine.load_frame(cine.first_frame_number)
raw_frame = cine.frame
rgb_frame = cine.get_frame_rgb()
average = cine.average_frames(cine.first_frame_number, cine.first_frame_number + 9)
background = cine.mode_frames(cine.first_frame_number, cine.first_frame_number + 19)
Frame And Color Behavior
- Mono cines load as 2D arrays.
- Raw color CFA/Bayer cines load as 2D sensor mosaics by default.
- Interpolated 24-bit and 48-bit color payloads load as 3-channel arrays.
- Set
debayer=TrueonCine(...)or calldebayer_frame()to convert raw CFA frames to RGB. - Set
remove_dead_pixels=TrueonCine(...)or callreplace_dead_pixels()to repair dead pixels. red_pixels,green_pixels, andblue_pixelsexpose raw CFA sensor samples for Bayer frames, usingNaNat non-matching locations.
The Cine Class
Constructor
Cine(
filename,
keep_annotations=True,
remove_dead_pixels=False,
debayer=False,
dead_value=None,
dead_is_threshold=True,
bayer_pattern="auto",
)
filename: path to a.cinefile.keep_annotations: keep annotation block bytes inannotation_dataandannotation.remove_dead_pixels: repair dead pixels on eachload_frame.debayer: debayer raw CFA/Bayer frames on eachload_frame.dead_value: optional dead-pixel marker or threshold. If omitted, the value is inferred from camera metadata.dead_is_threshold: whenTrue, values greater than or equal todead_valueare treated as dead pixels.bayer_pattern:"auto","RGGB","BGGR","GRBG", or"GBRG".
Reader Lifecycle
open_cine_file(filename): reopen a.cinefile and parse the top-level metadata blocks.close_file(): close the active file handle.- Context manager support:
with Cine(path) as cine: ...
Metadata And Aliases
These properties are the most useful entry points for file metadata:
first_frame_numbertotal_frameslast_frame_numberframe_rateexposure_time_nsexposure_time_secondsexposure_timerecording_datetimerecording_datecfa_codebayer_pattern
The specification-aligned metadata objects are also available directly:
file_headerasCineHeaderimage_headerasBitmapHeadercamera_setupasSetupimage_locationsasImageOffsets
Frame Access
load_frame(image_no, convert_bgr_to_rgb=False)- Loads a single frame by global frame number.
convert_bgr_to_rgb=Trueconverts 3-channel payloads to RGB on load.
next_frame(increment=1, convert_bgr_to_rgb=False)- Loads the next frame relative to
current_frame. - Negative increments are allowed.
- Loads the next frame relative to
frameandimage- Aliases for the currently loaded NumPy array.
get_frame_rgb(image_no=None, bayer_pattern="auto")- Returns the current frame, or a selected frame, as RGB.
- Raw CFA/Bayer frames are demosaiced first.
Example:
with Cine("capture.cine") as cine:
cine.load_frame(cine.first_frame_number)
raw = cine.frame
rgb = cine.get_frame_rgb()
Pixel Repair And Demosaic
replace_dead_pixels(dead_value=None, dead_is_threshold=True)- Repairs dead pixels on the current frame.
- Works for mono, raw Bayer/CFA, and RGB data.
debayer_frame(bayer_pattern="auto")- Converts the current raw CFA/Bayer frame to RGB in place.
Example:
with Cine("capture.cine") as cine:
cine.load_frame(cine.first_frame_number)
cine.replace_dead_pixels()
cine.debayer_frame()
rgb = cine.frame
Multi-Frame Operations
average_frames(start_frame, end_frame, replace_dead_pixels=False, chunk_size=8)- Computes a per-pixel average over an inclusive frame range.
mode_frames(start_frame, end_frame, replace_dead_pixels=False, method="auto", q_bg=0.80, k_sigma=2.5, min_keep=3, max_keep=96, stack_limit=128)- Computes a robust bright-background estimate.
method="mad"uses a full-stack quantile/MAD estimator.method="topk"uses a bounded-memory top-k estimator.method="auto"chooses between them from the range length.
load_frames_batch(start_frame, count)- Loads consecutive frames into one stacked array.
- Output shape is
[H, W, N]for mono/raw CFA and[H, W, 3, N]for color.
save_frames_to_new_file(output_filename, start_frame, end_frame)- Writes a trimmed
.cinefile for an inclusive frame range.
- Writes a trimmed
Example:
with Cine("capture.cine") as cine:
first = cine.first_frame_number
last = min(first + 49, cine.last_frame_number)
avg = cine.average_frames(first, last, chunk_size=8)
bg = cine.mode_frames(first, last, method="topk")
batch = cine.load_frames_batch(first, 5)
cine.save_frames_to_new_file("trimmed.cine", first, last)
Standalone Helper Functions
Packed 10-bit Decode
unpack_10bit_data(data)- Decodes Phantom packed 10-bit payloads.
- Uses a bundled native unpack helper when one is available.
- Falls back to NumPy automatically.
unpack_10bit_numpy(data)- Pure-NumPy packed 10-bit decoder.
To force the NumPy path:
export CINE_READER_DISABLE_C_UNPACK=1
Dead-Pixel Repair
replace_dead_pixels(frame, dead_value=4095, dead_is_threshold=False, bayer_raw=False)- Dispatches to the right repair strategy for mono, Bayer, or RGB input.
replace_dead_pixels_mono(frame, dead_value=4095, dead_is_threshold=False)- Repairs dead pixels in a 2D mono frame from valid 8-neighbor values.
replace_dead_pixels_bayer(frame, dead_value=4095, dead_is_threshold=False)- Repairs a 2D raw Bayer/CFA frame phase-by-phase before demosaic.
replace_dead_pixels_rgb(frame, dead_value=4095, dead_is_threshold=False)- Repairs each color channel independently in a 3D image.
Example:
from cine_reader import replace_dead_pixels_bayer
clean = replace_dead_pixels_bayer(raw_bayer_frame, dead_value=4095)
Demosaic
demosaic_bilinear(frame, pattern="RGGB")- Bilinear Bayer demosaic for raw CFA frames.
- Supported patterns are
"RGGB","BGGR","GRBG", and"GBRG".
Example:
from cine_reader import demosaic_bilinear
rgb = demosaic_bilinear(raw_bayer_frame, pattern="RGGB")
Frame Statistics
average_from_frame_iter(frames, out_dtype=None, chunk_size=8)- Computes a per-pixel mean from an iterable of equally shaped frames.
- Returns
(average_frame, frame_count).
robust_background_mad_stack(frames, q_bg=0.80, k_sigma=2.5, min_keep=3, out_dtype=np.uint16)- Full-stack bright-background estimator based on quantile and MAD rejection.
robust_background_topk(frames, frame_count, q_bg=0.80, min_keep=3, max_keep=96, out_dtype=np.uint16)- Bounded-memory bright-background estimator that keeps the top-k samples per pixel.
Example:
from cine_reader import average_from_frame_iter, robust_background_topk
avg, count = average_from_frame_iter(frames, chunk_size=16)
bg = robust_background_topk(frames, frame_count=count, q_bg=0.80)
Metadata Classes
These classes are returned by the reader for direct access to CINE metadata:
CineHeader- File header fields such as
FirstImageNo,ImageCount, andOffImageOffsets.
- File header fields such as
BitmapHeader- Image header fields such as
biWidth,biHeight, andbiBitCount.
- Image header fields such as
ImageOffsets- Frame byte-offset table as
pImage.
- Frame byte-offset table as
Setup- Camera setup metadata including frame rate, exposure, bit depth, color flags, and descriptive strings.
Example:
with Cine("capture.cine") as cine:
print(cine.file_header.FirstImageNo)
print(cine.image_header.biWidth, cine.image_header.biHeight)
print(cine.camera_setup.FrameRate, cine.camera_setup.RealBPP)
Included Native Helpers
The wheel ships with runtime unpack libraries for packed 10-bit payloads:
unpack_data_win32.dllunpack_data_win64.dllunpack_data_elf64.sounpack_data_arm64.dylib
If no matching helper can be loaded, cine-handler falls back to the NumPy
decoder automatically.
MATLAB Implementation
The PyPI package is intentionally Python-only. If you also need the MATLAB reader, use the same GitHub repository:
- MATLAB package entry point: https://github.com/rverleur/cine-reader/blob/main/Matlab/Cine.m
- MATLAB setup and examples: https://github.com/rverleur/cine-reader/blob/main/Matlab/README.md
More Examples
- Basic usage: https://github.com/rverleur/cine-reader/blob/main/python/examples/basic_usage.py
- Trimming and background estimation: https://github.com/rverleur/cine-reader/blob/main/python/examples/trim_and_background.py
- Performance test: https://github.com/rverleur/cine-reader/blob/main/python/examples/performance_test.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cine_handler-0.1.1.tar.gz.
File metadata
- Download URL: cine_handler-0.1.1.tar.gz
- Upload date:
- Size: 144.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d35802d7a463103e7191ab1d0a751e43478bcdd57e712ee3e4bcd7d4a0e076f2
|
|
| MD5 |
d65781fb36936758b9e5ca39abcb5a7d
|
|
| BLAKE2b-256 |
d713b33a876723f79bfbb4ccfece010b7df570baba109e4dd22757647cade094
|
Provenance
The following attestation bundles were made for cine_handler-0.1.1.tar.gz:
Publisher:
publish-python-package.yml on rverleur/cine-reader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cine_handler-0.1.1.tar.gz -
Subject digest:
d35802d7a463103e7191ab1d0a751e43478bcdd57e712ee3e4bcd7d4a0e076f2 - Sigstore transparency entry: 1320285983
- Sigstore integration time:
-
Permalink:
rverleur/cine-reader@dfea86e845374846448c1ca0a2cb963bd123882e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/rverleur
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python-package.yml@dfea86e845374846448c1ca0a2cb963bd123882e -
Trigger Event:
release
-
Statement type:
File details
Details for the file cine_handler-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cine_handler-0.1.1-py3-none-any.whl
- Upload date:
- Size: 139.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
680c6d5bd1bf897c2bcef1ae241e4dd2716c68d4e02aed6181e9a70fe718ee0b
|
|
| MD5 |
fb741cbc931b63079f97d6df799819f4
|
|
| BLAKE2b-256 |
5f13181981de0c39ef892f5320efac910238d94c95dd2c659edfe13cbec9c6bc
|
Provenance
The following attestation bundles were made for cine_handler-0.1.1-py3-none-any.whl:
Publisher:
publish-python-package.yml on rverleur/cine-reader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cine_handler-0.1.1-py3-none-any.whl -
Subject digest:
680c6d5bd1bf897c2bcef1ae241e4dd2716c68d4e02aed6181e9a70fe718ee0b - Sigstore transparency entry: 1320286087
- Sigstore integration time:
-
Permalink:
rverleur/cine-reader@dfea86e845374846448c1ca0a2cb963bd123882e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/rverleur
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python-package.yml@dfea86e845374846448c1ca0a2cb963bd123882e -
Trigger Event:
release
-
Statement type: