org.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 org.jaitools.media.jai.regionalize.RegionalizeOpImage
All Implemented Interfaces:
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$
Author:
Michael Bedward
See Also:
RegionalizeDescriptor, RegionData

Field Summary
static int NO_REGION
          Destination value indicating that a 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(RenderedImage source, Map config, javax.media.jai.ImageLayout layout, int band, double tolerance, boolean diagonal)
          Creates a new instance.
 
Method Summary
protected  void addTileToCache(int tileX, int tileY, Raster tile)
          This method is overridden to prevent it being used by clients.
 Raster computeTile(int tileX, int tileY)
          
 Hashtable getProperties()
          Gets the properties for this operator.
 Object getProperty(String name)
          Gets a property associated with this operator.
 Class<?> getPropertyClass(String name)
          
 String[] getPropertyNames()
          
 Raster getTile(int tileX, int tileY)
          Returns a tile of this image as a Raster.
protected  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
Destination value indicating that a pixel does not belong to a region

See Also:
Constant Field Values
Constructor Detail

RegionalizeOpImage

public RegionalizeOpImage(RenderedImage source,
                          Map config,
                          javax.media.jai.ImageLayout layout,
                          int band,
                          double tolerance,
                          boolean diagonal)
Creates a new instance.

Parameters:
source - the source image
config - configurable attributes of the image (see AreaOpImage)
layout - an optional ImageLayout or null
band - the source image band to process
tolerance - the maximum absolute difference in value between the starting pixel for a region and other subsequent pixels added to it
diagonal - if true include sub-regions with only diagonal connectedness; if false require orthogonal connectedness
See Also:
RegionalizeDescriptor
Method Detail

getProperty

public Object getProperty(String name)
Gets 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 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 Hashtable getProperties()
Gets the properties for this operator. These will include the RegionData object.

Overrides:
getProperties in class javax.media.jai.PlanarImage
Returns:
the properties

getPropertyClass

public Class<?> getPropertyClass(String name)

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

getPropertyNames

public String[] getPropertyNames()

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

getTile

public 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 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 Raster computeTile(int tileX,
                          int tileY)

Overrides:
computeTile in class javax.media.jai.PointOpImage

addTileToCache

protected void addTileToCache(int tileX,
                              int tileY,
                              Raster tile)
This method is overridden to prevent it being used by clients.

Overrides:
addTileToCache in class javax.media.jai.OpImage
Parameters:
tileX - tile X ordinate
tileY - tile Y ordinate
tile - the tile
Throws:
UnsupportedOperationException - if called

getTileFromCache

protected 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:
IllegalArgumentException - if cache is null or not an instance of DiskMemTileCache


Copyright © 2009-2013. All Rights Reserved.