Class HTVQEncode
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class HTVQEncode extends Transformer
This actor encodes a matrix using Hierarchical Table-Lookup Vector Quantization.The matrix must be of dimensions that are amenable to this method. (i.e. 2x1, 2x2, 4x2, 4x4, etc.) Instead of performing a full-search vector quantization during execution, all the optimal encoding vectors are calculated before hand and stored in a lookup table. (This is known as Table-lookup Vector Quantization). However, for large vector sizes the lookup tables are unmanageably large. This actor approximates a full search VQ by storing the lookup tables hierarchically. The encoding is broken up into stages, and at each stage a number of 2x1 table lookup VQs are performed. For example, starting with a 4x2 vector in the first stage, codebook 0 (which operates on raw pixels) is used 4 times, resulting in a 2x2 vector of codewords. In the second stage, codebook 1 is used twice, resulting in a 2x1 vector. Lastly, a single 2x1 VQ using codebook 2 (which operates on codewords representing 2x2 vectors) returns a single codeword for the 4x2 vector.
The input is an IntMatrixToken corresponding to the block to be encoded. The values in this matrix are assumed to be between 0 and 255. The output is an IntToken with value between 0 and 255. Integers are used here because of the minimal byte support in Ptolemy or JAVA. The size of the input matrix should be the same as the parameters blockHeight and blockWidth.
The codebook is specified as a binary file that will be read during initialization. This file actually contains five sets of codebooks and lookups tables. The first set is for 2x1 blocks, the second is for 2x2 blocks, etc. (Thus the supplied codebook is only sufficient for block sizes up to 8x4 pixels.) In each set, the codebook precedes the lookup-tables. The codebook consists of all 256 codevectors, row scanned from top to bottom. The lookup table consists of 64K entries (one for each pair of codewords from the previous stage). Each entry in the lookup table is an 8-bit codeword.
Stage 0: 2x1 block size codebook = 256 blocks x 2 bytes = 512 bytes lookup tables = 65536 entries x 1 byte = 65536 bytes Stage 1: 2x2 block size codebook = 256 blocks x 4 bytes = 1024 bytes lookup tables = 65536 entries x 1 byte = 65536 bytes Stage 2: 4x2 block size codebook = 256 blocks x 8 bytes = 2048 bytes lookup tables = 65536 entries x 1 byte = 65536 bytes Stage 3: 4x4 block size codebook = 256 blocks x 16 bytes = 4096 bytes lookup tables = 65536 entries x 1 byte = 65536 bytes Stage 4: 8x4 block size codebook = 256 blocks x 32 bytes = 8192 bytes lookup tables = 65536 entries x 1 byte = 65536 bytes
The supplied codebook was trained using images from the USC image archive and is suitable for most general applications.
For more information here are some interesting references:
A. Gersho and R. M. Gray, Vector Quantization and Signal Compression. Kluwer Academic Publishers, Boston, 1992.
P. C. Chang, J. May, R. M. Gray, "Hierarchical Vector Quantizers with Table Lookup Encoders," International Conference on Acoustics Speech and Signal Processing, pp. 1452-1455, 1985.
M. Vishwanath and P. Chou, "An Efficient Algorithm for Hierarchical Compression of Video," International Conference on Image Processing, vol. 3, pp. 275-279, Nov. 1994
- Since:
- Ptolemy II 0.2
- Version:
- $Id$
- Author:
- Steve Neuendorffer
- Pt.AcceptedRating:
- Red (neuendor)
- Pt.ProposedRating:
- Yellow (neuendor)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description Parameter
blockCount
The number of blocks to be encoded during each firing.Parameter
blockHeight
The width, in pixels, of the block to encode.Parameter
blockWidth
The width, in pixels, of the block to encode.Parameter
codeBook
A Parameter of type String, giving the location of the codebook data file relative to the root classpath.Parameter
input_tokenConsumptionRate
The input rate.Parameter
output_tokenProductionRate
The output rate.-
Fields inherited from class ptolemy.actor.lib.Transformer
input, output
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description HTVQEncode(CompositeEntity container, java.lang.String name)
Construct an actor in the specified container with the specified name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone(Workspace workspace)
Clone the actor into the specified workspace.void
fire()
Fire this actor.void
initialize()
Initialize this actor.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
codeBook
public Parameter codeBook
A Parameter of type String, giving the location of the codebook data file relative to the root classpath.
-
blockCount
public Parameter blockCount
The number of blocks to be encoded during each firing. The default value is one, which will always work, but using a higher number (such as the number of blocks in a frame) will speed things up.
-
blockWidth
public Parameter blockWidth
The width, in pixels, of the block to encode.
-
blockHeight
public Parameter blockHeight
The width, in pixels, of the block to encode.
-
input_tokenConsumptionRate
public Parameter input_tokenConsumptionRate
The input rate.
-
output_tokenProductionRate
public Parameter output_tokenProductionRate
The output rate.
-
-
Constructor Detail
-
HTVQEncode
public HTVQEncode(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Construct an actor in the specified container with the specified name.- Parameters:
container
- The container.name
- The name of this adder within the container.- Throws:
IllegalActionException
- If the actor cannot be contained by the proposed container.NameDuplicationException
- If the name coincides with an actor already in the container.
-
-
Method Detail
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace.- Overrides:
clone
in classTypedAtomicActor
- Parameters:
workspace
- The workspace for the new object.- Returns:
- A new actor.
- Throws:
java.lang.CloneNotSupportedException
- If a derived class contains an attribute that cannot be cloned.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
fire
public void fire() throws IllegalActionException
Fire this actor. Consume a codeword on the input, and perform Vector Quantization using Hierarchical Table-Lookup Vector Quantization. Send the computed codeword on the output.- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If a contained method throws it.
-
initialize
public void initialize() throws IllegalActionException
Initialize this actor. Load the codebooks and lookup tables from the file given by the parameter "codeBook".- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the parameters do not have legal values, or the codebook file cannot be read.
-
-