You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenCV与Photoshop色相调整的颜色差异问题

问题:OpenCV色相调整与Photoshop结果不一致

图像对比

问题描述:
我在使用OpenCV为图像数据应用指定色相值时遇到颜色问题。应用**+50**色相值后,输出颜色与Photoshop中设置+50色相的结果不一致。

  • 第一张截图为未应用色相调整的原始图像。
  • 第二张截图为在Photoshop中应用+50色相后的图像。
  • 第三张截图为使用OpenCV代码应用+50色相后的图像(显示于ImGui中)。

疑问:
如何调整代码,使图像效果与Photoshop中应用**+50**色相后的效果一致?

以下代码中,currentImage为CV::Mat格式的图像数据,hueFactor代表应用的色相值,此处为**+50**。

我实现了如下函数:

cv::Mat apply_hue_for_data(cv::Mat &currentImage, float hueFactor) { 

    // Create the output image with the same size and type as the current image
    cv::Mat outputImage = currentImage.clone();

    // Separate the alpha channel
    std::vector<cv::Mat> channels(4);
    cv::split(outputImage, channels);
    cv::Mat alpha = channels[3];

    // Convert the image from BGR to HSV
    cv::cvtColor(outputImage, outputImage, cv::COLOR_BGRA2BGR);
    cv::cvtColor(outputImage, outputImage, cv::COLOR_BGR2HSV);

    // Loop through the rows
    for (int y = 0; y < outputImage.rows; ++y) {
        // Loop through the columns
        for (int x = 0; x < outputImage.cols; ++x) {
            // Retrieve the pixel value
            cv::Vec3b &pixelValue = outputImage.at<cv::Vec3b>(y, x);

            // Adjust the hue value
            int hue = static_cast<int>(pixelValue[0]) + static_cast<int>(hueFactor * 179.0f);
            
            // Ensure the hue value wraps around correctly within the 0-179 range
            hue = hue % 180;
            if (hue < 0) {
                hue += 180;
            }
            pixelValue[0] = static_cast<uchar>(hue);
        }
    }

    // Convert the image back to BGR
    cv::cvtColor(outputImage, outputImage, cv::COLOR_HSV2BGR);

    // Merge the alpha channel back
    std::vector<cv::Mat> bgrChannels;
    cv::split(outputImage, bgrChannels);
    std::vector<cv::Mat> bgraChannels = {bgrChannels[0], bgrChannels[1], bgrChannels[2], alpha};
    cv::merge(bgraChannels, outputImage);

    // Return the modified image data
    return outputImage;

}

盼求解!我尝试使用上述代码调整图像色相,但结果与Photoshop中的效果不符。

内容的提问来源于stack exchange,提问作者User298

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 00:52:35