jaitools.media.jai.regionalize
Class RegionalizeOpImage

java.lang.Object
  extended by javax.media.jai.PlanarImage
      extended by javax.media.jai.OpImage
          extended by javax.media.jai.PointOpImage
              extended by jaitools.media.jai.regionalize.RegionalizeOpImage
All Implemented Interfaces:
java.awt.image.RenderedImage, javax.media.jai.ImageJAI, javax.media.jai.PropertyChangeEmitter, javax.media.jai.PropertySource, javax.media.jai.WritablePropertySource

public class RegionalizeOpImage
extends javax.media.jai.PointOpImage

An operator to identify regions of uniform value, within a user-specified tolerance, in the source image. Produces a destination image of these regions where pixel values are equal to region ID.

To avoid region numbering artefacts on image tile boundaries this operator imposes an order on tile computation (by column within row). If an arbitrary tile is requested by the caller, the operator first checks that all of the preceding tiles have been computed and cached, processing any that have not. The operator creates its own ExecutorService for sequential tile computations.

Each computed tile is cached using an instance of DiskMemTileCache. The caller can provide this to the operator via RenderingHints, or set it as the default TileCache using JAI.getDefaultInstance().setTileCache(). Otherwise the operator will create a DiskMemTileCache object for itself.

Since:
1.0
Version:
$Id: RegionalizeOpImage.java 1100 2010-02-10 07:28:08Z michael.bedward $
Author:
Michael Bedward
See Also:
RegionalizeDescriptor, RegionData

Field Summary
static int NO_REGION
          Destingation value indicating that the pixel does not belong to a region
 
Fields inherited from class javax.media.jai.OpImage
cache, cobbleSources, OP_COMPUTE_BOUND, OP_IO_BOUND, OP_NETWORK_BOUND, tileCacheMetric, tileRecycler
 
Fields inherited from class javax.media.jai.PlanarImage
colorModel, eventManager, height, minX, minY, properties, sampleModel, tileFactory, tileGridXOffset, tileGridYOffset, tileHeight, tileWidth, width
 
Constructor Summary
RegionalizeOpImage(java.awt.image.RenderedImage source, java.util.Map config, javax.media.jai.ImageLayout layout, int band, double tolerance, boolean diagonal)
          Constructor
 
Method Summary
protected  void addTileToCache(int tileX, int tileY, java.awt.image.Raster tile)
          This method is overridden to prevent it being used because the RegionalizeOpImage object should be soley responsible for creating tiles and caching them.
 java.awt.image.Raster computeTile(int tileX, int tileY)
           
 java.util.Hashtable getProperties()
          Get the properties for this operator.
 java.lang.Object getProperty(java.lang.String name)
          Get a property associated with this operator.
 java.lang.Class<?> getPropertyClass(java.lang.String name)
          For internal use
 java.lang.String[] getPropertyNames()
          For internal use
 java.awt.image.Raster getTile(int tileX, int tileY)
          Returns a tile of this image as a Raster.
protected  java.awt.image.Raster getTileFromCache(int tileX, int tileY)
          This method is overridden to ensure that the cache is always addressed through the DiskMemImage being used by this operator, otherwise tile IDs calculated by the cache will vary with the perceived owner (the image or the operator) of the tile.
 void setTileCache(javax.media.jai.TileCache cache)
          Set the tile cache.
 
Methods inherited from class javax.media.jai.PointOpImage
dispose, isColormapOperation, mapDestRect, mapSourceRect, permitInPlaceOperation
 
Methods inherited from class javax.media.jai.OpImage
cancelTiles, computeRect, computeRect, computesUniqueTiles, createTile, getExpandedNumBands, getFormatTags, getOperationComputeType, getTileCache, getTileCacheMetric, getTileDependencies, getTileRecycler, getTiles, hasExtender, mapDestPoint, mapSourcePoint, prefetchTiles, queueTiles, recycleTile, vectorize, vectorize, vectorize
 
Methods inherited from class javax.media.jai.PlanarImage
addPropertyChangeListener, addPropertyChangeListener, addSink, addSink, addSource, addTileComputationListener, copyData, copyData, copyExtendedData, createColorModel, createSnapshot, createWritableRaster, finalize, getAsBufferedImage, getAsBufferedImage, getBounds, getColorModel, getData, getData, getDefaultColorModel, getExtendedData, getGraphics, getHeight, getImageID, getMaxTileX, getMaxTileY, getMaxX, getMaxY, getMinTileX, getMinTileY, getMinX, getMinY, getNumBands, getNumSources, getNumXTiles, getNumYTiles, getPropertyNames, getSampleModel, getSinks, getSource, getSourceImage, getSourceObject, getSources, getSplits, getTileComputationListeners, getTileFactory, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileIndices, getTileRect, getTiles, getTileWidth, getWidth, overlapsMultipleTiles, removeProperty, removePropertyChangeListener, removePropertyChangeListener, removeSink, removeSink, removeSinks, removeSource, removeSources, removeTileComputationListener, setImageLayout, setProperties, setProperty, setSource, setSources, tileXToX, tileXToX, tileYToY, tileYToY, toString, wrapRenderedImage, XToTileX, XToTileX, YToTileY, YToTileY
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_REGION

public static final int NO_REGION
Destingation value indicating that the pixel does not belong to a region

See Also:
Constant Field Values
Constructor Detail

RegionalizeOpImage

public RegionalizeOpImage(java.awt.image.RenderedImage source,
                          java.util.Map config,
                          javax.media.jai.ImageLayout layout,
                          int band,
                          double tolerance,
                          boolean diagonal)
Constructor

Parameters:
source - a RenderedImage.
config - configurable attributes of the image (see AreaOpImage)
layout - an ImageLayout optionally containing the tile grid layout, SampleModel, and ColorModel, or null.
band - the band to process
tolerance - max absolute difference in value between the starting pixel for a region and any pixel added to that region
diagonal - true to include sub-regions with only diagonal connectedness; false to require orthogonal connectedness
See Also:
RegionalizeDescriptor
Method Detail

getProperty

public java.lang.Object getProperty(java.lang.String name)
Get a property associated with this operator. Use this to retrieve the RegionData object with the property name RegionalizeDescriptor.REGION_DATA_PROPERTY

Specified by:
getProperty in interface java.awt.image.RenderedImage
Specified by:
getProperty in interface javax.media.jai.PropertySource
Overrides:
getProperty in class javax.media.jai.PlanarImage
Parameters:
name - property name
Returns:
the matching object or null if there was no match

getProperties

public java.util.Hashtable getProperties()
Get the properties for this operator. These will include the RegionData object

Overrides:
getProperties in class javax.media.jai.PlanarImage

getPropertyClass

public java.lang.Class<?> getPropertyClass(java.lang.String name)
For internal use

Specified by:
getPropertyClass in interface javax.media.jai.PropertySource
Overrides:
getPropertyClass in class javax.media.jai.PlanarImage

getPropertyNames

public java.lang.String[] getPropertyNames()
For internal use

Specified by:
getPropertyNames in interface java.awt.image.RenderedImage
Specified by:
getPropertyNames in interface javax.media.jai.PropertySource
Overrides:
getPropertyNames in class javax.media.jai.PlanarImage

getTile

public java.awt.image.Raster getTile(int tileX,
                                     int tileY)
Returns a tile of this image as a Raster. If the requested tile is completely outside of this image's bounds, this method returns null.

The nature of the regionalizing algorithm means that to compute any tile other than the first (top left) we must compute all tiles to avoid region numbering artefacts across tile boundaries.

Specified by:
getTile in interface java.awt.image.RenderedImage
Overrides:
getTile in class javax.media.jai.OpImage
Parameters:
tileX - The X index of the tile.
tileY - The Y index of the tile.

computeTile

public java.awt.image.Raster computeTile(int tileX,
                                         int tileY)
Overrides:
computeTile in class javax.media.jai.PointOpImage

addTileToCache

protected void addTileToCache(int tileX,
                              int tileY,
                              java.awt.image.Raster tile)
This method is overridden to prevent it being used because the RegionalizeOpImage object should be soley responsible for creating tiles and caching them. If invoked an UnsupportedOperationException will be thrown.

Overrides:
addTileToCache in class javax.media.jai.OpImage

getTileFromCache

protected java.awt.image.Raster getTileFromCache(int tileX,
                                                 int tileY)
This method is overridden to ensure that the cache is always addressed through the DiskMemImage being used by this operator, otherwise tile IDs calculated by the cache will vary with the perceived owner (the image or the operator) of the tile.

Overrides:
getTileFromCache in class javax.media.jai.OpImage
Parameters:
tileX - tile X coordinate
tileY - tile Y coordinate
Returns:
the requested tile

setTileCache

public void setTileCache(javax.media.jai.TileCache cache)
Set the tile cache. The supplied cache must be an instance of DiskMemTileCache.

Overrides:
setTileCache in class javax.media.jai.OpImage
Parameters:
cache - an instance of DiskMemTileCache
Throws:
java.lang.IllegalArgumentException - if cache is null or not an instance of DiskMemTileCache


Copyright © 2009-2010. All Rights Reserved.