Class RectifyImageOps

java.lang.Object
boofcv.alg.geo.RectifyImageOps

public class RectifyImageOps extends Object

Operations related to rectifying stereo image pairs. Provides functions for 1) creating rectification calculation algorithms, 2) rectification transforms, and 3) image distortion for rectification.

Definition of transformed coordinate systems:

Pixel
Original image coordinates in pixels.
Rect
Rectified image coordinates in pixels. Lens distortion has been removed.
RectNorm
Rectified image coordinates in normalized coordinates.

  • Constructor Details

    • RectifyImageOps

      public RectifyImageOps()
  • Method Details

    • createCalibrated

      public static RectifyCalibrated createCalibrated()

      Rectification for calibrated stereo pairs. Two stereo camera are considered calibrated if their baseline is known.

      After the rectification has been found it might still need to be adjusted for maximum viewing area. See fullViewLeft and allInsideLeft for adjusting the rectification.

      Returns:
      RectifyCalibrated
    • createUncalibrated

      public static RectifyFundamental createUncalibrated()

      Rectification for uncalibrated stereo pairs using the fundamental matrix. Uncalibrated refers to the stereo baseline being unknown. For this technique to work the fundamental matrix needs to be known very accurately. See comments in RectifyFundamental for more details.

      After the rectification has been found it might still need to be adjusted for maximum viewing area. See fullViewLeft(int, int, DMatrixRMaj, DMatrixRMaj) and allInsideLeft(int, int, DMatrixRMaj, DMatrixRMaj).

      Returns:
      RectifyFundamental
    • adjustView

      public static void adjustView(RectifyFillType approach, CameraPinholeBrown paramLeft, DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight, DMatrixRMaj rectifyK, @Nullable @Nullable ImageDimension rectifiedSize)

      Adjust the rectification based on the provided rule for filling the view.

      WARNING: There are pathological conditions where this will fail. If the new rotated image view and a pixel are parallel it will require infinite area.

      Parameters:
      paramLeft - (Input) Left camera intrinsic parameters
      rectifyLeft - (Input, Output) Left image transform from pixels to rectified pixels.
      rectifyRight - (Input, Output) Right image transform from pixels to rectified pixels.
      rectifyK - (Input, Output) Rectified intrinsic calibration matrix.
      rectifiedSize - (Output, Optional) Rectified image size that maximizes usable pixels at native resolution.
    • fullViewLeft

      public static void fullViewLeft(CameraPinholeBrown paramLeft, DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight, DMatrixRMaj rectifyK, @Nullable @Nullable ImageDimension rectifiedSize)

      Adjust the rectification such that the entire original left image can be seen and adjusts the shape of the rectified image to maximize it's area. For use with calibrated stereo images having a known baseline. Due to lens distortions it is possible for large parts of the rectified image to have no overlap with the original and will appear to be black. This can cause issues when processing the image

      WARNING: There are pathological conditions where this will fail. If the new rotated image view and a pixel are parallel it will require infinite area.

      Parameters:
      paramLeft - (Input) Left camera intrinsic parameters
      rectifyLeft - (Input, Output) Left image transform from pixels to rectified pixels.
      rectifyRight - (Input, Output) Right image transform from pixels to rectified pixels.
      rectifyK - (Input, Output) Rectified intrinsic calibration matrix.
      rectifiedSize - (Output, Optional) Rectified image size that maximizes usable pixels at native resolution.
    • fullViewLeft

      public static void fullViewLeft(CameraPinholeBrown paramLeft, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight, FMatrixRMaj rectifyK, @Nullable @Nullable ImageDimension rectifiedSize)

      Adjust the rectification such that the entire original left image can be seen. For use with calibrated stereo images having a known baseline. Due to lens distortions it is possible for large parts of the rectified image to have no overlap with the original and will appear to be black. This can cause issues when processing the image

      WARNING: There are pathological conditions where this will fail. If the new rotated image view and a pixel are parallel it will require infinite area.

      Parameters:
      paramLeft - (Input) Left camera intrinsic parameters
      rectifyLeft - (Input, Output) Left image transform from pixels to rectified pixels.
      rectifyRight - (Input, Output) Right image transform from pixels to rectified pixels.
      rectifyK - (Input, Output) Rectified intrinsic calibration matrix.
      rectifiedSize - (Output, Optional) Rectified image size that maximizes usable pixels at native resolution.
    • fullViewLeft

      public static void fullViewLeft(int imageWidth, int imageHeight, DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight)

      Adjust the rectification such that the entire original left image can be seen. For use with uncalibrated stereo images with unknown baseline.

      Input rectification matrices are overwritten with adjusted values on output.

      Parameters:
      imageWidth - (Input) Width of left image.
      imageHeight - (Input) Height of left image.
      rectifyLeft - (Input, Output) Left image transform from pixels to rectified pixels.
      rectifyRight - (Input, Output) Right image transform from pixels to rectified pixels.
    • fullViewLeft

      public static void fullViewLeft(int imageWidth, int imageHeight, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight)

      Adjust the rectification such that the entire original left image can be seen. For use with uncalibrated stereo images with unknown baseline.

      Input rectification matrices are overwritten with adjusted values on output.

      Parameters:
      imageWidth - (Input) Width of left image.
      imageHeight - (Input) Height of left image.
      rectifyLeft - (Input, Output) Left image transform from pixels to rectified pixels.
      rectifyRight - (Input, Output) Right image transform from pixels to rectified pixels.
    • allInsideLeft

      public static void allInsideLeft(CameraPinholeBrown paramLeft, DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight, DMatrixRMaj rectifyK, @Nullable @Nullable ImageDimension rectifiedSize)

      Adjust the rectification such that only pixels which overlap the original left image can be seen. For use with calibrated stereo images having a known baseline. Image processing is easier since only the "true" image pixels are visible, but information along the image border has been discarded. The rectification matrices are overwritten with adjusted values on output.

      Parameters:
      paramLeft - (Input) Left camera intrinsic parameters
      rectifyLeft - (Input, Output) Left image transform from pixels to rectified pixels.
      rectifyRight - (Input, Output) Right image transform from pixels to rectified pixels.
      rectifyK - (Input, Output) Rectified intrinsic calibration matrix.
      rectifiedSize - (Output, Optional) Rectified image size that maximizes usable pixels at native resolution.
    • allInsideLeft

      public static void allInsideLeft(CameraPinholeBrown paramLeft, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight, FMatrixRMaj rectifyK, @Nullable @Nullable ImageDimension rectifiedSize)

      Adjust the rectification such that only pixels which overlap the original left image can be seen. For use with calibrated stereo images having a known baseline. Image processing is easier since only the "true" image pixels are visible, but information along the image border has been discarded. The rectification matrices are overwritten with adjusted values on output.

      Parameters:
      paramLeft - (Input) Left camera intrinsic parameters
      rectifyLeft - (Input, Output) Left image transform from pixels to rectified pixels.
      rectifyRight - (Input, Output) Right image transform from pixels to rectified pixels.
      rectifyK - (Input, Output) Rectified intrinsic calibration matrix.
      rectifiedSize - (Output, Optional) Rectified image size that maximizes usable pixels at native resolution. Modified.
    • allInsideLeft

      public static void allInsideLeft(int imageWidth, int imageHeight, DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight)

      Adjust the rectification such that only pixels which overlap the original left image can be seen. For use with uncalibrated images with unknown baselines. Image processing is easier since only the "true" image pixels are visible, but information along the image border has been discarded. The rectification matrices are overwritten with adjusted values on output.

      Parameters:
      imageWidth - (Input) Width of left image.
      imageHeight - (Input) Height of left image.
      rectifyLeft - (Input, Output) Left image transform from pixels to rectified pixels.
      rectifyRight - (Input, Output) Right image transform from pixels to rectified pixels.
    • allInsideLeft

      public static void allInsideLeft(int imageWidth, int imageHeight, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight)

      Adjust the rectification such that only pixels which overlap the original left image can be seen. For use with uncalibrated images with unknown baselines. Image processing is easier since only the "true" image pixels are visible, but information along the image border has been discarded. The rectification matrices are overwritten with adjusted values on output.

      Parameters:
      imageWidth - (Input) Width of left image.
      imageHeight - (Input) Height of left image.
      rectifyLeft - (Input, Output) Left image transform from pixels to rectified pixels.
      rectifyRight - (Input, Output) Right image transform from pixels to rectified pixels.
    • transformRectToPixel

      public static Point2Transform2_F64 transformRectToPixel(CameraPinholeBrown param, DMatrixRMaj rectify)

      Creates a transform that goes from rectified to original distorted pixel coordinates. Rectification includes removal of lens distortion. Used for rendering rectified images.

      Parameters:
      param - (Input) Intrinsic parameters.
      rectify - (Input) Transform from pixels to rectified pixels
      Returns:
      Transform from rectified to unrectified pixels
    • transformRectToPixel

      public static Point2Transform2_F32 transformRectToPixel(CameraPinholeBrown param, FMatrixRMaj rectify)

      Creates a transform that goes from rectified to original distorted pixel coordinates. Rectification includes removal of lens distortion. Used for rendering rectified images.

      Parameters:
      param - (Input) Intrinsic parameters.
      rectify - (Input) Transform from pixels to rectified pixels
      Returns:
      Transform from rectified to unrectified pixels
    • transformPixelToRect

      public static Point2Transform2_F64 transformPixelToRect(CameraPinholeBrown param, DMatrixRMaj rectify)

      Creates a transform that applies rectification to unrectified distorted pixels.

      Parameters:
      param - (Input) Intrinsic parameters.
      rectify - (Input) Transform from pixels to rectified pixels
      Returns:
      Transform from distorted pixel to rectified pixels
    • transformPixelToRect

      public static Point2Transform2_F32 transformPixelToRect(CameraPinholeBrown param, FMatrixRMaj rectify)

      Creates a transform that applies rectification to unrectified distorted pixels.

      Parameters:
      param - (Input) Intrinsic parameters.
      rectify - (Input) Transform from pixels to rectified pixels
      Returns:
      Transform from distorted pixel to rectified pixels
    • transformPixelToRectNorm

      public static Point2Transform2_F64 transformPixelToRectNorm(CameraPinholeBrown param, DMatrixRMaj rectify, DMatrixRMaj rectifyK)

      Creates a transform that applies rectification to unrectified distorted pixels and outputs normalized pixel coordinates.

      Parameters:
      param - (Input) Intrinsic parameters.
      rectify - (Input) Transform from pixels to rectified pixels
      rectifyK - (Input) Camera calibration matrix after rectification
      Returns:
      Transform from unrectified to rectified normalized pixels
    • transformPixelToRectNorm

      public static Point2Transform2_F32 transformPixelToRectNorm(CameraPinholeBrown param, FMatrixRMaj rectify, FMatrixRMaj rectifyK)

      Creates a transform that applies rectification to unrectified distorted pixels and outputs normalized pixel coordinates.

      Parameters:
      param - (Input) Intrinsic parameters.
      rectify - (Input) Transform from pixels to rectified pixels
      rectifyK - Camera calibration matrix after rectification
      Returns:
      Transform from unrectified to rectified normalized pixels
    • applyMask

      public static void applyMask(GrayF32 disparity, GrayU8 mask, int radius)
      Applies a mask which indicates which pixels had mappings to the unrectified image. Pixels which were outside of the original image will be set to 255. The border is extended because the sharp edge in the rectified image can cause in incorrect match between image features.
      Parameters:
      disparity - (Input) disparity
      mask - (Input) mask. 1 = mapping to unrectified. 0 = no mapping
      radius - How much the border is extended by
    • applyMask

      public static void applyMask(GrayU8 disparity, GrayU8 mask, int radius)
      Applies a mask which indicates which pixels had mappings to the unrectified image. Pixels which were outside of the original image will be set to 255. The border is extended because the sharp edge can confuse disparity algorithms.
      Parameters:
      disparity - (Input) disparity
      mask - (Input) mask. 1 = mapping to unrectified. 0 = no mapping
      radius - How much the border is extended by