|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.ai.scorer.AbstractScorer
org.hd.d.pg2k.ai.scorer.AbstractImgScorer
public abstract class AbstractImgScorer
Base interface to compute the score and confidence for a 2D still image. All methods in this interface are guaranteed to be "safe" in so far as 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 preferably 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 calculations 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.
| Nested Class Summary | |
|---|---|
static interface |
AbstractImgScorer.ARGBPixelFilter
Interface to accept or reject putative samples in getSamplePoints(). |
| Field Summary | |
|---|---|
private static SoftReferenceMap<java.lang.Object,java.awt.image.BufferedImage> |
_tnBICache
Private static 'soft' cache from unique exhibit identifier to expanded (std) thumbnail image. |
static AbstractImgScorer.ARGBPixelFilter |
rejectMainlyTransparentPoints
Filter to reject mainly-transparent ARGB samples. |
| 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 | |
|---|---|
protected static java.awt.image.RenderedImage |
callStillImageFactory(java.util.concurrent.Callable<java.awt.image.RenderedImage> stillImageFactory)
Call the factory to retrieve a still image, handling wrapped IOExceptions and timeouts specially. |
ScoreAndConf |
computeScoreAndConfidence(SimpleExhibitPipelineIF dataSource,
Name.ExhibitFull exhibitName)
Implement core/generic compute method specially for image types. |
abstract ScoreAndConf |
computeScoreAndConfidenceOnStillImage(java.lang.Object key,
java.util.concurrent.Callable<java.awt.image.RenderedImage> stillImageFactory)
Compute score [-1,+1] and confidence[0,+1] for given image; never null. |
static int[] |
getSamplePoints(java.awt.image.RenderedImage stillImage,
int maxSamplePoints,
AbstractImgScorer.ARGBPixelFilter filter)
Collect a set of ARGB samples from the image. |
| 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 |
|---|
private static final SoftReferenceMap<java.lang.Object,java.awt.image.BufferedImage> _tnBICache
The (big) expanded images are held via SoftReferences to allow them to be ditched in case of memory shortage, and when individual thumbnails stop being used, and we don't cache new entries unless there is lots of free memory.
The cache key is the (full) exhibit name plus other static attributes 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.
This cache is shared between all derived image Scorer classes.
TODO: Deal with the case when a thumbnail IS changed/improved.
public static final AbstractImgScorer.ARGBPixelFilter rejectMainlyTransparentPoints
| Constructor Detail |
|---|
public AbstractImgScorer()
public AbstractImgScorer(java.lang.String nameAndParameters)
public AbstractImgScorer(java.lang.String baseName,
java.util.List<ScorerParam> parameters)
| Method Detail |
|---|
protected static java.awt.image.RenderedImage callStillImageFactory(java.util.concurrent.Callable<java.awt.image.RenderedImage> stillImageFactory)
throws java.io.IOException
java.io.IOException - if the factory threw IOException
java.lang.IllegalStateException - if the factory throws something unrecognised
public abstract ScoreAndConf computeScoreAndConfidenceOnStillImage(java.lang.Object key,
java.util.concurrent.Callable<java.awt.image.RenderedImage> stillImageFactory)
throws java.io.IOException
Note that the underlying factory may legitimately throw IOException, especially InterruptedIOException, in case of transient problems that indicate that a retry should probably be attempted later.
This is made public mainly so as to facilitate testing.
key - unique key identifying image for cacheing intermediate results for example;
if null then this will not be cachedstillImageFactory - produces on demand a non-null still 2D image or null if not possible;
if greater than 256x256 pixels then will be internally scaled; never null
java.io.IOException
public static int[] getSamplePoints(java.awt.image.RenderedImage stillImage,
int maxSamplePoints,
AbstractImgScorer.ARGBPixelFilter filter)
All samples returned are from unique pixels in the source image.
If the number of points requested greater than or equal to the number of image pixels then all pixels are 'sampled' and returned, else a pseudo-random (but consistent) sample set is returned.
The order of sample pixels is explicitly undefined since each sample should be treated independently of its position in the sample set.
This is made public mainly to assist with testing.
stillImage - still image (eg thumbnail) to sample pixels from; never null nor zero-sizedmaxSamplePoints - maximum number of samples to collect; strictly positiverejectMainlyTransparentPoints - if true then omit mainly transparent points
public ScoreAndConf computeScoreAndConfidence(SimpleExhibitPipelineIF dataSource,
Name.ExhibitFull exhibitName)
throws java.io.IOException
We assume the standard thumbnail to be representative of the full image (and usually good enough for a human to make a judgement from) without 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.
computeScoreAndConfidence in interface ScorerIFdataSource - source of exhibit data and metadata; never nullexhibitName - full name of exhibit; must be syntactically valid and not null
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.60.69 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||