Ask Your Question

Revision history [back]

Store calculation result from RGB in Vec3b into new matrix instead of Mat Object

Hi, I've been learning to work with image processing. I'm trying to access RGB value from a Mat image :

Mat picture = imread("picture.png", CV_LOAD_IMAGE_COLOR);
int rows = picture.rows;
int cols = picture.cols;

So, I can get these BGR value

    picture.at<Vec3b>(i, j)[0]
    picture.at<Vec3b>(i, j)[1]
    picture.at<Vec3b>(i, j)[2]

Then I need to multiply each channel value with some values. For example channel B --> [0] :

for (int i = 0; i < picture.rows; i++) {
        for (int j = 0; j < picture.cols; j++) {
            output.at<Vec3b>(i, j)[0] = (picture.at<Vec3b>(i, j)[0] * 0.2) +
                                        (picture.at<Vec3b>(i, j)[1] * 0.3) +
                                        (picture.at<Vec3b>(i, j)[2] * 0.4);
             }
        }

For now, I'm storing the calculation result as a Mat image (output). Is there any other way I can store the result of multiplication (output.at<Vec3b>(i, j)[0]) by creating a new matrix instead of store it as Mat object ? Because I need to calculate this value later and store it as matrix instead of Mat will help a lot.