简体   繁体   English

360 度图像中的对比度受限自适应直方图均衡

[英]Contrast Limited Adaptive Histogram Equalization in 360 images

I am currently applying the Contrast Limited Adaptive Histogram Equalization algorithm together with an algorithm to perform the photo denoise.我目前正在应用对比度受限自适应直方图均衡算法和算法来执行照片去噪。

My problem is that I am working with 360 photos.我的问题是我正在使用 360 度全景照片。 As the contrast generates different values at the edges when I join the photo, the edge line is highly noticeable.当我加入照片时,由于对比度在边缘产生不同的值,所以边缘线非常明显。 How can I mitigate that line?我怎样才能减轻那条线? What changes should I make so that it is not noticeable and the algorithm is applied consistently?我应该进行哪些更改以使其不明显并且算法始终如一地应用?

Original Photo:原始照片:

原始照片

Code to Contrast Limited Adaptive Histogram Equalization对比有限自适应直方图均衡的代码

    # CLAHE (Contrast Limited Adaptive Histogram Equalization)
    clahe = cv2.createCLAHE(clipLimit=1., tileGridSize=(6, 6))

    lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)  # convert from BGR to LAB color space
    l, a, b = cv2.split(lab)  # split on 3 different channels

    l2 = clahe.apply(l)  # apply CLAHE to the L-channel

    lab = cv2.merge((l2, a, b))  # merge channels
    img2 = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR)  # convert from LAB to BGR

Result:结果:

结果

360 performed: 360 执行:

360变形

It is highly notorious line of separation because it is not taken into account that the photo is joined later.这是非常臭名昭著的分隔线,因为它没有考虑到照片是稍后加入的。 What can I do?我能做些什么?

Here's an answer for C++, you can probably convert it easily to python/numpy.这是 C++ 的答案,您可以轻松地将其转换为 python/numpy。 The idea is to use a border region before performing CLAHE and crop the image afterwards.这个想法是在执行 CLAHE 之前使用边界区域,然后裁剪图像。

These are the subimage regions in the original image:这些是原始图像中的子图像区域: 在此处输入图像描述

and they will be copied the the left/right of the image like this:它们将被复制到图像的左/右,如下所示: 在此处输入图像描述

Maybe you can reduce the size of the border strongly:也许您可以强烈减小边框的大小:

int main()
{
    cv::Mat img = cv::imread("C:/data/SO_360.jpg");

    int borderSize = img.cols / 4;

    // make image that can have some border region
    cv::Mat borderImage = cv::Mat(cv::Size(img.cols + 2 * borderSize, img.rows), img.type());

    // posX, posY, width, height of the subimages
    cv::Rect leftBorderRegion = cv::Rect(0, 0, borderSize, borderImage.rows);
    cv::Rect rightBorderRegion = cv::Rect(borderImage.cols - borderSize, 0, borderSize, borderImage.rows);
    cv::Rect imgRegion = cv::Rect(borderSize, 0, img.cols, borderImage.rows);

    // original image regions to copy:
    cv::Rect left = cv::Rect(0, 0, borderSize, borderImage.rows);
    cv::Rect right = cv::Rect(img.cols - borderSize, 0, borderSize, img.rows);
    cv::Rect full = cv::Rect(0, 0, img.cols, img.rows);

    // perform copying to subimage (left part of the img goes to right part of the border image):
    img(left).copyTo(borderImage(rightBorderRegion));
    img(right).copyTo(borderImage(leftBorderRegion));
    img.copyTo(borderImage(imgRegion));

    cv::imwrite("SO_360_border.jpg", borderImage);

    //# CLAHE(Contrast Limited Adaptive Histogram Equalization)
    //clahe = cv2.createCLAHE(clipLimit = 1., tileGridSize = (6, 6))
    // apply the CLAHE algorithm to the L channel
    cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
    clahe->setClipLimit(1);
    clahe->setTilesGridSize(cv::Size(6, 6));

    cv::Mat lab;
    cv::cvtColor(borderImage, lab, cv::COLOR_BGR2Lab); //  # convert from BGR to LAB color space
    std::vector<cv::Mat> labChannels; //l, a, b = cv2.split(lab)  # split on 3 different channels
    cv::split(lab, labChannels);

    //l2 = clahe.apply(l)  # apply CLAHE to the L - channel
    cv::Mat dst;
    clahe->apply(labChannels[0], dst);

    labChannels[0] = dst;
    //lab = cv2.merge((l2, a, b))  # merge channels
    cv::merge(labChannels, lab);
    //img2 = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR)  # convert from LAB to BGR
    cv::cvtColor(lab, dst, cv::COLOR_Lab2BGR);

    cv::imwrite("SO_360_border_clahe.jpg", dst);

    // to crop the image after performing clahe:
    cv::Mat cropped = dst(imgRegion).clone();

    cv::imwrite("SO_360_clahe.jpg", cropped);
}

Images: input as in your original post.图片:输入您的原始帖子。

After creating the border:创建边框后: 在此处输入图像描述

After performing CLAHE (with border):执行 CLAHE(带边框)后: 在此处输入图像描述

After cropping the CLAHE-border-image:裁剪 CLAHE-border-image 后: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM