From a32d48625a1cbd09f8b37b29e1cedd6b56f501e8 Mon Sep 17 00:00:00 2001 From: miRoox Date: Mon, 16 Dec 2019 13:18:30 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=201.0.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现局部统计增强算法 --- DIP-src/DIP.pro | 2 +- DIP-src/algorithms.cpp | 45 ++++++++++++++++++++++++++++++++++++++++-- DIP-src/algorithms.h | 2 +- DIP-src/mainwindow.cpp | 2 +- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/DIP-src/DIP.pro b/DIP-src/DIP.pro index 0e556bf..a093419 100644 --- a/DIP-src/DIP.pro +++ b/DIP-src/DIP.pro @@ -5,7 +5,7 @@ TARGET = DIP CONFIG(release, debug|release): DESTDIR = ../bin -VERSION = 0.6.0 +VERSION = 1.0.0 QT += core gui charts diff --git a/DIP-src/algorithms.cpp b/DIP-src/algorithms.cpp index 6593650..18a9943 100644 --- a/DIP-src/algorithms.cpp +++ b/DIP-src/algorithms.cpp @@ -37,11 +37,52 @@ QImage equalizeHistogram(const QImage& image) //! 局部统计增强 QImage localStatisticalEnhance(const QImage &image, - double k0, double k1, double k2, double e, uint r) + double k0, double k1, double k2, double e, int r) { Q_ASSERT_X(image.format()==QImage::Format_Grayscale8,__func__,"Non-grayscale"); Q_ASSERT_X(k0>=0&&k0<=1&&k1<=k2&&e>=1&&r>=1,__func__,"Invalid parameter"); QImage out(image.size(),QImage::Format_Grayscale8); - out = image;//Do nothing; TODO: implement + const int width = image.width(); + const int height = image.height(); + const int size = width*height; + double g_mean = 0; + double g_std = 0; + for (int y=0; y=height) + continue; + const uint8_t* line = image.scanLine(yy); + for (int dx=-r; dx=width) + continue; + l_mean += line[xx]; + l_std += line[xx]*line[xx]; + l_size += 1; + } + } + l_mean /= l_size; + l_std = std::sqrt(l_std/l_size-l_mean*l_mean); // D(x)=E(x^2)-E(x)^2 + out_line[x] = l_mean<=k0*g_mean && l_std>=k1*g_std && l_std<=k2*g_std + ? static_cast(std::clamp(e*line[x],0.,1.*UINT8_MAX)) + : line[x]; + } + } return out; } diff --git a/DIP-src/algorithms.h b/DIP-src/algorithms.h index 8574b60..6a65a2b 100644 --- a/DIP-src/algorithms.h +++ b/DIP-src/algorithms.h @@ -7,6 +7,6 @@ QVector histogram(const QImage& image); QImage equalizeHistogram(const QImage& image); QImage localStatisticalEnhance(const QImage& image, - double k0, double k1, double k2, double E, uint r=1); + double k0, double k1, double k2, double E, int r=1); #endif // ALGORITHMS_H diff --git a/DIP-src/mainwindow.cpp b/DIP-src/mainwindow.cpp index 8c17afd..b8a4a0e 100644 --- a/DIP-src/mainwindow.cpp +++ b/DIP-src/mainwindow.cpp @@ -128,7 +128,7 @@ MainWindow::MainWindow(QWidget *parent) double k1 = k1Slider->value(); double k2 = k2Slider->value(); double E = eSlider->value(); - uint r = static_cast(rSlider->value()); + int r = static_cast(rSlider->value()); localEnh = localStatisticalEnhance(origin,k0,k1,k2,E,r); emit localEnhUpdated(); };