org.jaitools.imageutils
Class FloodFiller

java.lang.Object
  extended by org.jaitools.imageutils.FloodFiller

public class FloodFiller
extends Object

A flood-filling algorithm to use with rasters.

The code is adapted from an algorithm published in C# by J. Dunlap at:

   http://www.codeproject.com/KB/GDI-plus/queuelinearfloodfill.aspx
which was subsequently ported to Java by Owen Kaluza. The JAITools implementation is substantially different and any bugs should not be blamed on the above authors.

This version works with a source RenderedImage and a destination WritableRenderedImage, both of which are accessed using JAI iterators.

Since:
1.0
Version:
$Id$
Author:
Michael Bedward

Nested Class Summary
static class FloodFiller.ScanSegment
          Records a segment of contiguous pixels in a single row that will become part of a filled region.
 
Constructor Summary
FloodFiller(RenderedImage sourceImage, int sourceBand, WritableRenderedImage destImage, int destBand, double tolerance, boolean diagonal)
          Create a FloodFiller to work with the given source image
 
Method Summary
 FillResult fill(int x, int y, int fillValue)
          Fills the region connected to the specified start pixel.
 FillResult fill(int x, int y, int fillValue, double refValue)
          Fills the region connected to the specified start pixel.
 FillResult fillRadius(int x, int y, int fillValue, double radius)
          Fills the region connected to the specified start pixel and lying within radius pixels of the start pixel.
 FillResult fillRadius(int x, int y, int fillValue, double refValue, double radius)
          Fills the region connected to the specified start pixel and lying within radius pixels of the start pixel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FloodFiller

public FloodFiller(RenderedImage sourceImage,
                   int sourceBand,
                   WritableRenderedImage destImage,
                   int destBand,
                   double tolerance,
                   boolean diagonal)
Create a FloodFiller to work with the given source image

Parameters:
sourceImage - the source image
destImage - the destination image
sourceBand - the source image band to be processed
destBand - the destination image band to write to
tolerance - the maximum absolute difference in value for a pixel to be included in the region
diagonal - set to true to include sub-regions that are only connected diagonally; set to false to require orthogonal connections
Method Detail

fill

public FillResult fill(int x,
                       int y,
                       int fillValue)
Fills the region connected to the specified start pixel. A pixel belongs to this region if there is a path between it and the starting pixel which passes only through pixels of value v within the range start_pixel_value - tolerance <= v <= start_pixel_value + tolerance.

Parameters:
x - start pixel x coordinate
y - start pixel y coordinate
fillValue - the value to write to the destination image for this region
Returns:
a new FillResult

fillRadius

public FillResult fillRadius(int x,
                             int y,
                             int fillValue,
                             double radius)
Fills the region connected to the specified start pixel and lying within radius pixels of the start pixel.

A pixel belongs to this region if there is a path between it and the starting pixel which passes only through pixels of value v within the range start_pixel_value - tolerance <= v <= start_pixel_value + tolerance.

Parameters:
x - start pixel x coordinate
y - start pixel y coordinate
fillValue - the value to write to the destination image for this region
radius - maximum distance (pixels) that a candidate pixel can be from the start pixel
Returns:
a new FillResult

fill

public FillResult fill(int x,
                       int y,
                       int fillValue,
                       double refValue)
Fills the region connected to the specified start pixel. A pixel belongs to this region if there is a path between it and the starting pixel which passes only through pixels of value v within the range refValue - tolerance <= v <= refValue + tolerance.

Parameters:
x - start pixel x coordinate
y - start pixel y coordinate
fillValue - the value to write to the destination image for this region
refValue - the source image reference value for the region
Returns:
a new FillResult

fillRadius

public FillResult fillRadius(int x,
                             int y,
                             int fillValue,
                             double refValue,
                             double radius)
Fills the region connected to the specified start pixel and lying within radius pixels of the start pixel.

A pixel belongs to this region if there is a path between it and the starting pixel which passes only through pixels of value v within the range refValue - tolerance <= v <= refValue + tolerance.

Parameters:
x - start pixel x coordinate
y - start pixel y coordinate
fillValue - the value to write to the destination image for this region
refValue - the source image reference value for the region
radius - maximum distance (pixels) that a candidate pixel can be from the start pixel
Returns:
a new FillResult


Copyright © 2009-2013. All Rights Reserved.