Package adams.data.image
Class XScreenMaskHelper
- java.lang.Object
-
- adams.data.image.XScreenMaskHelper
-
public class XScreenMaskHelper extends Object
Helper class for masking out colors (like green screening).- Version:
- $Revision$
- Author:
- lx51 (lx51 at students dot waikato dot ac dot nz)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XScreenMaskHelper.Color
Colors that can be masked.
-
Constructor Summary
Constructors Constructor Description XScreenMaskHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BufferedImage
applyMask(BufferedImage image, int[][] mask, int threshold, boolean down, Logger log)
Given a previously generated mask, this uses the data to mask an image.static void
binarizeMask(int[][] mask, int threshold, boolean down, Logger log)
Given a previously generated mask, this binarizes the mask given a threshold.static int
determineThreshold(int[][] mask, Logger log)
Determine an optimal threshold value.protected static int
findThreshold(int[] histogram, int limit)
Finds the threshold in the normalized histogram.static int[][]
generateMask(BufferedImage image, XScreenMaskHelper.Color color)
Generate a color mask indicating how similar each pixel is to the selected color.
-
-
-
Method Detail
-
generateMask
public static int[][] generateMask(BufferedImage image, XScreenMaskHelper.Color color)
Generate a color mask indicating how similar each pixel is to the selected color. The mask is normalized to 0 and 255, with 0 being not similar and 255 being very similar.- Parameters:
image
- image to be processedcolor
- color to apply mask- Returns:
- a normalized mask between 0 and 255
-
applyMask
public static BufferedImage applyMask(BufferedImage image, int[][] mask, int threshold, boolean down, Logger log)
Given a previously generated mask, this uses the data to mask an image.- Parameters:
image
- image to maskmask
- generated maskthreshold
- threshold to binarize image, specify a negative value to automatically determine a thresholddown
- if true, then pixels <= threshold are not masked and the others' alpha channel are set to 0 (made transparent)log
- logger to be used to log the automatically determined threshold, can be null- Returns:
- masked image, type ARGB
-
binarizeMask
public static void binarizeMask(int[][] mask, int threshold, boolean down, Logger log)
Given a previously generated mask, this binarizes the mask given a threshold.- Parameters:
mask
- generated maskthreshold
- threshold to binarize image, specify a negative value to automatically determine a thresholddown
- if true, then pixels <= threshold are not masked and the others' alpha channel are set to 0 (made transparent)log
- logger to be used to log the automatically determined threshold, can be null
-
findThreshold
protected static int findThreshold(int[] histogram, int limit)
Finds the threshold in the normalized histogram.- Parameters:
histogram
- the histogram to processlimit
- the limit to use- Returns:
- the index in the histogram
-
determineThreshold
public static int determineThreshold(int[][] mask, Logger log)
Determine an optimal threshold value. A normalized histogram is calculated, assuming two peaks, the threshold begins in the middle, walking right until it hits the right peak, or left until it is walks off the peak.- Parameters:
mask
- generated masklog
- logger to be used to log the automatically determined threshold, can be null- Returns:
- threshold value
-
-