I've just read about HSV and what I found out is that the Hue, actually specifies that in what color range (like pink, orange,etc.) the color is, the Saturation specifies its tendency to white (the lower the value is, the whiter the color is) , and about the Value, it's just the same as Saturation, but about black color. I hope I've understood it correctly so far, because my actual question is, how can I get these H S V values from pixels? Is there a way I can get the values like I do for RGB? Or is there a way I can turn RGB values to HSV? Could someone help me on this please? Thanks. (I'm working with C++, and I shouldn't use OpenCV, I can only use CImg, and Imagemagick.)
-
Here you go - far too much information (including converting to RGB): https://en.wikipedia.org/wiki/HSL_and_HSV – Richard Critten Mar 18 '18 at 23:49
-
Pink is not a hue. Pink has red or purple hue, low saturation, and high value. Saturation is how vivid a color is, high saturation= vivid, low= dull,grayish. Very dark and very light colors all have low saturation. – Jive Dadson Mar 19 '18 at 04:08
2 Answers
how can I get these H S V values from pixels? Is there a way I can get the values like I do for RGB? Or is there a way I can turn RGB values to HSV?
With magick++ you would convert the colorspace to HSV, and access the color as RGB. Although the methods would still be red (hue), green (saturation), & blue (value).
#include <iostream>
#include <Magick++.h>
using namespace Magick;
using namespace std;
int main(int argc, const char * argv[]) {
InitializeMagick(*argv);
Image
rgb_img,
hsv_img;
rgb_img.read("rose:");
hsv_img.read("rose:");
Color point;
// Get Color @ index 10x10
point = rgb_img.pixelColor(10, 10);
cout << "Pixel Type : Default RGB Pixel" << endl;
cout << "First Channel : " << point.quantumRed() / QuantumRange << endl;
cout << "Second Channel : " << point.quantumGreen() / QuantumRange << endl;
cout << "Third Channel : " << point.quantumBlue() / QuantumRange << endl;
cout << endl;
// Convert to HSV
hsv_img.colorSpace(HSVColorspace);
// Get Color @ index 10x10
point = hsv_img.pixelColor(10, 10);
cout << "Pixel Type : HSV Pixel" << endl;
cout << "First Channel : " << point.quantumRed() / QuantumRange << endl;
cout << "Second Channel : " << point.quantumGreen() / QuantumRange << endl;
cout << "Third Channel : " << point.quantumBlue() / QuantumRange << endl;
cout << endl;
return 0;
}
Which would output...
Pixel Type : Default RGB Pixel
First Channel : 0.282353
Second Channel : 0.25098
Third Channel : 0.223529
Pixel Type : HSV Pixel
First Channel : 0.0777778
Second Channel : 0.208333
Third Channel : 0.282353

- 23,800
- 4
- 50
- 66
In Imagemagick command line, you can do:
convert -size 1x1 xc:red -colorspace HSV -format "%[pixel:u.p{0,0}]\n" info:
hsv(0,100%,100%)
or
convert lena.png[3x3+10+10] -colorspace HSV txt:
# ImageMagick pixel enumeration: 3,3,65535,hsv
0,0: (1944,34369,57825) #0886E1 hsv(11,52%,88%)
1,0: (1560,32622,57825) #067FE1 hsv(9,50%,88%)
2,0: (1643,33060,57568) #0681E0 hsv(9,50%,88%)
0,1: (2072,33787,57825) #0883E1 hsv(11,52%,88%)
1,1: (2129,34369,57825) #0886E1 hsv(12,52%,88%)
2,1: (2036,34678,57311) #0887DF hsv(11,53%,87%)
0,2: (1805,33347,58082) #0782E2 hsv(10,51%,89%)
1,2: (2012,33057,58082) #0881E2 hsv(11,50%,89%)
2,2: (1916,33204,57825) #0781E1 hsv(11,51%,88%)
Sorry, I do not know C++. I would think all you need to do is use the equivalent of -colorspace HSV and then do what you normal do for RGB.
If that does not work, then you could ask on the Imagemagick Discourse Server Users or Magick++ forum at https://www.imagemagick.org/discourse-server/
P.S. Looking at http://cimg.eu/reference/structcimg__library_1_1CImg.html#a6c0ab36ca2418c9b62590cdfdcbdc793, I see
CImg< T > & RGBtoHSV ()
Convert pixel values from RGB to HSV color spaces.

- 46,825
- 10
- 62
- 80