Ask Your Question
0

Doubt about how to access a pixel in cvMat structure

asked Feb 20 '15

Diego Moreira gravatar image

Hi,

How to access the value of pixel in structure cvMat ? I need access the pixels in a image with 3 channels. Can you help me ?

Thank you.

Preview: (hide)

Comments

You could start by separating the 3 channels using the split( ) function, and then this statement accesses pixel values -> img.at<uchar>(Point(x, y)); Hope this helps.

Potato gravatar imagePotato (Feb 20 '15)edit

You are right @matman. It would definitely be better to use OpenCV 3.0.0 functionality.

Potato gravatar imagePotato (Feb 20 '15)edit

Thank you!

Diego Moreira gravatar imageDiego Moreira (Feb 21 '15)edit

1 answer

Sort by » oldest newest most voted
1

answered Feb 20 '15

matman gravatar image

updated Feb 20 '15

If you use Opencv 3.0 I would prefer extractChannel(input, output, channel) instead of split(). I don't now if this function exists in OpenCV 2.X. But instead of extracting a COI you can directly access to a pixel by using:

uchar pixelValue = img.at<vec3b>(Point(x, y))[channel];

Where channel is the channel you like to read between 0 and 2 for a 3channel image. Consider that Vec3b is for 3 channel byte Mat, if you have an int Mat use Vec3i and so on.

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Feb 20 '15

Seen: 297 times

Last updated: Feb 20 '15