package yi.iu.processor.color.reg;

import yi.util.config.*;
import yi.util.io.*;
import java.awt.*;
import yi.iu.processor.resample.*;
import yi.iu.processor.color.reg.merge.*;
import yi.util.label.Label;


/**
 * Segment images to patches of mxn
 */
public class ColorPatchSeg extends KMeansHSISeg
{
  public int PATCH_HEIGHT = 16;
  public int PATCH_WIDTH = 16;

  public ColorPatchSeg()
  {
  }

  /**
   * Segment the image.  Simple segment them to patches of mxn
   * @param pixels
   * @param d
   * @return
   */
  public int[] seg(int[] pixels, Dimension d)
  {
    int[] labels = Label.labelPatches(d.width, d.height, PATCH_WIDTH, PATCH_HEIGHT);
    return labels;
  }

//  public static void main(String[] args)
//  {
//   // init configuration
//   Configuration.init(args);
//
//   // get the image name
//   String img_name = ReadArgu.getOption('i', args);
//   if (img_name == null) {
//     System.err.println("Usage: -i image_name");
//     System.exit(1);
//   }
//
//   // get the scale
//   String scale_str = ReadArgu.getOption('s', args);
//   int scale = 1;
//   if (scale_str != null) {
//     scale = Integer.parseInt(scale_str);
//   }
//
//   // read in image
//   Image image = yi.util.io.ImageReader.JAIReadImage(img_name);
//   Dimension d = new Dimension();
//   int[] pixels = yi.util.io.ImageReader.getPixels(image, d);
//
//   // rescale the image if necessary
//   double the_scale = 1.0;
//   if (scale != 1) {
//     ColorPatchSeg dummy = new ColorPatchSeg();
//     ResampledDescriptor resampled = Resampler.scaleDown(pixels, d,
//         dummy.RESAMPLER, scale);
//     if (resampled != null) {
//       pixels = resampled.m_resampled;
//       d = resampled.m_newDimension;
//       the_scale = resampled.m_scale;
//       img_name = img_name + Resampler.RESIZED_FILE_SUFFIX + scale;
//     }
//   }
//
//   try {
//     // process
//     Configuration.setParameter("SOURCE_NAME", img_name);
//     yi.util.ImageUtil.setPixels(pixels);
//     yi.util.ImageUtil.setDimension(d);
//
//     long startTime = System.currentTimeMillis();
//     ColorPatchSeg processor = new ColorPatchSeg();
//     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);
//     yi.util.io.OutputResult.outputGIFImage(img_name + ".color.reg.gif", demo, d.width,
//                                            d.height, false);
//
//
//   } catch (Exception e) {
//     System.err.println("KMeansHSISeg Terminated.");
//     e.printStackTrace();
//   }
//
//    System.exit(0);
//  }

}
