Ask Your Question

Converting a rgb image to hsv and to grayscale

asked 2014-01-08 09:58:05 -0500

souraklis gravatar image

I am working with a face recognition task. I am reading an rgb image and trying to convert it to hsv as I am trying to see if hsv is better for illumination issues.

       image = imread( path, 1 );
       cropped_rgb = image(faceRect).clone();
       cvtColor(cropped_rgb, cropped_hsv, CV_BGR2HSV);
       cvtColor(cropped_hsv, cropped_hsv, CV_BGR2GRAY);

I am trying to understand if there is a really difference between converting an rgb image to bgr_gray and rgb to bgr_gray. In fact when I plot cropped_hsv I ve got a weird result is not the same with rgb_gray image. Is this the final hsv_gray I want??

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2014-01-08 13:08:26 -0500

xaffeine gravatar image

If your original image is BGR and you want only gray-scale, skip the HSV stage and use CV_BGR2GRAY. Only if you are interested in saturation or hue, use CV_BGR2HSV. In the HSV color space, the V is the same as gray-scale. If you have RGB (opposite color-order from BGR), use CV_RGB2GRAY or CV_RGB2HSV instead of the BGR options.

edit flag offensive delete link more


How can I keep the V channel. Is the third dimension of the mat file??

souraklis gravatar imagesouraklis ( 2014-01-08 16:58:54 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-01-08 09:58:05 -0500

Seen: 4,930 times

Last updated: Jan 08 '14