From RGB to HSV in OpenGL GLSL

I am the author of the second implementation. It has always behaved correctly for me, but you wrote 2.9 / 6.9 instead of 2.0 / 6.0. Since you target GLSL, you should use conversion routines that are written with the GPU in mind: // All components are in the range [0…1], including hue. vec3 rgb2hsv(vec3 … Read more

Tracking white color using python opencv

Let’s take a look at HSV color space: You need white, which is close to the center and rather high. Start with sensitivity = 15 lower_white = np.array([0,0,255-sensitivity]) upper_white = np.array([255,sensitivity,255]) and then adjust the threshold to your needs. You might also consider using HSL color space, which stands for Hue, Saturation, Lightness. Then you … Read more

Finding red color in image using Python & OpenCV

I would just add the masks together, and use np.where to mask the original image. img=cv2.imread(“img.bmp”) img_hsv=cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # lower mask (0-10) lower_red = np.array([0,50,50]) upper_red = np.array([10,255,255]) mask0 = cv2.inRange(img_hsv, lower_red, upper_red) # upper mask (170-180) lower_red = np.array([170,50,50]) upper_red = np.array([180,255,255]) mask1 = cv2.inRange(img_hsv, lower_red, upper_red) # join my masks mask = mask0+mask1 … Read more

HSV to RGB Color Conversion

That function expects decimal for s (saturation) and v (value), not percent. Divide by 100. >>> import colorsys # Using percent, incorrect >>> test_color = colorsys.hsv_to_rgb(359,100,100) >>> test_color (100, -9900.0, -9900.0) # Using decimal, correct >>> test_color = colorsys.hsv_to_rgb(1,1,1) >>> test_color (1, 0.0, 0.0) If you would like the non-normalized RGB tuple, here is a … Read more

HSB vs HSL vs HSV

Is HSB same as HSL? No. HSB is the same as HSV, but HSL is different. All these are used as a friendly way to represent RGB colors. The Wikipedia article on HSL an HSV explains the differences using color cylinders: HSL and HSV. Basically, Hue is the same for HSB and HSL but the … Read more

How to Convert RGB Color to HSV?

Note that Color.GetSaturation() and Color.GetBrightness() return HSL values, not HSV. The following code demonstrates the difference. Color original = Color.FromArgb(50, 120, 200); // original = {Name=ff3278c8, ARGB=(255, 50, 120, 200)} double hue; double saturation; double value; ColorToHSV(original, out hue, out saturation, out value); // hue = 212.0 // saturation = 0.75 // value = 0.78431372549019607 … Read more

How to compare two colors for similarity/difference

See Wikipedia’s article on Color Difference for the right leads. Basically, you want to compute a distance metric in some multidimensional colorspace. But RGB is not “perceptually uniform”, so your Euclidean RGB distance metric suggested by Vadim will not match the human-perceived distance between colors. For a start, L*a*b* is intended to be a perceptually … Read more

tech