tesseract v5.3.3.20231005
otsuthr.h
Go to the documentation of this file.
1
2// File: otsuthr.h
3// Description: Simple Otsu thresholding for binarizing images.
4// Author: Ray Smith
5//
6// (C) Copyright 2008, Google Inc.
7// Licensed under the Apache License, Version 2.0 (the "License");
8// you may not use this file except in compliance with the License.
9// You may obtain a copy of the License at
10// http://www.apache.org/licenses/LICENSE-2.0
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
18
19#ifndef TESSERACT_CCMAIN_OTSUTHR_H_
20#define TESSERACT_CCMAIN_OTSUTHR_H_
21
22#include "image.h"
23
24#include <vector> // for std::vector
25
26struct Pix;
27
28namespace tesseract {
29
30const int kHistogramSize = 256; // The size of a histogram of pixel values.
31
32// Computes the Otsu threshold(s) for the given image rectangle, making one
33// for each channel. Each channel is always one byte per pixel.
34// Returns an array of threshold values and an array of hi_values, such
35// that a pixel value >threshold[channel] is considered foreground if
36// hi_values[channel] is 0 or background if 1. A hi_value of -1 indicates
37// that there is no apparent foreground. At least one hi_value will not be -1.
38// The return value is the number of channels in the input image, being
39// the size of the output thresholds and hi_values arrays.
40int OtsuThreshold(Image src_pix, int left, int top, int width, int height,
41 std::vector<int> &thresholds,
42 std::vector<int> &hi_values);
43
44// Computes the histogram for the given image rectangle, and the given
45// single channel. Each channel is always one byte per pixel.
46// Histogram is always a kHistogramSize(256) element array to count
47// occurrences of each pixel value.
48void HistogramRect(Image src_pix, int channel, int left, int top, int width, int height,
49 int *histogram);
50
51// Computes the Otsu threshold(s) for the given histogram.
52// Also returns H = total count in histogram, and
53// omega0 = count of histogram below threshold.
54int OtsuStats(const int *histogram, int *H_out, int *omega0_out);
55
56} // namespace tesseract.
57
58#endif // TESSERACT_CCMAIN_OTSUTHR_H_
const int kHistogramSize
Definition: otsuthr.h:30
void HistogramRect(Image src_pix, int channel, int left, int top, int width, int height, int *histogram)
Definition: otsuthr.cpp:146
int OtsuStats(const int *histogram, int *H_out, int *omega0_out)
Definition: otsuthr.cpp:166
int OtsuThreshold(Image src_pix, int left, int top, int width, int height, std::vector< int > &thresholds, std::vector< int > &hi_values)
Definition: otsuthr.cpp:38