org.hd.d.pg2k.ai.scorer
Class AbstractImgScorer

java.lang.Object
  extended by org.hd.d.pg2k.ai.scorer.AbstractScorer
      extended by org.hd.d.pg2k.ai.scorer.AbstractImgScorer
All Implemented Interfaces:
ScorerIF
Direct Known Subclasses:
LocalSampler, SimpleExposure

public abstract class AbstractImgScorer
extends AbstractScorer
implements ScorerIF

Base interface to compute the score and confidence for a 2D still image. All methods in this interface are guaranteed to be "safe" insofaras they will complete in "reasonable" time with reasonable heap memory (and other resource, eg stack) and without doing anything that wouldn't be allowed in a minimal Applet/JWS sandbox.

All classes implementing this interface should be completely thread-safe in their implementation of the computeScoreAndConfidence() method, and preferrably purely functional (no visible side-effects), with as many concurrent threads as required safely doing separate computations in any one instance.

Classes implementing this interface should, where possible, do their calculations using integer arithmetic, since FPUs to support float/double calaculations may be a scarce resource on newer highly-threaded CPUs such as Sun's Niagara.

TODO: At least tie the cache to the AEP/pipeline, not static.


Field Summary
private static java.util.Map<java.lang.String,java.lang.ref.SoftReference<java.awt.image.BufferedImage>> _tnBICache
          Private static cache from exhibit name to expanded (std) thumbnail image.
 
Fields inherited from class org.hd.d.pg2k.ai.scorer.AbstractScorer
nameAndParameters, parameterNameRegex, parameterSepRegex, scorerNameRegex, SEPARATOR
 
Constructor Summary
AbstractImgScorer()
          Create simple non-parameterised instance.
AbstractImgScorer(java.lang.String nameAndParameters)
          Create parameterised version.
AbstractImgScorer(java.lang.String baseName, java.util.List<ScorerParam> parameters)
          Create parameterised version.
 
Method Summary
abstract  ScoreAndConf computeScoreAndConfidence(java.awt.image.RenderedImage stillImage)
          Compute score [-1,+1] and confidence[0,+1] for given image; never null.
 ScoreAndConf computeScoreAndConfidence(SimpleExhibitPipelineIF dataSource, java.lang.String exhibitName)
          Implement core/generic compute method specially for image types.
 
Methods inherited from class org.hd.d.pg2k.ai.scorer.AbstractScorer
canonicalise, createPerturbedVariant, getBaseName, getDefaultName, getNameAndParameters, getParameterDefsAndValues, getPerturbedDefsAndValues, isValidParameterName, isValidScorerName, paramListAsMap, paramListAsString, parseNameAndParameters, similarNParams, verySimilar
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.hd.d.pg2k.ai.scorer.ScorerIF
createPerturbedVariant, createVariant, createVariant, getBaseName, getNameAndParameters, getParameterDefsAndValues, getPerturbedDefsAndValues
 

Field Detail

_tnBICache

private static final java.util.Map<java.lang.String,java.lang.ref.SoftReference<java.awt.image.BufferedImage>> _tnBICache
Private static cache from exhibit name to expanded (std) thumbnail image. This exists to avoid having to unpack thumbnail images repeatedly.

The expanded images are held via SoftReferences to allow them to be ditched in case of memory shortage, and when individual thumbnails stop being used.

The cache key is the (full) exhibit name on the basis that thumbnails hardly ever change once created. This also means that we will stop hitting any thumbnail caches in the data pipeline once we have fetched a thumbnail once.

This cache is thread-safe and highly concurrent.

TODO: Deal with the case when a thumbnail IS changed/improved.

Constructor Detail

AbstractImgScorer

public AbstractImgScorer()
Create simple non-parameterised instance.


AbstractImgScorer

public AbstractImgScorer(java.lang.String nameAndParameters)
Create parameterised version.


AbstractImgScorer

public AbstractImgScorer(java.lang.String baseName,
                         java.util.List<ScorerParam> parameters)
Create parameterised version.

Method Detail

computeScoreAndConfidence

public abstract ScoreAndConf computeScoreAndConfidence(java.awt.image.RenderedImage stillImage)
Compute score [-1,+1] and confidence[0,+1] for given image; never null. This routine must NOT alter the image.

Parameters:
stillImage - non-null still 2D image; if greater than 256x256 pixels then will be internally scaled

computeScoreAndConfidence

public ScoreAndConf computeScoreAndConfidence(SimpleExhibitPipelineIF dataSource,
                                              java.lang.String exhibitName)
                                       throws java.io.IOException
Implement core/generic compute method specially for image types. For any suitable 2D still image type that has a standard thumbnail, this uses calls the computeScoreAndConfidence(RenderedImage) method with that thumbnail.

We use the standard thumbnail as being representative of the full image (and usually good enough for a human to make a judgement from) with out requiring all the system resources of the full image.

For non-image types (or images with no thumbnails possible) this returns (0,0) to indicate that it does not have a view.

Specified by:
computeScoreAndConfidence in interface ScorerIF
Parameters:
dataSource - souce of exhibit data and metadata; never null
exhibitName - name of exhibit; must be syntactically valid and not null
Throws:
java.io.IOException - in case of I/O difficulties, or when a thumbnail is not currently available but may be later (upon retry)

DHD Multimedia Gallery V1.50.55

Copyright (c) 1996-2008, Damon Hart-Davis. All rights reserved.