【问题标题】:RGB to LMS color space conversion with OpenCV使用 OpenCV 进行 RGB 到 LMS 颜色空间转换
【发布时间】:2016-02-28 02:41:00
【问题描述】:

我在理解如何正确使用矩阵类型进行从 rgb 到 lms 颜色空间与 opencv 的颜色转换时遇到问题。我找到的论文是here。我想要做的只是计算 lms 颜色三元组如下:

Mat actRGBVec = new Mat(1,3,Imgproc.COLOR_RGB2BGR);
Mat lmsResVec = new Mat(1,3,CvType.CV_64FC3);

lmsMat = new Mat(inputImg.rows(),inputImg.cols(),CvType.CV_64FC3);

// iterate through all pixels and multiply rgb values with the lms transformation matrix
try {
  for (int x = 0; x < inputImg.rows(); x++) {
    for (int y = 0; y < inputImg.cols(); y++) {
      actRGBVal = inputImg.get(x, y);

      // vector holding rgb info
      actRGBVec.put(0, 0, actRGBVal);
      Core.gemm(lmsTransformMat, actRGBVec, 1, null, 0, lmsResVec, 0);

      lmsMat.put(x, y, lmsResVec.get(0, 0));
    }
  }
}
catch (Exception e) {
  Log.d("ImageHandler","Error rgb to lms conversion! " + e.getMessage());
}

lmsMat 是 CV_64FC3 类型。 inputImg 的类型为 Imgproc.COLOR_RGB2BGR。 lmsTransformMat 是 CV_64FC1 类型(因为它只包含标量值,这应该是正确的类型?)。

异常说:错误 rgb 到 lms 转换!无效的 我在这里做错了什么?

【问题讨论】:

    标签: java opencv rgb


    【解决方案1】:

    确保所有矩阵的尺寸和类型都正确:

    • inputImage 不能是 Imgproc.COLOR_RGB2BGR 类型。这是用于cvtColor 函数的常量,而不是 OpenCV 矩阵类型。由于您的输入图像可能是彩色图像,因此CV_8UC3 的类型正确。
    • lmsTransformMat 应该是 CV_64FC1 类型的 3x3 矩阵。
    • actRGBVec 需要是与lmsTransformMat 相同类型的 3x1 矩阵。 (再次重申:Imgproc.COLOR_RGB2BGR 不是矩阵类型)。
    • lmsResVec 需要是与 lmsTransformMat 相同类型的 3x1 矩阵。 (不过,您可以只使用 new Mat()。OpenCV 会在 Core.gemm 中处理它。
    • lmsMat 看起来不错。

    此外,您将null 作为src3 参数传递给Core.gemm。这就是您的NullPointerException 的原因。由于您的beta 参数是0,您可以只提供new Mat() 而不是null

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2012-11-02
      • 2018-07-06
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 2015-05-30
      相关资源
      最近更新 更多