Ask Your Question
0

Doubt about how to access a pixel in cvMat structure

asked 2015-02-20 10:13:14 -0500

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.

edit retag flag offensive close merge delete

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 ( 2015-02-20 10:50:37 -0500 )edit

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

Potato gravatar imagePotato ( 2015-02-20 13:03:37 -0500 )edit

Thank you!

Diego Moreira gravatar imageDiego Moreira ( 2015-02-21 13:22:11 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-02-20 11:34:36 -0500

matman gravatar image

updated 2015-02-20 12:20:53 -0500

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.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-02-20 10:13:14 -0500

Seen: 162 times

Last updated: Feb 20 '15