Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // 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 namespace tesseract {
24 
25 const int kHistogramSize = 256; // The size of a histogram of pixel values.
26 
27 // Compute the Otsu threshold(s) for the given image rectangle, making one
28 // for each channel. Each channel is always one byte per pixel.
29 // Returns an array of threshold values and an array of hi_values, such
30 // that a pixel value >threshold[channel] is considered foreground if
31 // hi_values[channel] is 0 or background if 1. A hi_value of -1 indicates
32 // that there is no apparent foreground. At least one hi_value will not be -1.
33 // Delete thresholds and hi_values with delete [] after use.
34 void OtsuThreshold(const unsigned char* imagedata,
35  int bytes_per_pixel, int bytes_per_line,
36  int left, int top, int width, int height,
37  int** thresholds, int** hi_values);
38 
39 // Compute the histogram for the given image rectangle, and the given
40 // channel. (Channel pointed to by imagedata.) Each channel is always
41 // one byte per pixel.
42 // Bytes per pixel is used to skip channels not being
43 // counted with this call in a multi-channel (pixel-major) image.
44 // Histogram is always a 256 element array to count occurrences of
45 // each pixel value.
46 void HistogramRect(const unsigned char* imagedata,
47  int bytes_per_pixel, int bytes_per_line,
48  int left, int top, int width, int height,
49  int* histogram);
50 
51 // Compute the Otsu threshold(s) for the given histogram.
52 // Also returns H = total count in histogram, and
53 // omega0 = count of histogram below threshold.
54 int OtsuStats(const int* histogram, int* H_out, int* omega0_out);
55 
56 } // namespace tesseract.
57 
58 #endif // TESSERACT_CCMAIN_OTSUTHR_H__