示例#1
0
  /**
   * Convert a 3-channel {@link MultiSpectral} image from RGB into YUV.
   *
   * @param rgb (Input) RGB encoded image
   * @param yuv (Output) YUV encoded image
   */
  public static void rgbToYuv_F32(
      MultiSpectral<ImageFloat32> rgb, MultiSpectral<ImageFloat32> yuv) {

    InputSanityCheck.checkSameShape(yuv, rgb);

    ImageFloat32 R = rgb.getBand(0);
    ImageFloat32 G = rgb.getBand(1);
    ImageFloat32 B = rgb.getBand(2);

    ImageFloat32 Y = yuv.getBand(0);
    ImageFloat32 U = yuv.getBand(1);
    ImageFloat32 V = yuv.getBand(2);

    for (int row = 0; row < yuv.height; row++) {
      int indexYuv = yuv.startIndex + row * yuv.stride;
      int indexRgb = rgb.startIndex + row * rgb.stride;

      for (int col = 0; col < yuv.width; col++, indexYuv++, indexRgb++) {
        float r = R.data[indexRgb];
        float g = G.data[indexRgb];
        float b = B.data[indexRgb];

        float y = 0.299f * r + 0.587f * g + 0.114f * b;

        Y.data[indexRgb] = y;
        U.data[indexRgb] = 0.492f * (b - y);
        V.data[indexRgb] = 0.877f * (r - y);
      }
    }
  }
示例#2
0
  /**
   * Convert a 3-channel {@link MultiSpectral} image from YUV into RGB.
   *
   * @param rgb (Input) RGB encoded image
   * @param yuv (Output) YUV encoded image
   */
  public static void yuvToRgb_F32(
      MultiSpectral<ImageFloat32> yuv, MultiSpectral<ImageFloat32> rgb) {

    InputSanityCheck.checkSameShape(yuv, rgb);

    ImageFloat32 Y = yuv.getBand(0);
    ImageFloat32 U = yuv.getBand(1);
    ImageFloat32 V = yuv.getBand(2);

    ImageFloat32 R = rgb.getBand(0);
    ImageFloat32 G = rgb.getBand(1);
    ImageFloat32 B = rgb.getBand(2);

    for (int row = 0; row < yuv.height; row++) {
      int indexYuv = yuv.startIndex + row * yuv.stride;
      int indexRgb = rgb.startIndex + row * rgb.stride;

      for (int col = 0; col < yuv.width; col++, indexYuv++, indexRgb++) {
        float y = Y.data[indexYuv];
        float u = U.data[indexYuv];
        float v = V.data[indexYuv];

        R.data[indexRgb] = y + 1.13983f * v;
        G.data[indexRgb] = y - 0.39465f * u - 0.58060f * v;
        B.data[indexRgb] = y + 2.032f * u;
      }
    }
  }
示例#3
0
  /**
   * Performs a horizontal 1D convolution across the image. Borders are handled as specified by the
   * 'border' parameter.
   *
   * @param image The original image. Not modified.
   * @param dest Where the resulting image is written to. Modified.
   * @param kernel The kernel that is being convolved. Not modified.
   * @param border How the image borders are handled.
   */
  public static void horizontal(
      Kernel1D_I32 kernel, GrayU8 image, GrayI16 dest, ImageBorder_S32 border) {
    InputSanityCheck.checkSameShape(image, dest);

    border.setImage(image);
    ConvolveImageNoBorder.horizontal(kernel, image, dest);
    ConvolveJustBorder_General.horizontal(kernel, border, dest);
  }
示例#4
0
  /**
   * Performs a 2D convolution across the image. Borders are handled as specified by the 'border'
   * parameter.
   *
   * @param image The original image. Not modified.
   * @param dest Where the resulting image is written to. Modified.
   * @param kernel The kernel that is being convolved. Not modified.
   * @param border How the image borders are handled.
   */
  public static void convolve(
      Kernel2D_F32 kernel, GrayF32 image, GrayF32 dest, ImageBorder_F32 border) {
    InputSanityCheck.checkSameShape(image, dest);

    border.setImage(image);
    ConvolveImageNoBorder.convolve(kernel, image, dest);
    ConvolveJustBorder_General.convolve(kernel, border, dest);
  }
  /**
   * Converts an image from one type to another type. Creates a new image instance if an output is
   * not provided.
   *
   * @param src Input image. Not modified.
   * @param dst Converted output image. If null a new one will be declared. Modified.
   * @param typeDst The type of output image.
   * @return Converted image.
   */
  public static <T extends ImageSingleBand> T convert(
      ImageSingleBand<?> src, T dst, Class<T> typeDst) {
    if (dst == null) {
      dst = (T) createSingleBand(typeDst, src.width, src.height);
    } else {
      InputSanityCheck.checkSameShape(src, dst);
    }
    convert(src, dst);

    return dst;
  }
  /**
   * Computes disparity between two stereo images
   *
   * @param left Left rectified stereo image. Input
   * @param right Right rectified stereo image. Input
   * @param disparity Disparity between the two images. Output
   */
  public void process(Input left, Input right, Disparity disparity) {
    // initialize data structures
    InputSanityCheck.checkSameShape(left, right, disparity);

    if (maxDisparity > left.width - 2 * radiusX)
      throw new RuntimeException(
          "The maximum disparity is too large for this image size: max size "
              + (left.width - 2 * radiusX));

    lengthHorizontal = left.width * rangeDisparity;

    _process(left, right, disparity);
  }
示例#7
0
  /**
   * Computes the optical flow form 'prev' to 'curr' and stores the output into output
   *
   * @param prev Previous image
   * @param curr Current image
   * @param output Dense optical flow output
   */
  public void process(T prev, T curr, ImageFlow output) {

    InputSanityCheck.checkSameShape(prev, curr);
    output.invalidateAll();

    int N = prev.width * prev.height;
    if (scores.length < N) scores = new float[N];

    int r = searchRadius + regionRadius;
    int x1 = prev.width - r;
    int y1 = prev.height - r;

    for (int y = r; y < y1; y++) {
      for (int x = r; x < x1; x++) {
        extractTemplate(x, y, prev);
        float score = findFlow(x, y, curr, tmp);

        if (tmp.valid) checkNeighbors(x, y, tmp, output, score);
      }
    }

    // TODO process image border
  }
  /**
   * Converts the gray scale input image into a binary image
   *
   * @param input Input image
   * @param output Output binary image
   */
  public void process(T input, ImageUInt8 output) {
    InputSanityCheck.checkSameShape(input, output);

    if (input.width < requestedBlockWidth || input.height < requestedBlockWidth) {
      throw new IllegalArgumentException("Image is smaller than block size");
    }

    selectBlockSize(input.width, input.height);

    minmax.reshape(input.width / blockWidth, input.height / blockHeight);

    int innerWidth =
        input.width % blockWidth == 0
            ? input.width
            : input.width - blockWidth - input.width % blockWidth;
    int innerHeight =
        input.height % blockHeight == 0
            ? input.height
            : input.height - blockHeight - input.height % blockHeight;

    computeMinMax(input, innerWidth, innerHeight);
    applyThreshold(input, output);
  }