1. cine

This module is used to read Phatom CINE files.

1.1. Overview

Cine(fn) Class for reading Vision Research CINE files, e.g.

1.2. Example Usage

#!/usr/bin/env python
from ilpm import cine

#Load the cine
c = cine.Cine('/Volumes/labshared2/dustin/2013_10_09_smoke_rings/2103_10_09_snoke_ring_close_III.cine')


#Print some basic info
print 'Total frames:', len(c)
print 'Bit depth:', c.real_bpp
print 'Frame size: %dx%d' % (c.width, c.height)
print 'Frame rate:', c.frame_rate


#Load a frame
frame_num = len(c)//3
t = c.get_time(frame_num)

#Get the raw frame data
raw = c[frame_num]
#If the raw image has more than 8 bytes of data we need to fix this so we can
#  save as a regular image!
if c.real_bpp > 8:
    raw = (raw>>(c.real_bpp - 8)).astype('u1')

#Get a gamma correceted frame - this should appear more natural when saved as
#  a regular image.
gamma_corrected = c.gamma_corrected_frame(frame_num)


#Convert to Python Image Library objects to save as a PNG
import Image
Image.fromarray(raw).save('cine-test-raw.png')
Image.fromarray(gamma_corrected).save('cine-test-gamma_corrected.png')


#Plot some images with pylab.
import pylab as P

P.subplot(211)
P.title('Raw Data (t=%d ms)' % (t*1E3))
P.imshow(raw, cmap='gray')

P.subplot(212)
P.title('Gamma Corrected (t=%d ms)' % (t*1E3))
P.imshow(gamma_corrected, cmap='gray')

P.show()

1.3. Cine Class

class ilpm.cine.Cine(fn)[source]

Bases: object

Class for reading Vision Research CINE files, e.g. from Phantom cameras.

Supports indexing, so frame can be accessed like list items, and len returns the number of frames. Iteration is also supported.

Cine objects also use locks for file reading, allowing cine objects to be shared safely by several threads.

filename : string
Source filename

Attributes

hash
trigger_time_p Returns the time of the trigger, tuple of (datatime_object, fraction_in_ns)

Methods

close() Closes the cine file.
gamma_corrected_frame(frame_number[, ...]) Return a frame as a gamma corrected ‘u1’ array, suitable for saving to a standard image.
get_fps() Get the frames per second of the movie.
get_frame(frame_number) Get a frame from the cine file.
get_time(frame_number) Get the time of a specific frame.
len()
next()
read_header(fields[, offset])
read_tagged_blocks()
unpack(fs[, offset])
gamma_corrected_frame(frame_number, bottom_clip=0, top_clip=None, gamma=2.2)[source]

Return a frame as a gamma corrected ‘u1’ array, suitable for saving to a standard image.

Output is equal to: 255 * ((original - bottom_clip) / (top_clip - bottom_clip))*(1/gamma)

Parameters:

frame_number : integer

gamma : float (default: 2.2)

The gamma correction to apply

top_clip : integer (default: 0)

bottom_clip : integer (default: 2**real_bpp)

Returns:

frame : numpy array (dtype=’u1’)

get_frame(frame_number)[source]

Get a frame from the cine file.

Parameters:frame_number : integer
Returns:frame : numpy array (dtype=’u1’ or ‘u2’, depending on bit depth)
get_time(frame_number)[source]

Get the time of a specific frame.

Parameters:

frame_number : integer

Returns:

time : float

Time from start in seconds.

get_fps()[source]

Get the frames per second of the movie.

Returns:fps : int
close()[source]

Closes the cine file.

trigger_time_p

Returns the time of the trigger, tuple of (datatime_object, fraction_in_ns)