Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.20: threshold: new method Grad #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/app/DefaultParamsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ DefaultParamsDialog::DefaultParamsDialog(QWidget* parent)
fillingColorBox->addItem(tr("White"), FILL_WHITE);
fillingColorBox->addItem(tr("Black"), FILL_BLACK);

thresholdMethodBox->addItem(tr("Otsu"), OTSU);
thresholdMethodBox->addItem(tr("Sauvola"), SAUVOLA);
thresholdMethodBox->addItem(tr("Wolf"), WOLF);
thresholdMethodBox->addItem(tr("Bradley"), BRADLEY);
thresholdMethodBox->addItem(tr("EdgePlus"), EDGEPLUS);
thresholdMethodBox->addItem(tr("BlurDiv"), BLURDIV);
thresholdMethodBox->addItem(tr("EdgeDiv"), EDGEDIV);
thresholdMethodBox->addItem(tr("Otsu"), T_OTSU);
thresholdMethodBox->addItem(tr("Sauvola"), T_SAUVOLA);
thresholdMethodBox->addItem(tr("Wolf"), T_WOLF);
thresholdMethodBox->addItem(tr("Bradley"), T_BRADLEY);
thresholdMethodBox->addItem(tr("Grad"), T_GRAD);
thresholdMethodBox->addItem(tr("EdgePlus"), T_EDGEPLUS);
thresholdMethodBox->addItem(tr("BlurDiv"), T_BLURDIV);
thresholdMethodBox->addItem(tr("EdgeDiv"), T_EDGEDIV);

pictureShapeSelector->addItem(tr("Off"), OFF_SHAPE);
pictureShapeSelector->addItem(tr("Free"), FREE_SHAPE);
Expand Down Expand Up @@ -666,10 +667,10 @@ std::unique_ptr<DefaultParams> DefaultParamsDialog::buildParams() const {
blackWhiteOptions.setBinarizationMethod(binarizationMethod);
blackWhiteOptions.setThresholdAdjustment(thresholdSlider->value());
blackWhiteOptions.setSauvolaCoef(sauvolaCoef->value());
if (binarizationMethod == SAUVOLA || binarizationMethod == BRADLEY || binarizationMethod == EDGEPLUS
|| binarizationMethod == BLURDIV || binarizationMethod == EDGEDIV) {
if (binarizationMethod == T_SAUVOLA || binarizationMethod == T_BRADLEY || binarizationMethod == T_EDGEPLUS
|| binarizationMethod == T_BLURDIV || binarizationMethod == T_EDGEDIV) {
blackWhiteOptions.setWindowSize(sauvolaWindowSize->value());
} else if (binarizationMethod == WOLF) {
} else if (binarizationMethod == T_WOLF || binarizationMethod == T_GRAD) {
blackWhiteOptions.setWindowSize(wolfWindowSize->value());
}
blackWhiteOptions.setWolfCoef(wolfCoef->value());
Expand Down
2 changes: 1 addition & 1 deletion src/core/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#ifndef SCANTAILOR_CORE_UTILS_H_
#define SCANTAILOR_CORE_UTILS_H_

#include <QString>
#include <QObject>
#include <QString>
#include <map>
#include <unordered_map>

Expand Down
35 changes: 20 additions & 15 deletions src/core/filters/output/BlackWhiteOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BlackWhiteOptions::BlackWhiteOptions()
m_wolfLowerBound(1),
m_wolfUpperBound(254),
m_wolfCoef(0.3),
m_binarizationMethod(OTSU) {}
m_binarizationMethod(T_OTSU) {}

BlackWhiteOptions::BlackWhiteOptions(const QDomElement& el)
: m_thresholdAdjustment(el.attribute("thresholdAdj").toInt()),
Expand Down Expand Up @@ -69,44 +69,49 @@ bool BlackWhiteOptions::operator!=(const BlackWhiteOptions& other) const {

BinarizationMethod BlackWhiteOptions::parseBinarizationMethod(const QString& str) {
if (str == "wolf") {
return WOLF;
return T_WOLF;
} else if (str == "sauvola") {
return SAUVOLA;
return T_SAUVOLA;
} else if (str == "bradley") {
return BRADLEY;
return T_BRADLEY;
} else if (str == "grad") {
return T_GRAD;
} else if (str == "edgeplus") {
return EDGEPLUS;
return T_EDGEPLUS;
} else if (str == "blurdiv") {
return BLURDIV;
return T_BLURDIV;
} else if (str == "edgediv") {
return EDGEDIV;
return T_EDGEDIV;
} else {
return OTSU;
return T_OTSU;
}
}

QString BlackWhiteOptions::formatBinarizationMethod(BinarizationMethod type) {
QString str = "";
switch (type) {
case OTSU:
case T_OTSU:
str = "otsu";
break;
case SAUVOLA:
case T_SAUVOLA:
str = "sauvola";
break;
case WOLF:
case T_WOLF:
str = "wolf";
break;
case BRADLEY:
case T_BRADLEY:
str = "bradley";
break;
case EDGEPLUS:
case T_GRAD:
str = "grad";
break;
case T_EDGEPLUS:
str = "edgeplus";
break;
case BLURDIV:
case T_BLURDIV:
str = "blurdiv";
break;
case EDGEDIV:
case T_EDGEDIV:
str = "edgediv";
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/filters/output/BlackWhiteOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class QDomDocument;
class QDomElement;

namespace output {
enum BinarizationMethod { OTSU, SAUVOLA, WOLF, BRADLEY, EDGEPLUS, BLURDIV, EDGEDIV };
enum BinarizationMethod { T_OTSU, T_SAUVOLA, T_WOLF, T_BRADLEY, T_GRAD, T_EDGEPLUS, T_BLURDIV, T_EDGEDIV };

class BlackWhiteOptions {
public:
Expand Down
17 changes: 10 additions & 7 deletions src/core/filters/output/OptionsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ OptionsWidget::OptionsWidget(std::shared_ptr<Settings> settings, const PageSelec
colorModeSelector->addItem(tr("Color / Grayscale"), COLOR_GRAYSCALE);
colorModeSelector->addItem(tr("Mixed"), MIXED);

thresholdMethodBox->addItem(tr("Otsu"), OTSU);
thresholdMethodBox->addItem(tr("Sauvola"), SAUVOLA);
thresholdMethodBox->addItem(tr("Wolf"), WOLF);
thresholdMethodBox->addItem(tr("Bradley"), BRADLEY);
thresholdMethodBox->addItem(tr("EdgePlus"), EDGEPLUS);
thresholdMethodBox->addItem(tr("BlurDiv"), BLURDIV);
thresholdMethodBox->addItem(tr("EdgeDiv"), EDGEDIV);
thresholdMethodBox->addItem(tr("Otsu"), T_OTSU);
thresholdMethodBox->addItem(tr("Sauvola"), T_SAUVOLA);
thresholdMethodBox->addItem(tr("Wolf"), T_WOLF);
thresholdMethodBox->addItem(tr("Bradley"), T_BRADLEY);
thresholdMethodBox->addItem(tr("Grad"), T_GRAD);
thresholdMethodBox->addItem(tr("EdgePlus"), T_EDGEPLUS);
thresholdMethodBox->addItem(tr("BlurDiv"), T_BLURDIV);
thresholdMethodBox->addItem(tr("EdgeDiv"), T_EDGEDIV);

fillingColorBox->addItem(tr("Background"), FILL_BACKGROUND);
fillingColorBox->addItem(tr("White"), FILL_WHITE);
Expand All @@ -57,6 +58,7 @@ OptionsWidget::OptionsWidget(std::shared_ptr<Settings> settings, const PageSelec
QPointer<BinarizationOptionsWidget> wolfBinarizationOptionsWidget = new WolfBinarizationOptionsWidget(m_settings);
QPointer<BinarizationOptionsWidget> bradleyBinarizationOptionsWidget
= new SauvolaBinarizationOptionsWidget(m_settings);
QPointer<BinarizationOptionsWidget> gradBinarizationOptionsWidget = new WolfBinarizationOptionsWidget(m_settings);
QPointer<BinarizationOptionsWidget> edgeplusBinarizationOptionsWidget
= new SauvolaBinarizationOptionsWidget(m_settings);
QPointer<BinarizationOptionsWidget> blurdivBinarizationOptionsWidget
Expand All @@ -71,6 +73,7 @@ OptionsWidget::OptionsWidget(std::shared_ptr<Settings> settings, const PageSelec
addBinarizationOptionsWidget(sauvolaBinarizationOptionsWidget);
addBinarizationOptionsWidget(wolfBinarizationOptionsWidget);
addBinarizationOptionsWidget(bradleyBinarizationOptionsWidget);
addBinarizationOptionsWidget(gradBinarizationOptionsWidget);
addBinarizationOptionsWidget(edgeplusBinarizationOptionsWidget);
addBinarizationOptionsWidget(blurdivBinarizationOptionsWidget);
addBinarizationOptionsWidget(edgedivBinarizationOptionsWidget);
Expand Down
24 changes: 17 additions & 7 deletions src/core/filters/output/OutputGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2294,22 +2294,22 @@ BinaryImage OutputGenerator::Processor::binarize(const QImage& image) const {

BinaryImage binarized;
switch (binarizationMethod) {
case OTSU: {
case T_OTSU: {
GrayscaleHistogram hist(image);
const BinaryThreshold bwThresh(BinaryThreshold::otsuThreshold(hist));

binarized = BinaryImage(image, adjustThreshold(bwThresh));
break;
}
case SAUVOLA: {
case T_SAUVOLA: {
const double thresholdDelta = blackWhiteOptions.thresholdAdjustment();
const QSize windowsSize = QSize(blackWhiteOptions.getWindowSize(), blackWhiteOptions.getWindowSize());
const double thresholdCoef = blackWhiteOptions.getSauvolaCoef();

binarized = binarizeSauvola(image, windowsSize, thresholdCoef, thresholdDelta);
break;
}
case WOLF: {
case T_WOLF: {
const double thresholdDelta = blackWhiteOptions.thresholdAdjustment();
const QSize windowsSize = QSize(blackWhiteOptions.getWindowSize(), blackWhiteOptions.getWindowSize());
const auto lowerBound = (unsigned char) blackWhiteOptions.getWolfLowerBound();
Expand All @@ -2319,31 +2319,41 @@ BinaryImage OutputGenerator::Processor::binarize(const QImage& image) const {
binarized = binarizeWolf(image, windowsSize, lowerBound, upperBound, thresholdCoef, thresholdDelta);
break;
}
case BRADLEY: {
case T_BRADLEY: {
const double thresholdDelta = blackWhiteOptions.thresholdAdjustment();
const QSize windowsSize = QSize(blackWhiteOptions.getWindowSize(), blackWhiteOptions.getWindowSize());
const double thresholdCoef = blackWhiteOptions.getSauvolaCoef();

binarized = binarizeBradley(image, windowsSize, thresholdCoef, thresholdDelta);
break;
}
case EDGEPLUS: {
case T_GRAD: {
const double thresholdDelta = blackWhiteOptions.thresholdAdjustment();
const QSize windowsSize = QSize(blackWhiteOptions.getWindowSize(), blackWhiteOptions.getWindowSize());
const auto lowerBound = (unsigned char) blackWhiteOptions.getWolfLowerBound();
const auto upperBound = (unsigned char) blackWhiteOptions.getWolfUpperBound();
const double thresholdCoef = blackWhiteOptions.getWolfCoef();

binarized = binarizeGrad(image, windowsSize, lowerBound, upperBound, thresholdCoef, thresholdDelta);
break;
}
case T_EDGEPLUS: {
const double thresholdDelta = blackWhiteOptions.thresholdAdjustment();
const QSize windowsSize = QSize(blackWhiteOptions.getWindowSize(), blackWhiteOptions.getWindowSize());
const double thresholdCoef = blackWhiteOptions.getSauvolaCoef();

binarized = binarizeEdgeDiv(image, windowsSize, thresholdCoef, 0.0, thresholdDelta);
break;
}
case BLURDIV: {
case T_BLURDIV: {
const double thresholdDelta = blackWhiteOptions.thresholdAdjustment();
const QSize windowsSize = QSize(blackWhiteOptions.getWindowSize(), blackWhiteOptions.getWindowSize());
const double thresholdCoef = blackWhiteOptions.getSauvolaCoef();

binarized = binarizeEdgeDiv(image, windowsSize, 0.0, thresholdCoef, thresholdDelta);
break;
}
case EDGEDIV: {
case T_EDGEDIV: {
const double thresholdDelta = blackWhiteOptions.thresholdAdjustment();
const QSize windowsSize = QSize(blackWhiteOptions.getWindowSize(), blackWhiteOptions.getWindowSize());
const double thresholdCoef = blackWhiteOptions.getSauvolaCoef();
Expand Down
Loading
Loading