Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 使用OpenCV对彩色图像中的色调饱和度亮度进行均衡/规格化_Image Processing_Opencv - Fatal编程技术网

Image processing 使用OpenCV对彩色图像中的色调饱和度亮度进行均衡/规格化

Image processing 使用OpenCV对彩色图像中的色调饱和度亮度进行均衡/规格化,image-processing,opencv,Image Processing,Opencv,我想均衡同一主题的两个半边脸彩色图像,然后合并它们。每幅图像都有不同的色调饱和度和亮度值……使用opencv如何对每幅半图像进行规格化/均衡 我试着表演CVHist(v,v);在转换后的HSV图像的v值上,但两个图像仍然存在显著差异,并且在合并后,两半的颜色之间仍然有一条线…谢谢我不确定,因为我现在面临相同的问题, 但也许尝试平衡H&S值而不是V 还可以尝试使用Photoshop手动调整它,看看什么效果最好,然后尝试使用代码复制它。您尝试过阅读此链接吗 void Utils::Brightnes

我想均衡同一主题的两个半边脸彩色图像,然后合并它们。每幅图像都有不同的色调饱和度和亮度值……使用opencv如何对每幅半图像进行规格化/均衡


我试着表演CVHist(v,v);在转换后的HSV图像的v值上,但两个图像仍然存在显著差异,并且在合并后,两半的颜色之间仍然有一条线…谢谢

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


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

您尝试过阅读此链接吗

void Utils::BrightnessAndContrastAuto(常量cv::Mat&src,cv::Mat&dst,浮点clipHistPercent)
{
CV_断言(clipHistPercent>=0);
CV_断言((src.type()==CV_8UC1)| |(src.type()==CV_8UC3)| |(src.type()==CV_8UC4));
int histSize=256;
浮动α,β;
double minGray=0,maxGray=0;
//计算灰度直方图
cv::席灰色;
如果(src.type()==CV_8UC1)gray=src;
否则,如果(src.type()==CV_8UC3)cvtColor(src,gray,CV_bgr2 gray);
否则如果(src.type()==CV_8UC4)cvt颜色(src,灰色,CV_BGRA2GRAY);
如果(clipHistPercent==0)
{
//保持全部可用范围
cv::minMaxLoc(灰色、明雷和maxGray);
}
其他的
{
cv::Mat hist;//灰度直方图
浮动范围[]={0,256};
常量浮点*histRange={range};
布尔一致=真;
布尔累积=假;
calcHist(&gray,1,0,cv::Mat(),hist,1,&histSize,&histRange,统一,累积);
//根据直方图计算累积分布
std::向量累加器(histSize);
累加器[0]=在(0)处的历史记录;
对于(int i=1;i=(最大-clipHistPercent))
马克斯格雷--;
}
//电流范围
float inputRange=maxGray-minGray;
alpha=(histSize-1)/inputRange;//alpha将当前范围扩展到histSize范围
beta=-minGray*alpha;//beta移动当前范围,使minGray变为0
//应用亮度和对比度标准化
//convertTo与saurate_cast合作
src.convertTo(dst,-1,alpha,beta);
//从源还原alpha通道
如果(dst.type()=CV_8UC4)
{
int从_到[]={3,3};
cv::混合通道(&src,4,&dst,1,从_到,1);
}
返回;
}

您可以将图像上传到某个地方……您应该解释这是如何解决提问者的问题的。仅仅从代码上看,这并不明显。
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;
}