コード例 #1
0
ファイル: DescribePointSift.java プロジェクト: hzqhssn/BoofCV
  private void constructHistograms(double c_x, double c_y, double scale, double orientation) {
    double c = Math.cos(orientation);
    double s = Math.sin(orientation);

    int gridRadius = gridWidth / 2;

    // This is the distance between samples
    // The size is computed by finding the width of one block in the grid, then dividing by the
    // number of samples along that side
    double sampleUnit = (2.0 * scale * sigmaToRadius) / numSamples;
    // how wide a grid cell is in pixels
    double gridCellLength = numSamples * sampleUnit;
    int gridCellLengthI = (int) (gridCellLength + 0.5); // round to int

    //		System.out.println("-----------------------------------------");
    //		System.out.println("  cell length "+gridCellLength);
    //		System.out.println("  sampleUnit "+sampleUnit);

    int allSampleIndex = 0;
    for (int gy = 0; gy < gridWidth; gy++) {
      double gridY = (gy - gridRadius) * gridCellLength;
      for (int gx = 0; gx < gridWidth; gx++) {
        // top left coordinate of grid in pixels
        double gridX = (gx - gridRadius) * gridCellLength;

        // TODO Sample all pixels here
        for (int sy = 0; sy < numSamples; sy++) {
          double y = sy * sampleUnit + gridY;
          for (int sx = 0; sx < numSamples; sx++, allSampleIndex++) {
            // Sample point in pixels in grid coordinate system
            double x = sx * sampleUnit + gridX;

            // Rotate and translate into image pixel coordinates, then round
            int px = (int) (x * c - y * s + c_x + 0.5);
            int py = (int) (x * s + y * c + c_y + 0.5);

            if (image.isInBounds(px, py)) {
              double dx = derivX.unsafe_get(px, py);
              double dy = derivY.unsafe_get(px, py);

              // Gaussian weighting applied to whole sample area
              double w = gridWeights[allSampleIndex];

              // rotate derivative into grid coordinate system
              double adjX = (dx * c + dy * s) * w;
              double adjY = (-dx * s + dy * c) * w;

              addToHistograms(
                  gx - gridRadius,
                  gy - gridRadius,
                  x / gridCellLength,
                  y / gridCellLength,
                  adjX,
                  adjY);
            }
          }
        }
      }
    }
  }
コード例 #2
0
  /** Sets a rectangle inside the image with the specified value. */
  public static void fillRectangle(
      ImageFloat32 img, float value, int x0, int y0, int width, int height) {
    int x1 = x0 + width;
    int y1 = y0 + height;

    for (int y = y0; y < y1; y++) {
      for (int x = x0; x < x1; x++) {
        if (img.isInBounds(x, y)) img.set(x, y, value);
      }
    }
  }
コード例 #3
0
  public void checkBorder(ImageFloat32 image, int c_x, int c_y, int w, int h) {
    ImplDescribePointPixelRegion_F32 alg = new ImplDescribePointPixelRegion_F32(w, h);

    TupleDesc_F32 desc = new TupleDesc_F32(alg.getDescriptorLength());
    alg.setImage(image);
    alg.process(c_x, c_y, desc);

    int index = 0;
    int y0 = c_y - h / 2;
    int x0 = c_x - w / 2;
    for (int y = y0; y < y0 + h; y++) {
      for (int x = x0; x < x0 + w; x++, index++) {
        if (image.isInBounds(x, y)) assertEquals(image.get(x, y), desc.value[index], 1e-4);
        else assertEquals(0, desc.value[index], 1e-4);
      }
    }
  }