Take the 2-minute tour ×

In MATLAB, i read a color video , extract a certain frame and convert it to a gray scale image using the rgb2gray function.But when I load the same video with OpenCV2.3.1, extract the same frame and then convert it to gray scale it doesn't give the same gray scale values as MATLAB. Why is that?

This is the C++ code using OpenCV:

VideoCapture cap(0);    
cap.open("Human sperm evaluation_0.avi");    

Mat image;    
Mat gray(480,640,CV_8U);    

for(int i=0;i<513;i++)

        cout<<(int)gray.at<uchar>(i,j)<<' ';
share|improve this question
Is the image in MATLAB of uint8 type or you convert it to double? –  Sassa Sep 6 '12 at 22:41

1 Answer 1

First, all color images in OpenCV are BGR and not RGB so maybe one of the problems could be that OpenCV is making the transformation wrong. You should use BGR2GRAY. And second, If I remember well in matlab yo should specify which are the ranges of values in your image. You have to put between 0 and 255 for a gray image.

I hope this can help you.

share|improve this answer

Your Answer


