Skip to content

Commit d6805c2

Browse files
committed
Avoid error in pixSauvolaBinarizeTiled (issue #4390)
Don't use Sauvola binarization if the image has a width or height which is too small. Use LeptonicaOtsu as a fallback in this case. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 7474a0f commit d6805c2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/ccmain/thresholder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ std::tuple<bool, Image, Image, Image> ImageThresholder::Threshold(
207207
tprintf("\nimage width: %d height: %d ppi: %d\n", pix_w, pix_h, yres_);
208208
}
209209

210-
if (method == ThresholdMethod::Sauvola) {
210+
if (method == ThresholdMethod::Sauvola && pix_w > 6 && pix_h > 6) {
211+
// pixSauvolaBinarizeTiled requires half_window_size >= 2.
212+
// Therefore window_size must be at least 4 which requires
213+
// pix_w and pix_h to be at least 7.
211214
int window_size;
212215
double window_size_factor;
213216
api->GetDoubleVariable("thresholding_window_size", &window_size_factor);

0 commit comments

Comments
 (0)