Esempio n. 1
0
 public double cval(double td) {
   if (td == 0) return (1.0);
   else if ((td < -sz) || (td > sz)) return (0.0);
   double tdp = td * Math.PI;
   double wtdp = tdp / sz;
   return ((Math.sin(tdp) / tdp) * (Math.sin(wtdp) / wtdp));
 }
Esempio n. 2
0
  public void method352(
      int i, int j, int ai[], int k, int ai1[], int i1, int j1, int k1, int l1, int i2) {
    try {
      int j2 = -l1 / 2;
      int k2 = -i / 2;
      int l2 = (int) (Math.sin((double) j / 326.11000000000001D) * 65536D);
      int i3 = (int) (Math.cos((double) j / 326.11000000000001D) * 65536D);
      l2 = l2 * k >> 8;
      i3 = i3 * k >> 8;
      int j3 = (i2 << 16) + (k2 * l2 + j2 * i3);
      int k3 = (i1 << 16) + (k2 * i3 - j2 * l2);
      int l3 = k1 + j1 * DrawingArea.width;
      for (j1 = 0; j1 < i; j1++) {
        int i4 = ai1[j1];
        int j4 = l3 + i4;
        int k4 = j3 + i3 * i4;
        int l4 = k3 - l2 * i4;
        for (k1 = -ai[j1]; k1 < 0; k1++) {
          DrawingArea.pixels[j4++] = myPixels[(k4 >> 16) + (l4 >> 16) * myWidth];
          k4 += i3;
          l4 -= l2;
        }

        j3 += l2;
        k3 += i3;
        l3 += DrawingArea.width;
      }

    } catch (Exception _ex) {
    }
  }
Esempio n. 3
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);

    int width = src.getWidth();
    int height = src.getHeight();
    int numScratches = (int) (density * width * height / 100);
    ArrayList<Line2D> lines = new ArrayList<Line2D>();
    {
      float l = length * width;
      Random random = new Random(seed);
      Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(new Color(color));
      g.setStroke(new BasicStroke(this.width));
      for (int i = 0; i < numScratches; i++) {
        float x = width * random.nextFloat();
        float y = height * random.nextFloat();
        float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
        float s = (float) Math.sin(a) * l;
        float c = (float) Math.cos(a) * l;
        float x1 = x - c;
        float y1 = y - s;
        float x2 = x + c;
        float y2 = y + s;
        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
        lines.add(new Line2D.Float(x1, y1, x2, y2));
      }
      g.dispose();
    }

    if (false) {
      //		int[] inPixels = getRGB( src, 0, 0, width, height, null );
      int[] inPixels = new int[width * height];
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float sx = x, sy = y;
          for (int i = 0; i < numScratches; i++) {
            Line2D.Float l = (Line2D.Float) lines.get(i);
            float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
            if (dot > 0) inPixels[index] |= (1 << i);
          }
          index++;
        }
      }

      Colormap colormap = new LinearColormap();
      index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
          inPixels[index] = colormap.getColor(f);
          index++;
        }
      }
      setRGB(dst, 0, 0, width, height, inPixels);
    }
    return dst;
  }
 private void initialize() {
   sinTable = new float[256];
   cosTable = new float[256];
   for (int i = 0; i < 256; i++) {
     float angle = ImageMath.TWO_PI * i / 256f * turbulence;
     sinTable[i] = (float) (-yScale * Math.sin(angle));
     cosTable[i] = (float) (yScale * Math.cos(angle));
   }
 }
Esempio n. 5
0
 /**
  * Prepare the light for rendering.
  *
  * @param width the output image width
  * @param height the output image height
  */
 public void prepare(int width, int height) {
   float lx = (float) (Math.cos(azimuth) * Math.cos(elevation));
   float ly = (float) (Math.sin(azimuth) * Math.cos(elevation));
   float lz = (float) Math.sin(elevation);
   direction = new Vector3f(lx, ly, lz);
   direction.normalize();
   if (type != DISTANT) {
     lx *= distance;
     ly *= distance;
     lz *= distance;
     lx += width * centreX;
     ly += height * centreY;
   }
   position = new Vector3f(lx, ly, lz);
   realColor.set(new Color(color));
   realColor.scale(intensity);
   cosConeAngle = (float) Math.cos(coneAngle);
 }
Esempio n. 6
0
  public NTSCRenderer() {
    int hue = -512;
    double col_adjust = 1.2 / .707;
    for (int j = 0; j < 12; ++j) {
      float angle = (float) (Math.PI * ((hue + (j << 8)) / (12 * 128.0) - 33.0 / 180));
      i_filter[j] = (float) (-col_adjust * Math.cos(angle));
      q_filter[j] = (float) (col_adjust * Math.sin(angle));
    }
    //        utils.printarray(i_filter);
    //        utils.printarray(q_filter);

  }
Esempio n. 7
0
 public void fellipse(Coord c, Coord r, int a1, int a2) {
   st.set(cur2d);
   apply();
   gl.glBegin(GL.GL_TRIANGLE_FAN);
   vertex(c);
   for (int i = a1; i <= a2; i += 5) {
     double a = (i * Math.PI * 2) / 360.0;
     vertex(c.add((int) (Math.cos(a) * r.x), -(int) (Math.sin(a) * r.y)));
   }
   gl.glEnd();
   checkerr();
 }
Esempio n. 8
0
 protected void transformInverse(int x, int y, float[] out) {
   float dx = x - icentreX;
   float dy = y - icentreY;
   float distance = dx * dx + dy * dy;
   if (distance > radius2) {
     out[0] = x;
     out[1] = y;
   } else {
     distance = (float) Math.sqrt(distance);
     float a = (float) Math.atan2(dy, dx) + angle * (radius - distance) / radius;
     out[0] = icentreX + distance * (float) Math.cos(a);
     out[1] = icentreY + distance * (float) Math.sin(a);
   }
 }
Esempio n. 9
0
  /** Recalculates the (x,y) point used to indicate the selected color. */
  private void regeneratePoint() {
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));
    if (mode == ColorPicker.HUE || mode == ColorPicker.SAT || mode == ColorPicker.BRI) {
      if (mode == ColorPicker.HUE) {
        point = new Point((int) (sat * size), (int) (bri * size));
      } else if (mode == ColorPicker.SAT) {
        double theta = hue * 2 * Math.PI - Math.PI / 2;
        if (theta < 0) theta += 2 * Math.PI;

        double r = bri * size / 2;
        point =
            new Point(
                (int) (r * Math.cos(theta) + .5 + size / 2.0),
                (int) (r * Math.sin(theta) + .5 + size / 2.0));
      } else if (mode == ColorPicker.BRI) {
        double theta = hue * 2 * Math.PI - Math.PI / 2;
        if (theta < 0) theta += 2 * Math.PI;
        double r = sat * size / 2;
        point =
            new Point(
                (int) (r * Math.cos(theta) + .5 + size / 2.0),
                (int) (r * Math.sin(theta) + .5 + size / 2.0));
      }
    } else if (mode == ColorPicker.RED) {
      point = new Point((int) (green * size / 255f + .49f), (int) (blue * size / 255f + .49f));
    } else if (mode == ColorPicker.GREEN) {
      point = new Point((int) (red * size / 255f + .49f), (int) (blue * size / 255f + .49f));
    } else if (mode == ColorPicker.BLUE) {
      point = new Point((int) (red * size / 255f + .49f), (int) (green * size / 255f + .49f));
    }
  }
Esempio n. 10
0
 private Path2D.Double makeStar(int r1, int r2, int vc) {
   int or = Math.max(r1, r2);
   int ir = Math.min(r1, r2);
   double agl = 0d;
   double add = 2 * Math.PI / (vc * 2);
   Path2D.Double p = new Path2D.Double();
   p.moveTo(or * 1, or * 0);
   for (int i = 0; i < vc * 2 - 1; i++) {
     agl += add;
     int r = i % 2 == 0 ? ir : or;
     p.lineTo(r * Math.cos(agl), r * Math.sin(agl));
   }
   p.closePath();
   AffineTransform at = AffineTransform.getRotateInstance(-Math.PI / 2, or, 0);
   return new Path2D.Double(p, at);
 }
Esempio n. 11
0
  public void method353(int i, double d, int l1) {
    // all of the following were parameters
    int j = 15;
    int k = 20;
    int l = 15;
    int j1 = 256;
    int k1 = 20;
    // all of the previous were parameters
    try {
      int i2 = -k / 2;
      int j2 = -k1 / 2;
      int k2 = (int) (Math.sin(d) * 65536D);
      int l2 = (int) (Math.cos(d) * 65536D);
      k2 = k2 * j1 >> 8;
      l2 = l2 * j1 >> 8;
      int i3 = (l << 16) + (j2 * k2 + i2 * l2);
      int j3 = (j << 16) + (j2 * l2 - i2 * k2);
      int k3 = l1 + i * DrawingArea.width;
      for (i = 0; i < k1; i++) {
        int l3 = k3;
        int i4 = i3;
        int j4 = j3;
        for (l1 = -k; l1 < 0; l1++) {
          int k4 = myPixels[(i4 >> 16) + (j4 >> 16) * myWidth];
          if (k4 != 0) DrawingArea.pixels[l3++] = k4;
          else l3++;
          i4 += l2;
          j4 -= k2;
        }

        i3 += k2;
        j3 += l2;
        k3 += DrawingArea.width;
      }

    } catch (Exception _ex) {
    }
  }
Esempio n. 12
0
  private void spawnCircles() {
    if (circular) {
      for (int i = 0; i < ballN; i++) {
        double degree = Math.random() * 2 * Math.PI;
        float x = ((Player) players.get(0)).getX() + distance * (float) Math.sin(degree * i);
        float y = ((Player) players.get(0)).getY() + distance * (float) Math.cos(degree * i);
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    } else {
      for (int i = 1; i < (ballN / 2); i++) {
        float x = (i * 2 * width) / (ballN);
        float y = 0;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }

      for (int i = (ballN / 2) + 1; i < ballN; i++) {
        float x = ((i - ballN / 2) * 2 * width) / ballN;
        float y = height;
        enemies.add(new EnemyTypes.Circle(x, y, invSpeed));
      }
    }
    spawnIncrease = false;
  }
Esempio n. 13
0
  private int getEnvironmentMap(Vector3f normal, int[] inPixels, int width, int height) {
    if (environmentMap != null) {
      float angle = (float) Math.acos(-normal.y);

      float x, y;
      y = angle / ImageMath.PI;

      if (y == 0.0f || y == 1.0f) x = 0.0f;
      else {
        float f = normal.x / (float) Math.sin(angle);

        if (f > 1.0f) f = 1.0f;
        else if (f < -1.0f) f = -1.0f;

        x = (float) Math.acos(f) / ImageMath.PI;
      }
      // A bit of empirical scaling....
      x = ImageMath.clamp(x * envWidth, 0, envWidth - 1);
      y = ImageMath.clamp(y * envHeight, 0, envHeight - 1);
      int ix = (int) x;
      int iy = (int) y;

      float xWeight = x - ix;
      float yWeight = y - iy;
      int i = envWidth * iy + ix;
      int dx = ix == envWidth - 1 ? 0 : 1;
      int dy = iy == envHeight - 1 ? 0 : envWidth;
      return ImageMath.bilinearInterpolate(
          xWeight,
          yWeight,
          envPixels[i],
          envPixels[i + dx],
          envPixels[i + dy],
          envPixels[i + dx + dy]);
    }
    return 0;
  }
Esempio n. 14
0
  /** Rotate theta degrees about the x axis */
  void xrot(double theta) {
    theta *= (pi / 180);
    double ct = Math.cos(theta);
    double st = Math.sin(theta);

    double Nyx = (yx * ct + zx * st);
    double Nyy = (yy * ct + zy * st);
    double Nyz = (yz * ct + zz * st);
    double Nyo = (yo * ct + zo * st);

    double Nzx = (zx * ct - yx * st);
    double Nzy = (zy * ct - yy * st);
    double Nzz = (zz * ct - yz * st);
    double Nzo = (zo * ct - yo * st);

    yo = Nyo;
    yx = Nyx;
    yy = Nyy;
    yz = Nyz;
    zo = Nzo;
    zx = Nzx;
    zy = Nzy;
    zz = Nzz;
  }
Esempio n. 15
0
  /** Rotate theta degrees about the z axis */
  void zrot(double theta) {
    theta *= pi / 180;
    double ct = Math.cos(theta);
    double st = Math.sin(theta);

    double Nyx = (yx * ct + xx * st);
    double Nyy = (yy * ct + xy * st);
    double Nyz = (yz * ct + xz * st);
    double Nyo = (yo * ct + xo * st);

    double Nxx = (xx * ct - yx * st);
    double Nxy = (xy * ct - yy * st);
    double Nxz = (xz * ct - yz * st);
    double Nxo = (xo * ct - yo * st);

    yo = Nyo;
    yx = Nyx;
    yy = Nyy;
    yz = Nyz;
    xo = Nxo;
    xx = Nxx;
    xy = Nxy;
    xz = Nxz;
  }
Esempio n. 16
0
  /** Rotate theta degrees around the y axis */
  void yrot(double theta) {
    theta *= (pi / 180);
    double ct = Math.cos(theta);
    double st = Math.sin(theta);

    double Nxx = (xx * ct + zx * st);
    double Nxy = (xy * ct + zy * st);
    double Nxz = (xz * ct + zz * st);
    double Nxo = (xo * ct + zo * st);

    double Nzx = (zx * ct - xx * st);
    double Nzy = (zy * ct - xy * st);
    double Nzz = (zz * ct - xz * st);
    double Nzo = (zo * ct - xo * st);

    xo = Nxo;
    xx = Nxx;
    xy = Nxy;
    xz = Nxz;
    zo = Nzo;
    zx = Nzx;
    zy = Nzy;
    zz = Nzz;
  }
Esempio n. 17
0
 /**
  * Specifies the angle of the texture.
  *
  * @param angle the angle of the texture.
  * @angle
  * @see #getAngle
  */
 public void setAngle(float angle) {
   this.angle = angle;
   p2 = new Point((int) (64 * Math.cos(angle)), (int) (64 * Math.sin(angle)));
 }
Esempio n. 18
0
  protected void transformInverse(int x, int y, float[] out) {
    float theta, t;
    float m, xmax, ymax;
    float r = 0;

    switch (type) {
      case RECT_TO_POLAR:
        theta = 0;
        if (x >= centreX) {
          if (y > centreY) {
            theta =
                ImageMath.PI - (float) Math.atan(((float) (x - centreX)) / ((float) (y - centreY)));
            r = (float) Math.sqrt(sqr(x - centreX) + sqr(y - centreY));
          } else if (y < centreY) {
            theta = (float) Math.atan(((float) (x - centreX)) / ((float) (centreY - y)));
            r = (float) Math.sqrt(sqr(x - centreX) + sqr(centreY - y));
          } else {
            theta = ImageMath.HALF_PI;
            r = x - centreX;
          }
        } else if (x < centreX) {
          if (y < centreY) {
            theta =
                ImageMath.TWO_PI
                    - (float) Math.atan(((float) (centreX - x)) / ((float) (centreY - y)));
            r = (float) Math.sqrt(sqr(centreX - x) + sqr(centreY - y));
          } else if (y > centreY) {
            theta =
                ImageMath.PI + (float) Math.atan(((float) (centreX - x)) / ((float) (y - centreY)));
            r = (float) Math.sqrt(sqr(centreX - x) + sqr(y - centreY));
          } else {
            theta = 1.5f * ImageMath.PI;
            r = centreX - x;
          }
        }
        if (x != centreX) m = Math.abs(((float) (y - centreY)) / ((float) (x - centreX)));
        else m = 0;

        if (m <= ((float) height / (float) width)) {
          if (x == centreX) {
            xmax = 0;
            ymax = centreY;
          } else {
            xmax = centreX;
            ymax = m * xmax;
          }
        } else {
          ymax = centreY;
          xmax = ymax / m;
        }

        out[0] = (width - 1) - (width - 1) / ImageMath.TWO_PI * theta;
        out[1] = height * r / radius;
        break;
      case POLAR_TO_RECT:
        theta = x / width * ImageMath.TWO_PI;
        float theta2;

        if (theta >= 1.5f * ImageMath.PI) theta2 = ImageMath.TWO_PI - theta;
        else if (theta >= ImageMath.PI) theta2 = theta - ImageMath.PI;
        else if (theta >= 0.5f * ImageMath.PI) theta2 = ImageMath.PI - theta;
        else theta2 = theta;

        t = (float) Math.tan(theta2);
        if (t != 0) m = 1.0f / t;
        else m = 0;

        if (m <= ((float) (height) / (float) (width))) {
          if (theta2 == 0) {
            xmax = 0;
            ymax = centreY;
          } else {
            xmax = centreX;
            ymax = m * xmax;
          }
        } else {
          ymax = centreY;
          xmax = ymax / m;
        }

        r = radius * (float) (y / (float) (height));

        float nx = -r * (float) Math.sin(theta2);
        float ny = r * (float) Math.cos(theta2);

        if (theta >= 1.5f * ImageMath.PI) {
          out[0] = (float) centreX - nx;
          out[1] = (float) centreY - ny;
        } else if (theta >= Math.PI) {
          out[0] = (float) centreX - nx;
          out[1] = (float) centreY + ny;
        } else if (theta >= 0.5 * Math.PI) {
          out[0] = (float) centreX + nx;
          out[1] = (float) centreY + ny;
        } else {
          out[0] = (float) centreX + nx;
          out[1] = (float) centreY - ny;
        }
        break;
      case INVERT_IN_CIRCLE:
        float dx = x - centreX;
        float dy = y - centreY;
        float distance2 = dx * dx + dy * dy;
        out[0] = centreX + centreX * centreX * dx / distance2;
        out[1] = centreY + centreY * centreY * dy / distance2;
        break;
    }
  }
Esempio n. 19
0
 private int xCor(int len, double dir) {
   return (int) (len * Math.sin(dir));
 }
  /**
   * Gets the template location at which the best match occurs in a rectangle and along a line. May
   * return null.
   *
   * @param target the image to search
   * @param searchRect the rectangle to search within the target image
   * @param x0 the x-component of a point on the line
   * @param y0 the y-component of a point on the line
   * @param slope the slope of the line
   * @param spread the spread of the line (line width = 1+2*spread)
   * @return the optimized template location of the best match, if any
   */
  public TPoint getMatchLocation(
      BufferedImage target, Rectangle searchRect, double x0, double y0, double theta, int spread) {
    wTarget = target.getWidth();
    hTarget = target.getHeight();
    // determine insets needed to accommodate template
    int left = wTemplate / 2, right = left;
    if (wTemplate % 2 > 0) right++;
    int top = hTemplate / 2, bottom = top;
    if (hTemplate % 2 > 0) bottom++;

    // trim search rectangle if necessary
    searchRect.x = Math.max(left, Math.min(wTarget - right, searchRect.x));
    searchRect.y = Math.max(top, Math.min(hTarget - bottom, searchRect.y));
    searchRect.width = Math.min(wTarget - searchRect.x - right, searchRect.width);
    searchRect.height = Math.min(hTarget - searchRect.y - bottom, searchRect.height);
    if (searchRect.width <= 0 || searchRect.height <= 0) {
      peakHeight = Double.NaN;
      peakWidth = Double.NaN;
      return null;
    }
    // set up test pixels to search (rectangle plus template)
    int xMin = Math.max(0, searchRect.x - left);
    int xMax = Math.min(wTarget, searchRect.x + searchRect.width + right);
    int yMin = Math.max(0, searchRect.y - top);
    int yMax = Math.min(hTarget, searchRect.y + searchRect.height + bottom);
    wTest = xMax - xMin;
    hTest = yMax - yMin;
    if (target.getType() != BufferedImage.TYPE_INT_RGB) {
      BufferedImage image = new BufferedImage(wTarget, hTarget, BufferedImage.TYPE_INT_RGB);
      image.createGraphics().drawImage(target, 0, 0, null);
      target = image;
    }
    targetPixels = new int[wTest * hTest];
    target.getRaster().getDataElements(xMin, yMin, wTest, hTest, targetPixels);
    // get the points to search along the line
    ArrayList<Point2D> searchPts = getSearchPoints(searchRect, x0, y0, theta);
    if (searchPts == null) {
      peakHeight = Double.NaN;
      peakWidth = Double.NaN;
      return null;
    }
    // collect differences in a map as they are measured
    HashMap<Point2D, Double> diffs = new HashMap<Point2D, Double>();
    // find the point with the minimum difference from template
    double matchDiff = largeNumber; // larger than typical differences
    int xMatch = 0, yMatch = 0;
    double avgDiff = 0;
    Point2D matchPt = null;
    for (Point2D pt : searchPts) {
      int x = (int) pt.getX();
      int y = (int) pt.getY();
      double diff = getDifferenceAtTestPoint(x, y);
      diffs.put(pt, diff);
      avgDiff += diff;
      if (diff < matchDiff) {
        matchDiff = diff;
        xMatch = x;
        yMatch = y;
        matchPt = pt;
      }
    }
    avgDiff /= searchPts.size();
    peakHeight = avgDiff / matchDiff - 1;
    peakWidth = Double.NaN;
    double dl = 0;
    int matchIndex = searchPts.indexOf(matchPt);

    // if match is not exact, fit a Gaussian and find peak
    if (!Double.isInfinite(peakHeight) && matchIndex > 0 && matchIndex < searchPts.size() - 1) {
      // fill data arrays
      Point2D pt = searchPts.get(matchIndex - 1);
      double diff = diffs.get(pt);
      xValues[0] = -pt.distance(matchPt);
      yValues[0] = avgDiff / diff - 1;
      xValues[1] = 0;
      yValues[1] = peakHeight;
      pt = searchPts.get(matchIndex + 1);
      diff = diffs.get(pt);
      xValues[2] = pt.distance(matchPt);
      yValues[2] = avgDiff / diff - 1;

      // determine approximate offset (dl) and width (w) values
      double pull = -xValues[0] / (yValues[1] - yValues[0]);
      double push = xValues[2] / (yValues[1] - yValues[2]);
      if (Double.isNaN(pull)) pull = LARGE_NUMBER;
      if (Double.isNaN(push)) push = LARGE_NUMBER;
      dl = 0.3 * (xValues[2] - xValues[0]) * (push - pull) / (push + pull);
      double ratio = dl > 0 ? peakHeight / yValues[0] : peakHeight / yValues[2];
      double w = dl > 0 ? dl - xValues[0] : dl - xValues[2];
      w = w * w / Math.log(ratio);

      // set parameters and fit to x data
      dataset.clear();
      dataset.append(xValues, yValues);
      double rmsDev = 1;
      for (int k = 0; k < 3; k++) {
        double c = k == 0 ? w : k == 1 ? w / 3 : w * 3;
        f.setParameterValue(0, peakHeight);
        f.setParameterValue(1, dl);
        f.setParameterValue(2, c);
        rmsDev = fitter.fit(f);
        if (rmsDev < 0.01) { // fitter succeeded (3-point fit should be exact)	
          dl = f.getParameterValue(1);
          peakWidth = f.getParameterValue(2);
          break;
        }
      }
    }
    double dx = dl * Math.cos(theta);
    double dy = dl * Math.sin(theta);
    double xImage = xMatch + searchRect.x - left - trimLeft + dx;
    double yImage = yMatch + searchRect.y - top - trimTop + dy;
    return new TPoint(xImage, yImage);
  }
Esempio n. 21
0
 public double cval(double td) {
   if (td == 0) return (1.0);
   else if ((td < -sz) || (td > sz)) return (0.0);
   double tdp = td * Math.PI;
   return ((Math.sin(tdp) / tdp) * (0.54 + (0.46 * Math.cos(tdp / sz))));
 }
Esempio n. 22
0
  public void Hough() {
    // for polar we need accumulator of 180degress * the longest length in the image
    // rmax = (int)Math.sqrt(width*width + height*height);

    System.out.println("w: " + width + " h: " + height + " rmax: " + rmax);
    acc = new int[width * height][accRMax];
    int rOffset;
    for (int x = 0; x < height; x++) {
      for (int y = 0; y < width; y++) {
        rOffset = 0;
        for (int r = rmin; r < rmax; r += offset) {
          acc[x * width + y][rOffset++] = 0;
        }
      }
    }
    System.out.println("accumulating");
    int x0, y0;
    double t;
    int[] val = new int[1];
    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {

        // if ((nonMax.getRaster().getPixel(x, y, val)[0])== -1) {
        if ((data[y * width + x] & 0xFF) == 255) {
          rOffset = 0;
          for (int r = rmin; r < rmax; r += offset) {
            for (int theta = 0; theta < 360; theta += 2) {
              t = (theta * 3.14159265) / 180;
              x0 = (int) Math.round(x - r * Math.cos(t));
              y0 = (int) Math.round(y - r * Math.sin(t));
              if (x0 < width && x0 > 0 && y0 < height && y0 > 0) {
                acc[x0 + (y0 * width)][rOffset] += 1;
              }
            }
            rOffset++;
          }
        }
      }
    }
    // now normalise to 255 and put in format for a pixel array
    int max = 0;
    // Find max acc value
    System.out.println("Finding Max");
    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        rOffset = 0;
        for (int r = rmin; r < rmax; r += offset) {
          if (acc[x + (y * width)][rOffset] > max) {
            max = acc[x + (y * width)][rOffset];
          }
          rOffset++;
        }
      }
    }

    // Normalise all the values
    int value;
    System.out.println("Normalising");
    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        rOffset = 0;
        for (int r = rmin; r < rmax; r += offset) {
          value = (int) (((double) acc[x + (y * width)][rOffset] / (double) max) * 255.0);
          acc[x + (y * width)][rOffset] = 0xff000000 | (value << 16 | value << 8 | value);
          rOffset++;
        }
      }
    }

    findMaxima();

    System.out.println("done");
  }