I want to convert 16UC3 image to 1 dimensional array? [closed]

asked 2016-10-26 01:59:45 -0600

Madalasa gravatar image

updated 2016-10-26 02:02:46 -0600

berak gravatar image

I'm unable to access the values in the matrix properly.

for (int i = 0; i < image.rows; i++)
    {
        for (int j = 0; j < image.cols; j++)
        {
            img[j + image.cols*i + image.cols*image.rows * 0] = image.at<cv::Vec3b>(i, j)[0];
            img[j + image.cols*i + image.cols*image.rows * 1] = image.at<cv::Vec3b>(i, j)[1];
            img[j + image.cols*i + image.cols*image.rows * 2] = image.at<cv::Vec3b>(i, j)[2];
        }
    }
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-12-04 11:40:43.058208

Comments

Vec3b is the wrong access for 16UC3 (uchar vs ushort)

berak gravatar imageberak ( 2016-10-26 02:11:29 -0600 )edit

What is the correct way to access those values??

Madalasa gravatar imageMadalasa ( 2016-10-26 03:20:44 -0600 )edit

image.at<ushort>(i,j)[0] is this way to access values...

Madalasa gravatar imageMadalasa ( 2016-10-26 03:33:58 -0600 )edit

hmm, that's a different context now. (why didn't you tell before ?)

one of the main differences between code above and answer below is, that opencv uses interleaved bgr pixels, while you seem to want sequential channels, can you clarify ?

berak gravatar imageberak ( 2016-10-26 04:21:20 -0600 )edit