Skip to content

Commit

Permalink
Thresholding: Change smooth scaling logic
Browse files Browse the repository at this point in the history
As suggested by @bertsky.
  • Loading branch information
amitdo committed Oct 15, 2021
1 parent 9a1ad43 commit 0aeb2e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
10 changes: 6 additions & 4 deletions src/ccmain/tesseractclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ Tesseract::Tesseract()
"Debug the thresholding process",
this->params())
, double_MEMBER(thresholding_window_size, 0.33,
"Window size for measuring local statistics (to be multiplied by image DPI). "
"Window size for measuring local statistics (to be "
"multiplied by image DPI). "
"This parameter is used by the Sauvola thresolding method",
this->params())
, double_MEMBER(thresholding_kfactor, 0.34,
Expand All @@ -96,10 +97,11 @@ Tesseract::Tesseract()
"This parameter is used by the LeptonicaOtsu thresolding "
"method",
this->params())
, double_MEMBER(thresholding_smooth_kernel_size, 1.0,
"Size of convolution kernel applied to threshold array. "
, double_MEMBER(thresholding_smooth_kernel_size, 0.0,
"Size of convolution kernel applied to threshold array "
"(to be multiplied by image DPI). Use 0 for no smoothing. "
"This parameter is used by the LeptonicaOtsu thresolding "
"method. Range: 0.0-1.0",
"method",
this->params())
, double_MEMBER(thresholding_score_fraction, 0.1,
"Fraction of the max Otsu score. "
Expand Down
19 changes: 7 additions & 12 deletions src/ccmain/thresholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,29 +255,24 @@ std::tuple<bool, Image, Image, Image> ImageThresholder::Threshold(
tile_size = tile_size_factor * yres_;
tile_size = std::max(16, tile_size);

int smooth_size_x, smooth_size_y;
int smooth_size;
double smooth_size_factor;
api->GetDoubleVariable("thresholding_smooth_kernel_size",
&smooth_size_factor);
smooth_size_factor = std::min(1.0, smooth_size_factor);
if (smooth_size_factor > 0) {
smooth_size_x = smooth_size_factor * pix_w / tile_size;
smooth_size_y = smooth_size_factor * pix_h / tile_size;
} else {
smooth_size_x = 0;
smooth_size_y = 0;
}
smooth_size_factor = std::max(0.0, smooth_size_factor);
smooth_size = smooth_size_factor * yres_;
int half_smooth_size = smooth_size / 2;

double score_fraction;
api->GetDoubleVariable("thresholding_score_fraction", &score_fraction);

if (thresholding_debug) {
tprintf("\ntile size: %d smooth_size_x: %d smooth_size_y: %d score_fraction: %f", tile_size, smooth_size_x, smooth_size_y, score_fraction);
tprintf("\ntile size: %d smooth_size: %d score_fraction: %f", tile_size, smooth_size, score_fraction);
}

r = pixOtsuAdaptiveThreshold(pix_grey, tile_size, tile_size,
smooth_size_x / 2, smooth_size_y / 2,
score_fraction,
half_smooth_size, half_smooth_size,
score_fraction,
(PIX**)pix_thresholds,
(PIX**)pix_binary);
}
Expand Down

0 comments on commit 0aeb2e7

Please sign in to comment.