no.hiof.imagepr.features
Class ConnectedComponents

java.lang.Object
  extended byno.hiof.imagepr.features.ConnectedComponents

public class ConnectedComponents
extends java.lang.Object

ConnectedComponents is a class for labeling connected components of a binary image, with respect to the 4-neighborhood (default), the or the 8-neighborhood definition. This class offers two algorithms, a recursive one and the so called classical algorithm. See "Computer Vision" chapter 3.4 by Linda G. Shapiro and George C. Stockman, for a description of the algorithms.

The classical algorithm was described by Rosenfeld and Pfaltz. In this class this is combined with a union-find structure as given in "Computer Vision" chapter 3.4 by Linda G. Shapiro and George C. Stockman.

The recursive algorithm will fail for pictures with large connected components due to the limited recursive depth possible in Java.

Author:
Mari-Ann Akerjord

Field Summary
static int CLASSICAL
          Option for the classical algorithm
static int N4
          Option for finding 4-connected components.
static int N8
          Option for finding 8-connected components.
static int RECURSIVE
          Option for the recursive algorithm
 
Constructor Summary
ConnectedComponents(BinaryImage bImage)
          Constructor which sets the BinaryImage to process.
ConnectedComponents(BinaryImage bImage, int nbhood)
          Constructor wich sets the BinaryImage to process and the type of connection to use.
ConnectedComponents(BinaryImage bImage, int nbhood, int algorithm)
          Constructor which sets the BinaryImage to process and the type of connection to use.
 
Method Summary
 IntensityImage getCompImage()
          Returns the labeled image in which the value of each pixel is the label of its connected component.
 BinaryImage getCompNo(int label)
          Returns an image with only one of the connected components.
 int getLabel()
          Returns the value of the label of the last connected component found in the image.
 void setMaxLabels(int max)
          Set maximum number of labels used with the classical algorithm.
 void showAllComponents()
          Show all components in a window, with a unique colour for each component.
 void showAllComponents(java.awt.Color mincolor, java.awt.Color maxcolor)
          Show all components in a window, with a unique colour for each component.
 void showCompNo(int label)
          Show a component in a window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

N4

public static final int N4
Option for finding 4-connected components.

See Also:
Constant Field Values

N8

public static final int N8
Option for finding 8-connected components.

See Also:
Constant Field Values

CLASSICAL

public static final int CLASSICAL
Option for the classical algorithm

See Also:
Constant Field Values

RECURSIVE

public static final int RECURSIVE
Option for the recursive algorithm

See Also:
Constant Field Values
Constructor Detail

ConnectedComponents

public ConnectedComponents(BinaryImage bImage)
Constructor which sets the BinaryImage to process. By default the generated instance of ConnectedComponents will find four-connected components.

Parameters:
bImage - Image to process

ConnectedComponents

public ConnectedComponents(BinaryImage bImage,
                           int nbhood)
Constructor wich sets the BinaryImage to process and the type of connection to use. The parameter nbhood should be either N4 or N8.

Parameters:
bImage - Image to process
nbhood - Type of neighbourhood

ConnectedComponents

public ConnectedComponents(BinaryImage bImage,
                           int nbhood,
                           int algorithm)
Constructor which sets the BinaryImage to process and the type of connection to use. Set nbhood to N4 of N8 and algorithm to CLASSICAL or RECURSIVE

Parameters:
bImage - Image to process
nbhood - Type of connection
algorithm - Type of algorithm
Method Detail

setMaxLabels

public void setMaxLabels(int max)
Set maximum number of labels used with the classical algorithm. I this method is not called, the number is set to 10000. Note that the number of labels must be set much larger than the maximum number of components, as the algorithm uses a temporary array of labels that may be much larger than the final number of components.

Parameters:
max - Maximum number of labels

getCompImage

public IntensityImage getCompImage()
Returns the labeled image in which the value of each pixel is the label of its connected component. All background pixels have value zero.

Returns:
The labeled image

getLabel

public int getLabel()
Returns the value of the label of the last connected component found in the image. This is the same as the number of connected components of the image.

Returns:
The label of the last connected component

getCompNo

public BinaryImage getCompNo(int label)
Returns an image with only one of the connected components.

Parameters:
label - The label of the component.
Returns:
A BinaryImage containing the spesific connected component.

showCompNo

public void showCompNo(int label)
Show a component in a window.

Parameters:
label - The label of the component.

showAllComponents

public void showAllComponents()
Show all components in a window, with a unique colour for each component.


showAllComponents

public void showAllComponents(java.awt.Color mincolor,
                              java.awt.Color maxcolor)
Show all components in a window, with a unique colour for each component.

Parameters:
mincolor - The color of the first component.
maxcolor - The color of the last component.