91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

OpenCV C++版圖像去霧技術對比

發布時間:2024-08-18 17:49:33 來源:億速云 閱讀:90 作者:小樊 欄目:編程語言

圖像去霧是一種重要的圖像增強技術,可以有效地提高圖像的清晰度和細節。在OpenCV中,有多種圖像去霧算法可以實現,比較常用的有Dark Channel Prior和Fast Visibility Restoration等算法。

下面我們將分別使用Dark Channel Prior和Fast Visibility Restoration算法對同一張含有霧的圖像進行處理,然后進行對比。

首先是Dark Channel Prior算法的實現代碼:

#include <opencv2/opencv.hpp>

using namespace cv;

Mat dehazeDarkChannelPrior(Mat& src, double w = 0.95, int r = 15) {
    Mat src_gray;
    cvtColor(src, src_gray, COLOR_BGR2GRAY);

    Mat dark_channel = Mat::zeros(src.size(), CV_8UC1);
    for (int i = 0; i < src.rows; ++i) {
        for (int j = 0; j < src.cols; ++j) {
            Vec3b pixel = src.at<Vec3b>(i, j);
            dark_channel.at<uchar>(i, j) = std::min({ pixel[0], pixel[1], pixel[2] });
        }
    }

    Mat dark_channel_blur;
    boxFilter(dark_channel, dark_channel_blur, CV_8UC1, Size(r, r));

    Mat A = Mat::zeros(src.size(), CV_8UC1);
    for (int i = 0; i < src.rows; ++i) {
        for (int j = 0; j < src.cols; ++j) {
            A.at<uchar>(i, j) = dark_channel_blur.at<uchar>(i, j);
        }
    }

    Mat transmission = Mat::zeros(src.size(), CV_64FC1);
    for (int i = 0; i < src.rows; ++i) {
        for (int j = 0; j < src.cols; ++j) {
            transmission.at<double>(i, j) = 1.0 - w * dark_channel.at<uchar>(i, j) / A.at<uchar>(i, j);
        }
    }

    Mat transmission_blur;
    boxFilter(transmission, transmission_blur, CV_64FC1, Size(r, r));

    Mat dehazed = Mat::zeros(src.size(), CV_8UC3);
    for (int i = 0; i < src.rows; ++i) {
        for (int j = 0; j < src.cols; ++j) {
            Vec3b pixel = src.at<Vec3b>(i, j);
            dehazed.at<Vec3b>(i, j) = pixel - (pixel - A.at<uchar>(i, j)) / transmission_blur.at<double>(i, j);
        }
    }

    return dehazed;
}

int main() {
    Mat src = imread("foggy_image.jpg");

    Mat dehazed = dehazeDarkChannelPrior(src);

    imshow("Original", src);
    imshow("Dehazed Dark Channel Prior", dehazed);
    waitKey();

    return 0;
}

然后是Fast Visibility Restoration算法的實現代碼:

#include <opencv2/opencv.hpp>

using namespace cv;

Mat dehazeFastVisibilityRestoration(Mat& src, double beta = 1.0, double omega = 0.95, int r = 60) {
    Mat src_gray;
    cvtColor(src, src_gray, COLOR_BGR2GRAY);

    Mat dark_channel = Mat::zeros(src.size(), CV_8UC1);
    for (int i = 0; i < src.rows; ++i) {
        for (int j = 0; j < src.cols; ++j) {
            Vec3b pixel = src.at<Vec3b>(i, j);
            dark_channel.at<uchar>(i, j) = std::min({ pixel[0], pixel[1], pixel[2] });
        }
    }

    Mat dark_channel_blur;
    boxFilter(dark_channel, dark_channel_blur, CV_8UC1, Size(r, r));

    Mat A = Mat::zeros(src.size(), CV_8UC1);
    for (int i = 0; i < src.rows; ++i) {
        for (int j = 0; j < src.cols; ++j) {
            A.at<uchar>(i, j) = dark_channel_blur.at<uchar>(i, j);
        }
    }

    Mat transmission = Mat::zeros(src.size(), CV_64FC1);
    for (int i = 0; i < src.rows; ++i) {
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

c++
AI

桂阳县| 南华县| 莱州市| 宁安市| 五莲县| 高青县| 汝阳县| 菏泽市| 扬中市| 巩留县| 广汉市| 敖汉旗| 拉孜县| 龙南县| 河东区| 从化市| 华池县| 曲沃县| 焦作市| 宣威市| 靖江市| 青岛市| 新兴县| 开阳县| 秦安县| 镶黄旗| 垣曲县| 泰兴市| 晋州市| 巩留县| 怀集县| 荣成市| 建湖县| 航空| 阿克陶县| 朝阳市| 额济纳旗| 无锡市| 广河县| 夏邑县| 苏尼特右旗|