Ask Your Question

Revision history [back]

Pixel multiplication gives different result

In detail I read a image in c++ and multiplied its pixel of 3 channel BGR value with 255, It gives me resultant image as negative image. In this case, if you are multiplying a pixel value with 255, it should be saturated to white have to give [255, 255, 255]. But negative image have different values. The following code is,

uchar *p;
for (int i = 0; i < nRows; i++){
    p = image.ptr<uchar>(i);
    for (int j = 0; j < nCols; j++){
        p[j] =  table[p[j]] * 255;
        //cout << (int)p[j] * 255 <<" ";
    }
}

image description

So I test a user-defined Mat with one pixel value of 3 channel BGR value with 255, producing result of [255, 255, 255].

Mat sample = Mat(1, 1, CV_8UC3);
uchar *l;
l = sample.data;
for (int i = 0; i < sample.rows * sample.cols; i++){
    cout << sample * 255;
    cout << sample;
}