Mauro
Mauro

Reputation: 237

How can i change a pixel value from a grayscaled image using Opencv 2.3?

When i read a grayscaled image using for example in Opencv 2.3:

Mat src = imread("44.png" ,0);

How can i access the pixel value of it?

I know if its RGB i can use:

std::cout << src.at<cv::Vec3b>(i,j)[0].

Thanks in advance.

Upvotes: 2

Views: 5069

Answers (1)

Christian Rau
Christian Rau

Reputation: 45948

Since a grayscale image contains only one component instead of 3, the resulting matrix/image is of type CV_8UC1 instead of CV_8UC3. And this in turn means, that individual pixels are not 3-vectors of bytes (cv::Vec3b) but just single bytes (unsigned char or OpenCV's uchar). So you can just use:

src.at<unsigned char>(i, j)

Upvotes: 4

Related Questions