Friday, May 27, 2011

To use cvCvtColor

Be careful to use CV_BGR2HSV, the detail of the manual shows:
// In case of 8-bit and 16-bit images
// R, G and B are converted to floating-point format and scaled to fit 0..1 range

V <- max(R,G,B)
S <- (V-min(R,G,B))/V if V≠0, 0 otherwise

(G - B)*60/S, if V=R
H <- 180+(B - R)*60/S, if V=G
240+(R - G)*60/S, if V=B

if H<0 then H<-H+360

On output 0≤V≤1, 0≤S≤1, 0≤H≤360.
The values are then converted to the destination data type:
8-bit images:
V <- V*255, S <- S*255, H <- H/2 (to fit to 0..255)
16-bit images (currently not supported):
V <- V*65535, S <- S*65535, H <- H
32-bit images:
H, S, V are left as is

If the original image is float, you should manually convert the pixel values in the original image to [0, 1].

No comments: