br.usp.ime.klava.segmentit.util
Class MatrixImagesUtils

java.lang.Object
  extended by br.usp.ime.klava.segmentit.util.MatrixImagesUtils

public class MatrixImagesUtils
extends java.lang.Object

Performs operations involving images and matrices.

Author:
Bruno Klava

Constructor Summary
MatrixImagesUtils()
           
 
Method Summary
static java.awt.Color[][] getColorMatrix(java.awt.image.BufferedImage image)
          Constructs a matrix of Colors that represents the given image.
static int[][] getGrayLevelMatrix(java.awt.image.BufferedImage image)
          Constructs a matrix of ints that represents the given image.
static java.awt.image.BufferedImage getImage(int[][] grayLevelMatrix)
          Returns an image with the gray levels given by the grayLevelMatrix.
static java.lang.Boolean[][] getMarkedPixels(java.awt.image.BufferedImage image)
          Returns a matrix of Booleans that indicates if each pixel of image is marked (not transparent).
static Pixel[][] getPixelsMatrix(java.awt.image.BufferedImage image)
          Constructs a matrix of Pixels that represents the given image.
static int[] markBasins(PrimitiveCatchmentBasinsGraph graph, java.awt.image.BufferedImage markers, LabelingCriterion labelingCriterion)
          Given a unique label to each connected color component of the markers image and maps this labels to the vertices of graph.
static java.awt.image.BufferedImage paintBasins(Pixel[][] matrix, java.awt.Color watershedColor, ColorSpace colorSpace)
          Paints an image with each catchment basin of the matrix with a unique color (according to the labeling of each pixel).
static java.awt.image.BufferedImage paintBasins(PrimitiveCatchmentBasinsGraph graph, int[] labels, ColorSpace colorSpace)
          Paints each primitive catchment basin of the given graph according to labels.
static java.awt.image.BufferedImage paintPartitionFromColors(PrimitiveCatchmentBasinsGraph graph, java.awt.Color[] colors)
          Paints each PrimitiveCatchmentBasin of the given graph with the corresponding Color in colors.
static java.awt.image.BufferedImage paintPartitionFromMarkersColors(Pixel[][] partition, java.awt.image.BufferedImage markers)
          Paints each segment of the partition with the colors of the corresponding marker.
static java.awt.image.BufferedImage paintPartitionFromMarkersColors(PrimitiveCatchmentBasinsGraph graph, int[] labels, java.awt.image.BufferedImage markers)
          Paints the partition given by the labels used in the graph with the colors of the corresponding markers.
static java.awt.image.BufferedImage paintWatershed(Pixel[][] matrix, java.awt.Color watershedColor, java.awt.Color backgroundColor)
          Paints an image with the Pixels marked as watershed with watershedColor.
static int refreshMarkers(Pixel[][] matrix, java.awt.image.BufferedImage markers, LabelingCriterion labelingCriterion)
          Refreshes the content of matrix labeling each connected color component of the markers image with a unique label.
static int refreshMarkers(Pixel[][] matrix, java.awt.image.BufferedImage markers, LabelingCriterion labelingCriterion, Connectivity connectivity)
          Refreshes the content of matrix labeling each connected color component of the markers image with a unique label.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixImagesUtils

public MatrixImagesUtils()
Method Detail

getPixelsMatrix

public static Pixel[][] getPixelsMatrix(java.awt.image.BufferedImage image)
                                 throws ColorImageException
Constructs a matrix of Pixels that represents the given image.

Parameters:
image - the input image
Returns:
a matrix of Pixels that represents the given image
Throws:
ColorImageException - if image is not a gray level image

getColorMatrix

public static java.awt.Color[][] getColorMatrix(java.awt.image.BufferedImage image)
Constructs a matrix of Colors that represents the given image.

Parameters:
image - the input image
Returns:
a matrix of Pixels that represents the given image

getGrayLevelMatrix

public static int[][] getGrayLevelMatrix(java.awt.image.BufferedImage image)
                                  throws ColorImageException
Constructs a matrix of ints that represents the given image.

Parameters:
image - the input image
Returns:
a matrix of ints that represents the given image
Throws:
ColorImageException - if image is not a gray level image

refreshMarkers

public static int refreshMarkers(Pixel[][] matrix,
                                 java.awt.image.BufferedImage markers,
                                 LabelingCriterion labelingCriterion)
Refreshes the content of matrix labeling each connected color component of the markers image with a unique label.

Parameters:
matrix - the matrix of Pixels whose markers will be refreshed
markers - the markers image
labelingCriterion - the criterion for labeling markers
Returns:
the number of markers found

refreshMarkers

public static int refreshMarkers(Pixel[][] matrix,
                                 java.awt.image.BufferedImage markers,
                                 LabelingCriterion labelingCriterion,
                                 Connectivity connectivity)
Refreshes the content of matrix labeling each connected color component of the markers image with a unique label.

Parameters:
matrix - the matrix of Pixels whose markers will be refreshed
markers - the markers image
labelingCriterion - the criterion for labeling markers
connectivity - the Connectivity for labeling markers
Returns:
the number of markers found

markBasins

public static int[] markBasins(PrimitiveCatchmentBasinsGraph graph,
                               java.awt.image.BufferedImage markers,
                               LabelingCriterion labelingCriterion)
Given a unique label to each connected color component of the markers image and maps this labels to the vertices of graph. If there is more than one marker that crosses a primitive catchment basin, the label associated to this vertex is the label of the last marker found (using the raster scan order).

Parameters:
graph - a graph of primitive catchment basins
markers - the markers image
labelingCriterion - the criterion for labeling markers
Returns:
a labeling for the vertices of graph according to its intersections with each connected color component of the markers image

getMarkedPixels

public static java.lang.Boolean[][] getMarkedPixels(java.awt.image.BufferedImage image)
Returns a matrix of Booleans that indicates if each pixel of image is marked (not transparent).

Parameters:
image - the input image
Returns:
a matrix of Booleans that indicates if each pixel of image is marked (not transparent)

paintWatershed

public static java.awt.image.BufferedImage paintWatershed(Pixel[][] matrix,
                                                          java.awt.Color watershedColor,
                                                          java.awt.Color backgroundColor)
Paints an image with the Pixels marked as watershed with watershedColor.

Parameters:
matrix - the input Pixels matrix
watershedColor - the color used to paint the Pixels belonging to the watershed lines
backgroundColor - the color of the background of the output image, null for a transparent background
Returns:
an image with the watershed lines of matrix

paintBasins

public static java.awt.image.BufferedImage paintBasins(Pixel[][] matrix,
                                                       java.awt.Color watershedColor,
                                                       ColorSpace colorSpace)
Paints an image with each catchment basin of the matrix with a unique color (according to the labeling of each pixel). It returns an empty image if there is only one (or none) catchment basin.

Parameters:
matrix - the input matrix
watershedColor - the color to paint the watershed lines, null if the watershed lines must not be painted
colorSpace - the ColorSpace that associates a unique Color for each catchment basin
Returns:
an image with the catchment basins of matrix painted

paintBasins

public static java.awt.image.BufferedImage paintBasins(PrimitiveCatchmentBasinsGraph graph,
                                                       int[] labels,
                                                       ColorSpace colorSpace)
Paints each primitive catchment basin of the given graph according to labels. It returns an empty image if there is only one label in labels.

Parameters:
graph - a graph of primitive catchment basins
labels - a labeling for the vertices of graph
colorSpace - the ColorSpace that associates a unique Color for each label in labels
Returns:
an image with the vertices of graph painted according to labels

getImage

public static java.awt.image.BufferedImage getImage(int[][] grayLevelMatrix)
Returns an image with the gray levels given by the grayLevelMatrix.

Parameters:
grayLevelMatrix - a matrix of gray levels representing an image
Returns:
the gray level image represented by grayLevelMatrix

paintPartitionFromMarkersColors

public static java.awt.image.BufferedImage paintPartitionFromMarkersColors(Pixel[][] partition,
                                                                           java.awt.image.BufferedImage markers)
Paints each segment of the partition with the colors of the corresponding marker.

Parameters:
partition - the input Pixels matrix, representing an image partition
markers - the markers image used to obtain the partition
Returns:
the partition painted with the colors from the markers

paintPartitionFromMarkersColors

public static java.awt.image.BufferedImage paintPartitionFromMarkersColors(PrimitiveCatchmentBasinsGraph graph,
                                                                           int[] labels,
                                                                           java.awt.image.BufferedImage markers)
Paints the partition given by the labels used in the graph with the colors of the corresponding markers.

Parameters:
graph - a PrimitiveCatchmentBasinsGraph
labels - a labeling to the vertices of the graph
markers - the markers image used to obtain the partition
Returns:
the partition painted with the colors from the markers

paintPartitionFromColors

public static java.awt.image.BufferedImage paintPartitionFromColors(PrimitiveCatchmentBasinsGraph graph,
                                                                    java.awt.Color[] colors)
Paints each PrimitiveCatchmentBasin of the given graph with the corresponding Color in colors.

Parameters:
graph - a PrimitiveCatchmentBasinsGraph
colors - a coloring for the vertices of the graph
Returns:
the graph painted with the colors