//Source file: D:\\Projects\\src\\yi\\iu\\processor\\color\\reg\\PolygonRegionColorStat.java

package yi.iu.processor.color.reg;

import yi.iu.region.*;
import yi.ds.*;
import java.util.LinkedList;

/**
PolygonRegionColorStat is basically a RgbColorRegion.  The differences
are * it provides the variance of the colors besides the mean (the color
in the region may be not just from a single color).  The region is not a
Region which can be used to represent the region with an ellipse, but a
PolygonRegion which can be used to represent the region as a polygon
 */
public class PolygonRegionColorStat extends PolygonRegionFeatureStat
{

   /**
   @param feature
   @roseuid 3F994F9C0243
    */
   public PolygonRegionColorStat(PolygonRegionFeatureStat feature)
   {
    super(feature.getMean(), feature.getCovariance(), feature.getPolygonRegion());
   }

   /**
   @param mean
   @param covariance
   @param region
   @roseuid 3F994F9C0224
    */
   public PolygonRegionColorStat(double[] mean, double[][] covariance, PolygonRegion region)
   {
    super(mean, covariance, region);
   }

   /**
   @roseuid 3F994F9C0223
    */
   public PolygonRegionColorStat()
   {
    super();
   }

   /**
   Calculate the multiple rgb color polygon regions from an image
   @param rgb
   @param labels
   @param width
   @param height
   @return
   @roseuid 3F994F9C0252
    */
   public static PolygonRegionFeatureStat[] getStatRgbColorPolygonRegions(int[] rgb, int[] labels, int width, int height)
   {
    double[][] data = new double[rgb.length][3];
    for (int i = 0; i < rgb.length; i++) {
      data[i][0] = (rgb[i] >> 16) & 0xff;
      data[i][1] = (rgb[i] >> 8) & 0xff;
      data[i][2] = rgb[i] & 0xff;
    }
    PolygonRegionFeatureStat[] rst = createPolygonRegionFeatureStats(data, labels, width, height, false);
    for (int i=0; i<rst.length; i++) {
      rst[i] = new PolygonRegionColorStat(rst[i]);
    }
    return rst;
   }

}