Exemplo n.º 1
0
 public void launch(String[] args) {
   try {
     // make_dir(args[0]);
     // get_file(args[0]);
     // Cloner(args[0], args[1]);
     csvAverage(args[0]);
   } catch (ArrayIndexOutOfBoundsException n) {
     System.out.println("oops looks like you forgot to add an arg");
     n.printStackTrace();
   }
 }
Exemplo n.º 2
0
  public void analyze(boolean doit) {

    float min = Float.POSITIVE_INFINITY;
    float max = Float.NEGATIVE_INFINITY;
    for (int k = 0; k < size; k++) {
      //    	System.out.println(f[k]);
      /*
       * if (f[k] == Float.NaN) { System.out.println("NaN at k= "+k);
       * f[k] = 0f; }
       */
      if (Float.isNaN(f[k])) {
        System.out.println("NaN at k= " + k);
        f[k] = 0f;
        continue;
      }
      if (Float.isInfinite(f[k])) {
        if (f[k] < 0) {
          System.out.println("-Infinity at k= " + k);
          f[k] = 0f; // -1000f;
        } else {
          System.out.println("+Infinity at k= " + k);
          f[k] = 0f; // +1000f;
        }
        continue;
      }
      // System.out.print(k +"="+f[k]+ ", ");
      min = Math.min(min, f[k]);
      max = Math.max(max, f[k]);
    }

    int N = 256;
    float[] histogram = new float[N];

    for (int k = 0; k < size; k++) {
      int level = (int) (0.999f * (float) N * (f[k] - min) / (max - min));
      try {
        histogram[level]++;
      } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("ArrayIndexOutOfBoundsException in ScalarImage.analyze(double) [A].");
      }
    }

    float[] cumulative = new float[N];
    if (histogram[0] > 0) {
      if (doit) {
        cumulative[0] = histogram[0];
      } else {
        cumulative[0] = 1; // histogram[0];
      }
    }
    for (int i = 1; i < N; i++) {
      if (histogram[i] > 0) {
        if (doit) {
          cumulative[i] = cumulative[i - 1] + histogram[i];
        } else {
          cumulative[i] = cumulative[i - 1] + 1; // histogram[i];
        }
      } else {
        cumulative[i] = cumulative[i - 1];
      }
    }

    /*		for(int k=0; k<size; k++) {
    			int level = (int) ( 0.999f*(float)N*(f[k]-min)/(max-min) );
    			try {
    				f[k]=(cumulative[level]-cumulative[0])/(cumulative[N-1]-cumulative[0]);
    			} catch( ArrayIndexOutOfBoundsException e) {
    				System.out.println("ArrayIndexOutOfBoundsException in ScalarImage.analyze(double) [B].");
    			}
    		}
    */
    for (int k = 0; k < size; k++) {
      float x, x1, x2, f1, f2;
      try {
        x = Math.abs((f[k] - min) / (max - min));
        x1 = (float) Math.floor((float) (N - 1) * x * 0.999f) / (float) (N - 1);
        x2 = (float) Math.ceil((float) (N - 1) * x * 0.999f) / (float) (N - 1);
        f1 =
            (cumulative[(int) Math.floor((float) (N - 1) * x * 0.999f)] - cumulative[0])
                / (cumulative[N - 1] - cumulative[0]);
        f2 =
            (cumulative[(int) Math.ceil((float) (N - 1) * x * 0.999f)] - cumulative[0])
                / (cumulative[N - 1] - cumulative[0]);
        f[k] = (f2 - f1) * (x - x1) / (x2 - x1) + f1;
      } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println(
            "ArrayIndexOutOfBoundsException in ScalarImage.analyze(double) [C]. " + e.getMessage());
      }
    }

    return;

    /*
    		double offset = 0. - min;
    		if ((max - min) != 0f) {
    			scale /= (max - min);
    			offset *= scale;
    			rescale(scale, offset);
    		}
    		System.out.println("Normalizing using: min= " + min + " max= " + max
    				+ ", through scaleAdd(" + scale + ", " + offset + ").");
    		min = 1000f;
    		max = -1000f;
    		for (int k = 0; k < size; k++) {
    			if (Float.isNaN(f[k])) {
    				System.out.println("NaN at k= " + k + " after normalization.");
    				f[k] = 0f;
    				continue;
    			}
    			min = Math.min(min, f[k]);
    			max = Math.max(max, f[k]);
    		}
    		System.out.println("After normalization: min= " + min + " max= " + max);
    */
  }