首页 文章

如何使用HSV颜色值? [关闭]

提问于
浏览
-3

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

2 回答

  • 1

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

    使用magick++,您可以将色彩空间转换为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
    
  • 0

    在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话语服务器用户或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.
    

相关问题