Tesseract
3.02
|
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 namespace tesseract { 00024 00025 const int kHistogramSize = 256; // The size of a histogram of pixel values. 00026 00027 // Compute the Otsu threshold(s) for the given image rectangle, making one 00028 // for each channel. Each channel is always one byte per pixel. 00029 // Returns an array of threshold values and an array of hi_values, such 00030 // that a pixel value >threshold[channel] is considered foreground if 00031 // hi_values[channel] is 0 or background if 1. A hi_value of -1 indicates 00032 // that there is no apparent foreground. At least one hi_value will not be -1. 00033 // Delete thresholds and hi_values with delete [] after use. 00034 void OtsuThreshold(const unsigned char* imagedata, 00035 int bytes_per_pixel, int bytes_per_line, 00036 int left, int top, int width, int height, 00037 int** thresholds, int** hi_values); 00038 00039 // Compute the histogram for the given image rectangle, and the given 00040 // channel. (Channel pointed to by imagedata.) Each channel is always 00041 // one byte per pixel. 00042 // Bytes per pixel is used to skip channels not being 00043 // counted with this call in a multi-channel (pixel-major) image. 00044 // Histogram is always a 256 element array to count occurrences of 00045 // each pixel value. 00046 void HistogramRect(const unsigned char* imagedata, 00047 int bytes_per_pixel, int bytes_per_line, 00048 int left, int top, int width, int height, 00049 int* histogram); 00050 00051 // Compute the Otsu threshold(s) for the given histogram. 00052 // Also returns H = total count in histogram, and 00053 // omega0 = count of histogram below threshold. 00054 int OtsuStats(const int* histogram, int* H_out, int* omega0_out); 00055 00056 } // namespace tesseract. 00057 00058 #endif // TESSERACT_CCMAIN_OTSUTHR_H__