tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/ccstruct/otsuthr.h
Go to the documentation of this file.
00001 
00002 // File:        otsuthr.h
00003 // Description: Simple Otsu thresholding for binarizing images.
00004 // Author:      Ray Smith
00005 // Created:     Fri Mar 07 12:14:01 PST 2008
00006 //
00007 // (C) Copyright 2008, Google Inc.
00008 // Licensed under the Apache License, Version 2.0 (the "License");
00009 // you may not use this file except in compliance with the License.
00010 // You may obtain a copy of the License at
00011 // http://www.apache.org/licenses/LICENSE-2.0
00012 // Unless required by applicable law or agreed to in writing, software
00013 // distributed under the License is distributed on an "AS IS" BASIS,
00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 // See the License for the specific language governing permissions and
00016 // limitations under the License.
00017 //
00019 
00020 #ifndef TESSERACT_CCMAIN_OTSUTHR_H__
00021 #define TESSERACT_CCMAIN_OTSUTHR_H__
00022 
00023 struct Pix;
00024 
00025 namespace tesseract {
00026 
00027 const int kHistogramSize = 256;  // The size of a histogram of pixel values.
00028 
00029 // Computes the Otsu threshold(s) for the given image rectangle, making one
00030 // for each channel. Each channel is always one byte per pixel.
00031 // Returns an array of threshold values and an array of hi_values, such
00032 // that a pixel value >threshold[channel] is considered foreground if
00033 // hi_values[channel] is 0 or background if 1. A hi_value of -1 indicates
00034 // that there is no apparent foreground. At least one hi_value will not be -1.
00035 // Delete thresholds and hi_values with delete [] after use.
00036 // The return value is the number of channels in the input image, being
00037 // the size of the output thresholds and hi_values arrays.
00038 int OtsuThreshold(Pix* src_pix, int left, int top, int width, int height,
00039                   int** thresholds, int** hi_values);
00040 
00041 // Computes the histogram for the given image rectangle, and the given
00042 // single channel. Each channel is always one byte per pixel.
00043 // Histogram is always a kHistogramSize(256) element array to count
00044 // occurrences of each pixel value.
00045 void HistogramRect(Pix* src_pix, int channel,
00046                    int left, int top, int width, int height,
00047                    int* histogram);
00048 
00049 // Computes the Otsu threshold(s) for the given histogram.
00050 // Also returns H = total count in histogram, and
00051 // omega0 = count of histogram below threshold.
00052 int OtsuStats(const int* histogram, int* H_out, int* omega0_out);
00053 
00054 }  // namespace tesseract.
00055 
00056 #endif  // TESSERACT_CCMAIN_OTSUTHR_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines