core.frame
Container for a single image or frame of video. |
|
Store "data about the data" in a |
- class Frame(**kwds)[source]
Bases:
objectContainer for a single image or frame of video.
This is a fairly free-form container (to which you can add other data), but every
Frameobject must have:a frame number
a data item
a type description string, such as “RGB”
a
Metadataitem
The data item can be a
numpy.ndarrayorPIL.Imageobject. In most instances anumpy.ndarrayshould have 3 dimensions: line, pixel, colour component.- initialise(other)[source]
Initialise a
Framefrom anotherFrame.Copies the metadata and (a reference to) the data from
other. Note that the data is not actually copied – you must make a copy of the data before changing it.- Parameters:
other (Frame) – The frame to copy.
- set_audit(*args, **kwds)[source]
See
Metadata.set_audit.
- merge_audit(*args, **kwds)[source]
See
Metadata.merge_audit.
- as_numpy(dtype=None, copy=False)[source]
Get image data in
numpy.ndarrayform.Note that if the image data is already in the correct format this can be a null operation.
When converting to limited range types (
numpy.uint8,numpy.uint16) the data is clipped (limited) to the range.- Parameters:
dtype (numpy.dtype) – What
dtypethe data should be in, e.g.numpy.float32. IfdtypeisNonethen no conversion will be done.copy (bool) – Forces a copy of the data to be made, even if it is already an
numpy.ndarraywith the requested dtype.
- Returns:
The image data as
numpy.ndarray.- Return type:
- class Metadata(**kwds)[source]
Bases:
objectStore “data about the data” in a
Frame.This container stores information about an image or video sequence that is not the actual image data. The main use of this is the “audit trail”. Each Pyctools component extends the audit trail with a short description of what it does, creating a detailed record of the processing. This can be useful in working out what went wrong (or right!) in some cases.
Many image file formats (such as JPEG) allow storage of metadata within the image file, but in Pyctools the metadata is always stored in a separate “sidecar” file. This allows the use of any image/video file format and, because the metadata is stored in XMP text format, the sidecar can be read with any text editor.
“Raw” video files, often used to store YUV, have their image dimensions and “fourcc” format stored in a metadata file. The
pyctools-setmetadatatool can be used to create or modify the metadata file if this information is missing.- set_audit(component, text, with_history=True, with_date=False, with_config=None)[source]
Set audit trail.
This is a convenient way to add to the audit trail in a “standard” format. The component’s module and class names are added to the audit trail to record which component did the processing. The text should describe what was done and finish with a newline, e.g.
data = FFT(data)\n. Using the worddatato describe single input or output data keeps the audit trail consistent. If you are combining two or more inputs you can “rename” each one with themerge_auditmethod.- Parameters:
component (Component) – The component that’s processing the frame.
text (str) – Text to be added to the audit trail.
with_history (bool) – Whether to include the previous audit trail.
with_date (bool) – Whether to include the current date & time in the audit trail. This is primarily used when writing files.
with_config (ConfigParent) – Whether to add the component’s configuration options with
config.ConfigParent.audit_string.
- merge_audit(parts)[source]
Merge audit trails from two or more frames.
The audit trail from each frame is indented and wrapped with braces (
{}). This makes the audit trail easier to read when a component uses two or more inputs.The
partsparameter is adictofFrameorMetadataobjects. Thedictkeys are used to label each indented audit trail.For example, this Python code:
out_frame.merge_audit({'Y': Y_frame, 'UV': UV_frame}) out_frame.set_audit( self, 'data = YUVtoRGB(Y, UV)\n matrix: {}\n'.format(matrix))
could produce this audit trail:
Y = { data = test.y path: '/home/jim/Videos/test.y', looping: 'repeat', noaudit: True <pyctools.components.io.videofilereader.VideoFileReader> } UV = { data = test.uv path: '/home/jim/Videos/test.uv', looping: 'repeat', noaudit: True <pyctools.components.io.videofilereader.VideoFileReader> } data = YUVtoRGB(Y, UV) matrix: 601 <pyctools.components.colourspace.yuvtorgb.YUVtoRGB>- Parameters:
parts (dict) – The inputs to merge.
- from_file(path)[source]
Read metadata from an XMP sidecar file or, if there is no sidecar, from the image/video file (if it has metadata).
Returns the
Metadataobject, allowing convenient code like this:md = Metadata().from_file(path)
- to_file(path, thumbnail=None)[source]
Write metadata to an image, video or XMP sidecar file.
- Parameters:
path (str) – The image/video file path name.
- copy(other)[source]
Copy metadata from another
Metadataobject.Returns the
Metadataobject, allowing convenient code like this:md = Metadata().copy(other_md)
- image_size()[source]
Get image dimensions from metadata.
This is primarily used by the
RawFileReadercomponent, as raw video files don’t have a header in which to store the dimensions.
- get(tag, default=None)[source]
Get a metadata value.
Each metadata value is referenced by a
tag– a short string such as'xlen'or'audit'. In the sidecar file these tag names are prepended with'Xmp.pyctools.', which corresponds to a custom namespace in the XML file.
Comments or questions? Please email jim@jim-easterbrook.me.uk.