Example #1
0
  public void accumulateBilinear(double x, double y, double s)
        /* Bilinearly accumulates 's' to the four integer grid points surrounding
         *   the continuous coordinate (x, y). */
      {
    double xpf = Math.floor(x);
    int xi = (int) xpf;
    double xf = x - xpf;

    double ypf = Math.floor(y);
    int yi = (int) ypf;
    double yf = y - ypf;

    double b;
    b = (1.0 - xf) * (1.0 - yf);
    accumulate(xi, yi, s * b);
    b = xf * (1.0 - yf);
    accumulate(xi + 1, yi, s * b);
    b = (1.0 - xf) * yf;
    accumulate(xi, yi + 1, s * b);
    b = xf * yf;
    accumulate(xi + 1, yi + 1, s * b);
  }
Example #2
0
  public double getBilinear(double x, double y)
        /* Returns: the bilinearly-interpolated value of the continuous field
         *   at (x, y).
         * Requires: (x, y) is inside the domain of the field */
      {
    if (!inBounds(x, y))
      throw new RuntimeException(
          "ScalarImage.getBilinear: RuntimeException at (" + x + "," + y + ")");

    int xi, yi;
    double xf, yf;
    if (x == (double) (width - 1)) {
      xi = width - 2;
      xf = 1.0;
    } else {
      double xpf = Math.floor(x);
      xi = (int) xpf;
      xf = x - xpf;
    }
    if (y == (double) (height - 1)) {
      yi = height - 2;
      yf = 1.0;
    } else {
      double ypf = Math.floor(y);
      yi = (int) ypf;
      yf = y - ypf;
    }

    double b1 = get(xi, yi);
    double b2 = get(xi + 1, yi);
    double b3 = get(xi, yi + 1);
    double b4 = get(xi + 1, yi + 1);

    double bb1 = b1 + xf * (b2 - b1);
    double bb2 = b3 + xf * (b4 - b3);

    return bb1 + yf * (bb2 - bb1);
  }
Example #3
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);
    */
  }