Class 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)
    • Constructor Detail

      • XScreenMaskHelper

        public XScreenMaskHelper()
    • 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 processed
        color - 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 mask
        mask - generated mask
        threshold - threshold to binarize image, specify a negative value to automatically determine a threshold
        down - 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 mask
        threshold - threshold to binarize image, specify a negative value to automatically determine a threshold
        down - 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 process
        limit - 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 mask
        log - logger to be used to log the automatically determined threshold, can be null
        Returns:
        threshold value