Example #1
0
  /*------------------------------------------------------------------*/
  void doIt(ImageProcessor ip) {
    int width = ip.getWidth();
    int height = ip.getHeight();
    double hLine[] = new double[width];
    double vLine[] = new double[height];

    if (!(ip.getPixels() instanceof float[])) {
      throw new IllegalArgumentException("Float image required");
    }
    switch (operation) {
      case GRADIENT_MAGNITUDE:
        {
          ImageProcessor h = ip.duplicate();
          ImageProcessor v = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsH = (float[]) h.getPixels();
          float[] floatPixelsV = (float[]) v.getPixels();

          getHorizontalGradient(h, FLT_EPSILON);
          getVerticalGradient(v, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              floatPixels[k] =
                  (float)
                      Math.sqrt(
                          floatPixelsH[k] * floatPixelsH[k] + floatPixelsV[k] * floatPixelsV[k]);
            }
            stepProgressBar();
          }
        }
        break;
      case GRADIENT_DIRECTION:
        {
          ImageProcessor h = ip.duplicate();
          ImageProcessor v = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsH = (float[]) h.getPixels();
          float[] floatPixelsV = (float[]) v.getPixels();

          getHorizontalGradient(h, FLT_EPSILON);
          getVerticalGradient(v, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              floatPixels[k] = (float) Math.atan2(floatPixelsH[k], floatPixelsV[k]);
            }
            stepProgressBar();
          }
        }
        break;
      case LAPLACIAN:
        {
          ImageProcessor hh = ip.duplicate();
          ImageProcessor vv = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsHH = (float[]) hh.getPixels();
          float[] floatPixelsVV = (float[]) vv.getPixels();

          getHorizontalHessian(hh, FLT_EPSILON);
          getVerticalHessian(vv, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              floatPixels[k] = (float) (floatPixelsHH[k] + floatPixelsVV[k]);
            }
            stepProgressBar();
          }
        }
        break;
      case LARGEST_HESSIAN:
        {
          ImageProcessor hh = ip.duplicate();
          ImageProcessor vv = ip.duplicate();
          ImageProcessor hv = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsHH = (float[]) hh.getPixels();
          float[] floatPixelsVV = (float[]) vv.getPixels();
          float[] floatPixelsHV = (float[]) hv.getPixels();

          getHorizontalHessian(hh, FLT_EPSILON);
          getVerticalHessian(vv, FLT_EPSILON);
          getCrossHessian(hv, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              floatPixels[k] =
                  (float)
                      (0.5
                          * (floatPixelsHH[k]
                              + floatPixelsVV[k]
                              + Math.sqrt(
                                  4.0 * floatPixelsHV[k] * floatPixelsHV[k]
                                      + (floatPixelsHH[k] - floatPixelsVV[k])
                                          * (floatPixelsHH[k] - floatPixelsVV[k]))));
            }
            stepProgressBar();
          }
        }
        break;
      case SMALLEST_HESSIAN:
        {
          ImageProcessor hh = ip.duplicate();
          ImageProcessor vv = ip.duplicate();
          ImageProcessor hv = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsHH = (float[]) hh.getPixels();
          float[] floatPixelsVV = (float[]) vv.getPixels();
          float[] floatPixelsHV = (float[]) hv.getPixels();

          getHorizontalHessian(hh, FLT_EPSILON);
          getVerticalHessian(vv, FLT_EPSILON);
          getCrossHessian(hv, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              floatPixels[k] =
                  (float)
                      (0.5
                          * (floatPixelsHH[k]
                              + floatPixelsVV[k]
                              - Math.sqrt(
                                  4.0 * floatPixelsHV[k] * floatPixelsHV[k]
                                      + (floatPixelsHH[k] - floatPixelsVV[k])
                                          * (floatPixelsHH[k] - floatPixelsVV[k]))));
            }
            stepProgressBar();
          }
        }
        break;
      case HESSIAN_ORIENTATION:
        {
          ImageProcessor hh = ip.duplicate();
          ImageProcessor vv = ip.duplicate();
          ImageProcessor hv = ip.duplicate();
          float[] floatPixels = (float[]) ip.getPixels();
          float[] floatPixelsHH = (float[]) hh.getPixels();
          float[] floatPixelsVV = (float[]) vv.getPixels();
          float[] floatPixelsHV = (float[]) hv.getPixels();

          getHorizontalHessian(hh, FLT_EPSILON);
          getVerticalHessian(vv, FLT_EPSILON);
          getCrossHessian(hv, FLT_EPSILON);
          for (int y = 0, k = 0; (y < height); y++) {
            for (int x = 0; (x < width); x++, k++) {
              if (floatPixelsHV[k] < 0.0) {
                floatPixels[k] =
                    (float)
                        (-0.5
                            * Math.acos(
                                (floatPixelsHH[k] - floatPixelsVV[k])
                                    / Math.sqrt(
                                        4.0 * floatPixelsHV[k] * floatPixelsHV[k]
                                            + (floatPixelsHH[k] - floatPixelsVV[k])
                                                * (floatPixelsHH[k] - floatPixelsVV[k]))));
              } else {
                floatPixels[k] =
                    (float)
                        (0.5
                            * Math.acos(
                                (floatPixelsHH[k] - floatPixelsVV[k])
                                    / Math.sqrt(
                                        4.0 * floatPixelsHV[k] * floatPixelsHV[k]
                                            + (floatPixelsHH[k] - floatPixelsVV[k])
                                                * (floatPixelsHH[k] - floatPixelsVV[k]))));
              }
            }
            stepProgressBar();
          }
        }
        break;
      default:
        throw new IllegalArgumentException("Invalid operation");
    }
    ip.resetMinAndMax();
    imp.updateAndDraw();
  } /* end doIt */