Skip to content

Commit

Permalink
版本 1.0.0
Browse files Browse the repository at this point in the history
实现局部统计增强算法
  • Loading branch information
miRoox committed Dec 16, 2019
1 parent e4130da commit a32d486
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DIP-src/DIP.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TARGET = DIP

CONFIG(release, debug|release): DESTDIR = ../bin

VERSION = 0.6.0
VERSION = 1.0.0

QT += core gui charts

Expand Down
45 changes: 43 additions & 2 deletions DIP-src/algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; ++y) {
const uint8_t* line = image.scanLine(y);
for (int x=0; x<width; ++x) {
g_mean += line[x];
g_std += line[x]*line[x];
}
}
g_mean /= size;
g_std = std::sqrt(g_std/size-g_mean*g_mean); // D(x)=E(x^2)-E(x)^2
for (int y=0; y<height; ++y) {
const uint8_t* line = image.scanLine(y);
uint8_t* out_line = out.scanLine(y);
for (int x=0; x<width; ++x) {
double l_mean = 0;
double l_std = 0;
uint l_size = 0;
for (int dy=-r; dy<r; ++dy) {
const int yy = y+dy;
if (yy<0 || yy>=height)
continue;
const uint8_t* line = image.scanLine(yy);
for (int dx=-r; dx<r; ++dx) {
const int xx = x+dx;
if (xx<0 || x>=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<uint8_t>(std::clamp(e*line[x],0.,1.*UINT8_MAX))
: line[x];
}
}
return out;
}
2 changes: 1 addition & 1 deletion DIP-src/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
QVector<double> 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
2 changes: 1 addition & 1 deletion DIP-src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ MainWindow::MainWindow(QWidget *parent)
double k1 = k1Slider->value();
double k2 = k2Slider->value();
double E = eSlider->value();
uint r = static_cast<uint>(rSlider->value());
int r = static_cast<int>(rSlider->value());
localEnh = localStatisticalEnhance(origin,k0,k1,k2,E,r);
emit localEnhUpdated();
};
Expand Down

0 comments on commit a32d486

Please sign in to comment.