如何获取CIELAB图像的a轴和b轴上的像素值

时间:2015-05-16 16:01:46

标签: java opencv image-processing colors rgb

我将BGR图像转换为LAB颜色系统,我想知道a轴和b轴上LAB图像中像素的确切值。 如下面的代码中的shiwn,当我使用dst.get(0, 3)[0]来显示LAB图像中像素的像素值时,我会收到一个scalr值,而我想得到的是,LAB图像中的像素值a轴和b轴。

我需要它来计算一个ecludian距离。 请让我知道怎么做

*代码**:

    Mat dst = new Mat();
    Imgproc.cvtColor(bgrMat, dst, Imgproc.COLOR_BGR2Lab);
    ImageUtils.showMat(dst, "");

    Log.D(TAG, "main", "dst.dump() \n" + dst.dump());
    Log.D(TAG, "main", "dst.get(0, 3): " + dst.get(0, 3)[0]);

输出

    1: Debug: MainClass -> main: dst.dump() 
    [1, 128, 128, 7, 128, 128, 19, 128, 128, 47, 128, 128, 58, 128, 128, 28, 128, 128, 8, 128, 128, 16, 128, 128, 17, 128, 128, 18, 128, 128;
    2, 128, 128, 2, 128, 128, 15, 128, 128, 46, 128, 128, 55, 128, 128, 40, 128, 128, 27, 128, 128, 27, 128, 128, 25, 128, 128, 24, 128, 128;
    1, 128, 128, 3, 128, 128, 18, 128, 128, 34, 128, 128, 34, 128, 128, 41, 128, 128, 47, 128, 128, 39, 128, 128, 30, 128, 128, 23, 128, 128;
    9, 128, 128, 10, 128, 128, 19, 128, 128, 25, 128, 128, 17, 128, 128, 23, 128, 128, 41, 128, 128, 51, 128, 128, 24, 128, 128, 9, 128, 128;
    11, 128, 128, 9, 128, 128, 27, 128, 128, 58, 128, 128, 63, 128, 128, 43, 128, 128, 36, 128, 128, 48, 128, 128, 23, 128, 128, 5, 128, 128;
    5, 128, 128, 9, 128, 128, 36, 128, 128, 78, 128, 128, 103, 128, 128, 93, 128, 128, 71, 128, 128, 61, 128, 128, 19, 128, 128, 1, 128, 128;
    5, 128, 128, 10, 128, 128, 39, 128, 128, 68, 128, 128, 82, 128, 128, 87, 128, 128, 83, 128, 128, 73, 128, 128, 16, 128, 128, 1, 128, 128;
    1, 128, 128, 1, 128, 128, 41, 128, 128, 77, 128, 128, 57, 128, 128, 34, 128, 128, 38, 128, 128, 40, 128, 128, 27, 128, 128, 9, 128, 128;
    5, 128, 128, 5, 128, 128, 47, 128, 128, 87, 128, 128, 57, 128, 128, 27, 128, 128, 16, 128, 128, 9, 128, 128, 19, 128, 128, 39, 128, 128;
    11, 128, 128, 12, 128, 128, 58, 128, 128, 94, 128, 128, 67, 128, 128, 47, 128, 128, 35, 128, 128, 18, 128, 128, 24, 128, 128, 42, 128, 128]
    2: Debug: MainClass -> main: dst.get(0, 3): 47.0

1 个答案:

答案 0 :(得分:1)

你误解了3通道OpenCV Mat的结构和dump的输出。

如果你看here,你会发现下图显示了3通道垫子的内部结构。

enter image description here

桌子的颜色为蓝色,绿色和红色,但任何3通道垫子的结构都相同,包括CIELAB。

您会注意到每列由3个值组成。在BGR图像中,这些将是像素的蓝色,绿色和红色分量。在您的情况下,它们是Lab组件。

现在看看Mat的转储。它有10行,但有30列。我愿意打赌你的Mat的大小为10x10,有3个频道。如图所示,转储有30列而不是10列的原因是每个像素的3个组件是连续列出的。这是转储的第一行:

[1, 128, 128, 7, 128, 128, 19, 128, 128, 47, 128, 128, 58, 128, 128, 28, 128, 128, 8, 128, 128, 16, 128, 128, 17, 128, 128, 18, 128, 128; ..

(0,0)处的第一个像素的Lab成分1, 128, 128 (0,1)处的第二个像素具有Lab的{​​{1}}个分量 第三个像素是7, 128, 128。这些 3个像素会占用转储中的第一个 9个值 19, 128, 128处的第四个像素(从第10个值开始)是(0,3)

这就是为什么47, 128, 128
dst.get(0,3)[0] = 47
dst.get(0,3)[1]=128

通常,要单独访问这些像素,您可以dst.get(0,3)[2] = 128将它们放入与图像相同类型的数组中。例如,如果您有get,则可以将像素放入CV_8UC3

byte[]

现在,对于像素byte[] interestingPixel = dst.get(0, 3);

(0, 3)