Reputation: 71
I am a beginner in both Image Processing and Opencv. I am trying to find out the individual pixel intensities of an image, using OPENCV#. There is assistance here: http://docs.opencv.org/doc/user_guide/ug_mat.html?highlight=pixel%20intensity for the same issue. But I am not sure how to use it in OPENCV#. I know this is a very basic query. Please try to help out. Thanks in advance.
Upvotes: 4
Views: 16202
Reputation: 518
Pixel intensity is the same thing as that pixel's grayscale value. To get a grayscale (pixel intensity) version of an BGR image you can do this:
cv::cvtColor(bgr_mat,gray_mat,CV_BGR2GRAY);
Now the 3 channel BGR image has been converted to a 1 channel GRAYSCALE image. To find the intensity of pixel (x,y) in the gray image you can do this:
//NOTE: in OpenCV pixels are accessed in (row,col) format
int intensity = (int)gray_mat.at<uchar>(y,x);
Since each grayscale pixel is stored as uchar, the value of intensity
will range from (0-255) where 255 is maximum intensity (seen as a completely white pixel).
Upvotes: 4
Reputation: 2974
in emgu cv, you can do it like this.
//Color
//Red
byte Red_val = My_Image.Data[y,x,0];
//Green
byte Green_val = My_Image.Data[y,x,1];
//Blue
byte Blue_val = My_Image.Data[y,x,2];
//Greyscale
byte Gray_val = My_Image.Data[y,x,0];
Upvotes: 1