Package ca.cgjennings.graphics
Class Histogram
- java.lang.Object
-
- ca.cgjennings.graphics.Histogram
-
public class Histogram extends java.lang.ObjectAn image histogram contains information about the distribution of channel values in an image.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Field Summary
Fields Modifier and Type Field Description static intALPHAA mask value to include the alpha channel in the histogram.static intBLUEA mask value to include the blue channel in the histogram.static intGREENA mask value to include the green channel in the histogram.static intREDA mask value to include the red channel in the histogram.
-
Constructor Summary
Constructors Constructor Description Histogram()Creates a new, empty histogram.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.awt.image.BufferedImagecreateHistogramImage(java.awt.image.BufferedImage src)A utility method that creates an image of the histogram for an image, averaging the red, green, and blue channels together.static java.awt.image.BufferedImagecreateRGBHistogramImage(java.awt.image.BufferedImage src)A utility method that creates an image of the histogram for an image, showing separate red, green, and blue channels.intgetChannelMask()Returns the channel mask for the histogram.intgetCountForLevel(int level)Returns the number of samples counted for the given level.intgetMaximumCount()Returns the maximum count for any level.doublegetRelativeCountForLevel(int level)Returns the relative number of samples counted for the given level.intgetSampleCount()Returns the total number of samples that have been measured.booleanisZeroAlphaIgnored()Returnstrueif pixels with an alpha of zero will not be included in the histogram.voidmeasure(int[] image)Measures the samples in an array of pixel data and incorporates them into the histogram statistics.voidmeasure(java.awt.image.BufferedImage image)Measures the samples in an image and incorporates them into the histogram statistics.voidreset()Resets the histogram statistics.voidsetChannelMask(int mask)Sets the channel mask for the histogram.voidsetZeroAlphaIgnored(boolean ignoreZeroAlpha)Sets whether pixels with an alpha value of zero should be ignored.
-
-
-
Field Detail
-
BLUE
public static final int BLUE
A mask value to include the blue channel in the histogram.- See Also:
- Constant Field Values
-
GREEN
public static final int GREEN
A mask value to include the green channel in the histogram.- See Also:
- Constant Field Values
-
RED
public static final int RED
A mask value to include the red channel in the histogram.- See Also:
- Constant Field Values
-
ALPHA
public static final int ALPHA
A mask value to include the alpha channel in the histogram.- See Also:
- Constant Field Values
-
-
Method Detail
-
isZeroAlphaIgnored
public boolean isZeroAlphaIgnored()
Returnstrueif pixels with an alpha of zero will not be included in the histogram.- Returns:
trueif transparent pixels are ignored
-
setZeroAlphaIgnored
public void setZeroAlphaIgnored(boolean ignoreZeroAlpha)
Sets whether pixels with an alpha value of zero should be ignored. Ignored pixels are not counted in the histogram statistics.- Parameters:
ignoreZeroAlpha-trueto ignore transparent pixels
-
getChannelMask
public int getChannelMask()
Returns the channel mask for the histogram.- Returns:
- the bitwise-or of mask values for the channels included in the histogram
- See Also:
setChannelMask(int)
-
setChannelMask
public void setChannelMask(int mask)
Sets the channel mask for the histogram. The channel mask determines which channels of the image will be included in the histogram count. For a given pixel, the level measured by the histogram will be the mean of the channels included by the mask. The mask value is a bitwise-or of some combination ofRED,GREEN,BLUE, andALPHA. At least one channel must be specified by the mask.- Parameters:
mask- the bitwise-or of the channel masks for the channels to include
-
measure
public void measure(java.awt.image.BufferedImage image)
Measures the samples in an image and incorporates them into the histogram statistics. All channels indicated by thechannelMaskwill be averaged together to determine the histogram bucket.- Parameters:
image- the image to analyze
-
measure
public void measure(int[] image)
Measures the samples in an array of pixel data and incorporates them into the histogram statistics. All channels indicated by thechannelMaskwill be averaged together to determine the histogram bucket.- Parameters:
image- the image to analyze
-
reset
public void reset()
Resets the histogram statistics.
-
getCountForLevel
public int getCountForLevel(int level)
Returns the number of samples counted for the given level.- Parameters:
level- the level to return the histogram count for (0-255)- Returns:
- the number of samples counted at this level
-
getRelativeCountForLevel
public double getRelativeCountForLevel(int level)
Returns the relative number of samples counted for the given level.- Parameters:
level- the level to return the histogram count for (0-255)- Returns:
- the number of samples counted at this level over the total samples counted, from 0 to 1
-
getMaximumCount
public int getMaximumCount()
Returns the maximum count for any level.- Returns:
- the largest count value
-
getSampleCount
public int getSampleCount()
Returns the total number of samples that have been measured.- Returns:
- the number of pixels processed
-
createHistogramImage
public static java.awt.image.BufferedImage createHistogramImage(java.awt.image.BufferedImage src)
A utility method that creates an image of the histogram for an image, averaging the red, green, and blue channels together.- Parameters:
src- the image to analyze- Returns:
- a simple graph of the image's histogram
-
createRGBHistogramImage
public static java.awt.image.BufferedImage createRGBHistogramImage(java.awt.image.BufferedImage src)
A utility method that creates an image of the histogram for an image, showing separate red, green, and blue channels.- Parameters:
src- the image to analyze- Returns:
- a simple graph of the image's histogram
-
-