Пример #1
0
  public double calculateFrameWidthPix() {
    if (farEdge == null || farEdge.stdDev > worstEdgeStdDevAllowed) {
      if (sprocketEdge == null || sprocketEdge.stdDev > worstEdgeStdDevAllowed) return -1.0;
      else {
        // The frame center in the image will happen along the sprocket hole line
        //  right in between the two images. This will also need to change to the appropriate
        //  place along that line (not right between the two edges. .. actually, to
        //  make things even simpler for now I will make it exactly between the sprocket
        //  hole and the far edge.
        //
        // first determine the scale factor ...
        //
        double distPix = PolarLineFit.perpendicularDistance(fit, sprocketEdge.c, sprocketEdge.r);
        // we need to increase this amount by the percentage
        //   that the frame occupies when going from sprocket
        //   center to the far edge
        double scaleScale =
            FilmSpec.filmAttribute(filmType, FilmSpec.frameWidthIndex)
                / ((FilmSpec.filmAttribute(filmType, FilmSpec.edgeToEdgeIndex)
                    + (FilmSpec.filmAttribute(filmType, FilmSpec.widthIndex) / 2.0)));
        distPix *= scaleScale;

        // distPix is now the calculated frame width in pixels for this frame.

        return distPix;
      }
    } else {
      // The frame center in the image will happen along the sprocket hole line
      //  right in between the two images. This will also need to change to the appropriate
      //  place along that line (not right between the two edges. .. actually, to
      //  make things even simpler for now I will make it exactly between the sprocket
      //  hole and the far edge.
      //
      // first determine the scale factor ...
      //
      double distPix = PolarLineFit.perpendicularDistance(fit, farEdge.c, farEdge.r);

      // we need to reduce this amount by the percentage
      //   that the frame occupies when going from sprocket
      //   center to the far edge
      double scaleScale =
          FilmSpec.filmAttribute(filmType, FilmSpec.frameWidthIndex) / centerSprocketToFarEdgemm;

      // scaleScale is now the ratio of the frame width to the
      //  distance from the center of the sprocket to the far edge. This
      //  will be less than 1.0
      distPix *= scaleScale;

      // distPix is now the calculated frame width in pixels for this frame.

      return distPix;
    }
  }
Пример #2
0
  private void preMapSetupUsingFarEdge(
      int frameWidth,
      int frameHeight,
      double scaleMult,
      boolean reverseImage,
      boolean rescale,
      boolean correctrotation) {
    // center of the frame in a coord system centered in the lower
    //  left corner of the frame itself
    fcc = ((double) (frameWidth + 1)) / 2.0;
    fcr = ((double) (frameHeight + 1)) / 2.0;

    // for now fit the width of the image between the edges. This will change to
    //  an estimate of the frame and some overlap (which will need to be specified
    //  also) but for now lets see if i can simply get a good image
    //
    //      // The frame center in the image will happen along the sprocket hole line
    //      //  right in between the two images. This will also need to change to the appropriate
    //      //  place along that line (not right between the two edges. .. actually, to
    //      //  make things even simpler for now I will make it exactly between the sprocket
    //      //  hole and the far edge.
    //      //
    //      // first determine the scale factor ...
    //      //
    //      double distPix = PolarLineFit.perpendicularDistance(fit,farEdge.c, farEdge.r);
    //
    //      // we need to reduce this amount by the percentage
    //      //   that the frame occupies when going from sprocket
    //      //   center to the far edge
    //      double scaleScale = FilmSpec.filmAttribute(filmType,FilmSpec.frameWidthIndex) /
    //         centerSprocketToFarEdgemm;
    //
    //      // scaleScale is now the ratio of the frame width to the
    //      //  distance from the center of the sprocket to the far edge. This
    //      //  will be less than 1.0
    //      distPix *= scaleScale;
    //
    //      // distPix is now the calculated frame width in pixels for this frame.

    double distPix = calculateFrameWidthPix();

    scale = distPix / ((double) frameWidth); // original image pixels / frame pixels
    scale *= scaleMult;

    // now scr and scc give the location of the desired point scaled
    //  and relative to the center of the frame. So now we need to
    //  move cfc along the line between the sprocket hole center and
    //  the far edge starting from the point right in the middle.
    com.jiminger.image.Point farPoint = PolarLineFit.closest(fit, farEdge.c, farEdge.r);

    double farPointRow = farPoint.getRow();
    double farPointCol = farPoint.getCol();

    double percentageFromSprocketHoleToFarEdge =
        (centerFrameToCenterSprocketXmm / centerSprocketToFarEdgemm);

    imgcr =
        (fit.cr * (1.0 - percentageFromSprocketHoleToFarEdge))
            + (farPointRow * percentageFromSprocketHoleToFarEdge);

    imgcc =
        (fit.cc * (1.0 - percentageFromSprocketHoleToFarEdge))
            + (farPointCol * percentageFromSprocketHoleToFarEdge);

    // The following code is used to find a unit vector in the direction from
    //  the sprocket hole to the closest point on the far edge. It worked
    //  by understanding that the polar line representation of the far
    //  edge was exactly parallel to the line from the sprocket hole,
    //  through the axis that bisects the frame, to the closest point on
    //  the far edge. This code is commented out because of problems it has
    //  when the far edge line passes to the wrong side of the origin. Instead,
    //  since we are using the 'farPoint' above anyway, we will actually calculate
    //  the unit vector using these two points (the sprocket hole center and
    //  the closest point on the far edge).
    //
    //      // a unint vector in the direction of the edge of the film within
    //      // the image is given by
    //      double farEdgePolarMag = Math.sqrt( (farEdge.r * farEdge.r) + (farEdge.c * farEdge.c) );
    //      unitRow = farEdge.r / farEdgePolarMag;
    //      unitCol = farEdge.c / farEdgePolarMag;
    //
    //      // If the row of the fit was negative (and the orientation is horizontal)
    //      //  then the edge of the film was too close to the edge of the actual image
    //      //  (and we are in  danger of a singluarity ... but we'll fix that another time).
    //      //  The unit vector should point from the sprocket hole TO the
    //      //  far edge so the row should be reversed. In this case the origin occurrs in
    //      //  between the two.
    //      if (!isVertical && unitRow < 0.0) unitRow = -unitRow;
    //
    //      // If the col of the fit was negative (and the orientation is vertical)
    //      //  then the edge of the film was too close to the edge of the actual image
    //      //  (and we are in  danger of a singluarity ... but we'll fix that another time).
    //      //  The unit vector should point from the sprocket hole TO the
    //      //  far edge so the col should reversed. In this case the origin occurrs in
    //      //  between the two.
    //      if (isVertical && unitCol < 0.0) unitCol = -unitCol;

    //  Since we are using the 'farPoint' above anyway, we will actually calculate
    //  the unit vector using these two points (the sprocket hole center and
    //  the closest point on the far edge).
    //
    // diffR,diffC is the r,c representation of the vector from the sprocket
    //  hole center to the far edge.
    double diffRow = farPointRow - fit.getRow();
    double diffCol = farPointCol - fit.getCol();
    double diffMag = Math.sqrt((diffRow * diffRow) + (diffCol * diffCol));
    unitRow = diffRow / diffMag;
    unitCol = diffCol / diffMag;

    // vertUnit goes DOWN the frame (positive row direction)
    //  parallel to the edge.
    vertUnitRow = reverseImage ? -unitCol : unitCol;
    vertUnitCol = reverseImage ? unitRow : -unitRow;

    if (!correctrotation) unrotate();

    if (!rescale) scale = 1.0;
  }