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

Contrast Limited Adaptive Histogram Equalization in 360 images

我目前正在应用对比度受限自适应直方图均衡算法以及执行照片降噪的算法。

我的问题是我正在处理 360 度全景照片。当我加入照片时,对比度在边缘产生不同的值,因此边缘线非常明显。我怎样才能减轻那条线?我应该进行哪些更改才能使它不明显并且始终如一地应用算法?

原图:

对比有限自适应直方图均衡的代码

    # 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

结果:

360 次执行:

这是非常臭名昭著的分隔线,因为它没有考虑到照片稍后加入。我能做什么?

这是 C++ 的答案,您可以很容易地将其转换为 python/numpy。 这个想法是在执行 CLAHE 之前使用边界区域并在之后裁剪图像。

这些是原始图像中的子图像区域:

它们将被复制到图像的 left/right 中,如下所示:

也许你可以强烈减小边框的尺寸:

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);
}

图片: 按照原来的方式输入 post.

创建边框后:

执行 CLAHE 后(带边框):

裁剪 CLAHE-border-image 后: