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

0.2.15: threshold: new method Grad #138

Merged
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
2 changes: 1 addition & 1 deletion config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define PIXMAPS_DIR_ABS "@PIXMAPS_DIR_ABS@"
#define APPLICATION_NAME "Scan Tailor Universal"
#define ORGANIZATION_NAME APPLICATION_NAME
#define ORGANIZATION_NAME "Scan Tailor"
#define ORGANIZATION_DOMAIN "github.com/trufanov-nok/scantailor-universal"

#cmakedefine ENABLE_OPENGL
Expand Down
37 changes: 22 additions & 15 deletions src/core/filters/output/BlackWhiteOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace output
BlackWhiteOptions::BlackWhiteOptions():
m_thresholdAdjustment(GlobalStaticSettings::m_binrization_threshold_control_default),
m_thresholdForegroundAdjustment(m_thresholdAdjustment),
m_thresholdMethod(OTSU),
m_thresholdMethod(T_OTSU),
m_thresholdWindowSize(200),
m_thresholdCoef(0.3)
{
Expand Down Expand Up @@ -101,31 +101,35 @@ BlackWhiteOptions::parseThresholdMethod(QString const& str)
{
if (str == "sauvola")
{
return SAUVOLA;
return T_SAUVOLA;
}
else if (str == "wolf")
{
return WOLF;
return T_WOLF;
}
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;
}
}

Expand All @@ -135,25 +139,28 @@ BlackWhiteOptions::formatThresholdMethod(ThresholdFilter 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 @@ -26,7 +26,7 @@ class QDomElement;
namespace output
{

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

class BlackWhiteOptions
{
Expand Down
21 changes: 11 additions & 10 deletions src/core/filters/output/OptionsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ OptionsWidget::OptionsWidget(
{
setupUi(this);

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

setDespeckleLevel(DESPECKLE_NORMAL);

Expand Down Expand Up @@ -282,8 +283,8 @@ OptionsWidget::thresholdWindowSizeChanged(int value) {
blackWhiteOptions.setThresholdWindowSize(value);
m_colorParams.setBlackWhiteOptions(blackWhiteOptions);
m_ptrSettings->setColorParams(m_pageId, m_colorParams);
if (blackWhiteOptions.thresholdMethod() != OTSU)
emit reloadRequested();
if (blackWhiteOptions.thresholdMethod() != T_OTSU)
emit reloadRequested();
}

void
Expand Down Expand Up @@ -633,7 +634,7 @@ OptionsWidget::updateColorsDisplay()
thresholdSlider->setValue(blackWhiteOptions.thresholdAdjustment());
thresholdWindowSize->setValue(blackWhiteOptions.thresholdWindowSize());
thresholdCoef->setValue(blackWhiteOptions.thresholdCoef());
if (blackWhiteOptions.thresholdMethod() == OTSU)
if (blackWhiteOptions.thresholdMethod() == T_OTSU)
{
thresholdWindowSize->setEnabled( false );
thresholdCoef->setEnabled( false );
Expand Down
19 changes: 12 additions & 7 deletions src/core/filters/output/OutputGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2059,39 +2059,44 @@ OutputGenerator::binarize(QImage const& image, BinaryImage const& mask, const in
{
switch (thresholdMethod)
{
case OTSU:
case T_OTSU:
{
GrayscaleHistogram hist(image, mask);
BinaryThreshold const bw_thresh(BinaryThreshold::otsuThreshold(hist));
binarized = BinaryImage(image, adjustThreshold(bw_thresh, adjustment));
break;
}
case SAUVOLA:
case T_SAUVOLA:
{
binarized = binarizeSauvola(image, window_size, threshold_coef, threshold_delta);
break;
}
case WOLF:
case T_WOLF:
{
binarized = binarizeWolf(image, window_size, 1, 254, threshold_coef, threshold_delta);
break;
}
case BRADLEY:
case T_BRADLEY:
{
binarized = binarizeBradley(image, window_size, threshold_coef, threshold_delta);
break;
}
case EDGEPLUS:
case T_GRAD:
{
binarized = binarizeGrad(image, window_size, threshold_coef, threshold_delta);
break;
}
case T_EDGEPLUS:
{
binarized = binarizeEdgeDiv(image, window_size, threshold_coef, 0.0, threshold_delta);
break;
}
case BLURDIV:
case T_BLURDIV:
{
binarized = binarizeEdgeDiv(image, window_size, 0.0, threshold_coef, threshold_delta);
break;
}
case EDGEDIV:
case T_EDGEDIV:
{
binarized = binarizeEdgeDiv(image, window_size, threshold_coef, threshold_coef, threshold_delta);
break;
Expand Down
Loading
Loading