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