【问题标题】:equalize/normalize Hue Saturation Brightness in color images with OpenCV使用 OpenCV 均衡/归一化彩色图像中的色相饱和度亮度
【发布时间】:2011-08-22 18:58:28
【问题描述】:

我想均衡同一主题的两个半面彩色图像,然后合并它们。他们每个人都有不同的色调饱和度和亮度值......使用opencv我如何标准化/均衡每个半图像?

我尝试执行 cvEqualizeHist(v, v);在转换后的 HSV 图像的 v 值上,但是两个图像仍然有显着差异,并且在合并后两半的颜色之间仍然有一条线...谢谢

【问题讨论】:

  • 你可以把你的图片上传到某个地方...

标签: image-processing opencv


【解决方案1】:

你试过阅读这个链接吗? http://answers.opencv.org/question/75510/how-to-make-auto-adjustmentsbrightness-and-contrast-for-image-android-opencv-image-correction/

void Utils::BrightnessAndContrastAuto(const cv::Mat &src, cv::Mat &dst, float clipHistPercent)
{

    CV_Assert(clipHistPercent >= 0);
    CV_Assert((src.type() == CV_8UC1) || (src.type() == CV_8UC3) || (src.type() == CV_8UC4));

    int histSize = 256;
    float alpha, beta;
    double minGray = 0, maxGray = 0;

    //to calculate grayscale histogram
    cv::Mat gray;
    if (src.type() == CV_8UC1) gray = src;
    else if (src.type() == CV_8UC3) cvtColor(src, gray, CV_BGR2GRAY);
    else if (src.type() == CV_8UC4) cvtColor(src, gray, CV_BGRA2GRAY);
    if (clipHistPercent == 0)
    {
        // keep full available range
        cv::minMaxLoc(gray, &minGray, &maxGray);
    }
    else
    {
        cv::Mat hist; //the grayscale histogram

        float range[] = { 0, 256 };
        const float* histRange = { range };
        bool uniform = true;
        bool accumulate = false;
        calcHist(&gray, 1, 0, cv::Mat(), hist, 1, &histSize, &histRange, uniform, accumulate);

        // calculate cumulative distribution from the histogram
        std::vector<float> accumulator(histSize);
        accumulator[0] = hist.at<float>(0);
        for (int i = 1; i < histSize; i++)
        {
            accumulator[i] = accumulator[i - 1] + hist.at<float>(i);
        }

        // locate points that cuts at required value
        float max = accumulator.back();
        clipHistPercent *= (max / 100.0); //make percent as absolute
        clipHistPercent /= 2.0; // left and right wings
        // locate left cut
        minGray = 0;
        while (accumulator[minGray] < clipHistPercent)
            minGray++;

        // locate right cut
        maxGray = histSize - 1;
        while (accumulator[maxGray] >= (max - clipHistPercent))
            maxGray--;
    }

    // current range
    float inputRange = maxGray - minGray;

    alpha = (histSize - 1) / inputRange;   // alpha expands current range to histsize range
    beta = -minGray * alpha;             // beta shifts current range so that minGray will go to 0

    // Apply brightness and contrast normalization
    // convertTo operates with saurate_cast
    src.convertTo(dst, -1, alpha, beta);

    // restore alpha channel from source 
    if (dst.type() == CV_8UC4)
    {
        int from_to[] = { 3, 3 };
        cv::mixChannels(&src, 4, &dst, 1, from_to, 1);
    }
    return;
}

【讨论】:

  • 你应该解释这如何解决提问者的问题。仅从代码中并不能立即看出这一点。
【解决方案2】:

我不确定,因为我现在面临同样的问题, 但也许尝试均衡 H & S 值而不是 V?

也可以尝试使用 Photoshop 手动调整它,看看什么效果最好,然后尝试使用代码复制它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-20
    • 1970-01-01
    • 2012-12-03
    • 2023-03-25
    • 2013-02-07
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    相关资源
    最近更新 更多