Convert HSV to grayscale in OpenCV

后端 未结 4 1281
忘了有多久
忘了有多久 2020-12-17 00:06

I\'m a newbie in OpenCV. I\'m learning the Segmentation by Watershed algorithm and I have a problem.

I have to convert the image color to grayscale for using Watershe

4条回答
  •  Happy的楠姐
    2020-12-17 00:57

    in HSV color-space, V channel is defined as max(R, G, B) but in gray-scale, value is defined by mean(R, G, B). in RGB2HSV conversion, we use these formulas for S and V channel:

    V = max(R, G, B)
    S = (max(R, G, B) - min(R, G, B)) / max(R, G, B)
    

    so if S is zero, max(R, G, B) equals to min(R, G, B) and they are equal to mean(R, G, B). so if this criteria holds, V channel is equal to gray-scale value. other wise, they are different.

    one way is to convert image to RGB and then convert it to GRAY. but if you look for a more straight way, you can use picture below:

    HSV2RGB converion

    and hence gray value is mean(R, G, B) you can calculate it as:

    gray = m + (c + x) / 3
    

    where you can compute m,c and x from formula in image.

提交回复
热议问题