package yi.iu.processor.color.reg.merge;

import java.awt.*;

import yi.iu.processor.*;
import yi.iu.processor.color.reg.*;
import yi.iu.processor.resample.*;

/**
 * KMeansHSISegDemo is the demo wrapper for KMeansHSISeg
 */

public class KMeansHSISegDemo extends ImageProcessor{

  public int scale = 256;

  public int[] getProcessedPseudoColor(int pixels[], Dimension d)
  {

    Dimension old_d = (Dimension)d.clone();

    double the_scale = 1.0;
    if (scale != 1) {
      KMeansHSISeg dummy = new KMeansHSISeg();
      ResampledDescriptor resampled = Resampler.scaleDown(pixels, d,
          dummy.RESAMPLER, scale);
      if (resampled != null) {
        pixels = resampled.m_resampled;
        d.width = resampled.m_newDimension.width;
        d.height = resampled.m_newDimension.height;
        the_scale = resampled.m_scale;
      }
    }

    // process
    try {

//      long startTime = System.currentTimeMillis();
//      KMeansHSISeg processor = new KMeansHSISeg();
//      DS_PolygonRegionColorStat ds = processor.getReusablePolygonRegionColorStat(
//          pixels, d.width, d.height, the_scale);
//      long endTime = System.currentTimeMillis();
//      System.out.println("running time: " + (endTime-startTime));
//
//      int[] demo = ds.getPolygonDemo(null, true);
//      return demo;

      long startTime = System.currentTimeMillis();
      KMeansHSISeg processor = new KMeansHSISeg();
      ColorLabRgnFtsPxlVal ds = processor.getReusableColorLabRgnFtsPxlVal(
          pixels, d.width, d.height, old_d.width, old_d.height);
      long endTime = System.currentTimeMillis();
      System.out.println("running time: " + (endTime-startTime));


      int[] cdemo = ds.colorDemo();
      return cdemo;

    } catch (Exception e) {
      System.err.println("broken when processing... ");
      e.printStackTrace();
    }
    return null;
  }

  public int[] getProcessed(int source[], Dimension d) {return null;}

}
