//Source file: D:\\Projects\\src\\yi\\iu\\processor\\texture\\reg\\TextureLabRgnFtsPxlVal.java

package yi.iu.processor.texture.reg;

import yi.util.io.input.*;
import yi.util.config.*;
import yi.iu.imgdb.learn.FeatureRepresentationList;
import yi.iu.region.*;
import java.awt.Dimension;

public class TextureLabRgnFtsPxlVal extends LabeledRgnFtsWithPxlValue
{
  static final long serialVersionUID = -3333029850898861468L;

  public TextureLabRgnFtsPxlVal() {}

  public TextureLabRgnFtsPxlVal(double[][] gabors, int[] labels, int w, int h, int old_w, int old_h, boolean zeroAsBg, int ft_vect_dim)
  {
    super(gabors, labels, w, h, old_w, old_h, zeroAsBg, ft_vect_dim);
  }

  public LabeledRegionFeatures createFromFile(String processor_name, int scale, int rst_scale, String img) throws Exception {
    String scaled_img_name = img;
    if (scale != 0)
      scaled_img_name = img +
          yi.iu.processor.resample.Resampler.RESIZED_FILE_SUFFIX + scale;
    if (rst_scale != 0)
      scaled_img_name = scaled_img_name +
          ".r" + rst_scale;
    Configuration.setParameter("SOURCE_NAME", scaled_img_name);

    ColorGuidedTextureSeg dp = (ColorGuidedTextureSeg) Class.forName(processor_name).newInstance();

    TextureLabRgnFtsPxlVal ds = (TextureLabRgnFtsPxlVal) dp.reuseTextureLabRgnFtsPxlVal(DIU.
        INPUT_SER);

    return ds;
  }

  /**
   * Normalize the means as feature vectors
   * @return
   */
  protected double[][] generateFeatureVectors(String processor_name, int mode, Dimension fv_dim) {
    if (mode == 0) return super.generateFeatureVectors(processor_name, mode, fv_dim);

    fv_dim.width = m_ftVectDim;
    fv_dim.height = featureMeans.length;

    double[] normal_unit = {
        25.2,
        13.2,
        21.1,
        13.5,
        23.5,
        10.8,
        24.5,
        9.45,
        21.9,
        8.5,
        13.3,
        7.85
    };

    for (int i=0; i<featureMeans.length; i++) {
      if (featureMeans[i].length != normal_unit.length) {
        System.err.println("The data length " + featureMeans[i].length +
                           " is different from that assumed by normalization " +
                           normal_unit.length + ".  Normalization skipped");
        break;
      }
      for (int j=0; j<featureMeans[i].length; j++) {
        featureMeans[i][j] /= normal_unit[j];
      }
    }
    return featureMeans;
  }
}
