【问题标题】:How are HSV color values used? [closed]如何使用 HSV 颜色值? [关闭]
【发布时间】:2018-03-18 23:32:41
【问题描述】:

我刚刚阅读了有关 HSV 的内容,我发现色相实际上指定了颜色在什么颜色范围内(如粉红色、橙色等),饱和度指定了它向白色的趋势(越低)值是,颜色越白) ,关于值,它与饱和度相同,但与黑色有关。我希望到目前为止我已经正确理解了它,因为我的实际问题是,如何从像素中获取这些 H S V 值?有没有办法像获取 RGB 一样获取值?或者有没有办法可以将 RGB 值转换为 HSV?有人可以帮我吗?谢谢。 (我正在使用 C++,我不应该使用 OpenCV,我只能使用 CImg 和 Imagemagick。)

【问题讨论】:

  • 给你 - 太多信息(包括转换为 RGB):en.wikipedia.org/wiki/HSL_and_HSV
  • 粉红色不是色调。粉红色具有红色或紫色的色调,饱和度低,价值高。饱和度是颜色的鲜艳程度,高饱和度=鲜艳,低=暗淡,灰暗。非常深和非常浅的颜色都具有低饱和度。

标签: c++ imagemagick rgb hsv cimg


【解决方案1】:

如何从像素中获取这些 H S V 值?有没有办法像获取 RGB 一样获取值?或者有没有办法可以将 RGB 值转换为 HSV?

使用,您可以将颜色空间转换为 HSV,并将颜色作为 RGB 访问。虽然方法仍然是红色(色调)、绿色(饱和度)和蓝色(值)。

#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;
}

哪个会输出...

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

【讨论】:

  • @emcconville 感谢您提供正确的magick++代码。
【解决方案2】:

在 Imagemagick 命令行中,您可以:

convert -size 1x1 xc:red -colorspace HSV -format "%[pixel:u.p{0,0}]\n" info:
hsv(0,100%,100%)

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%)

对不起,我不懂 C++。我认为您需要做的就是使用 -colorspace HSV 的等效项,然后执行您通常为 RGB 执行的操作。

如果这不起作用,那么您可以在 Imagemagick Discourse Server Users 或 Magick++ 论坛上提问https://www.imagemagick.org/discourse-server/

附:看着http://cimg.eu/reference/structcimg__library_1_1CImg.html#a6c0ab36ca2418c9b62590cdfdcbdc793,我明白了

CImg< T > &     RGBtoHSV ()
    Convert pixel values from RGB to HSV color spaces. 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多