Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/ccstruct/otsuthr.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 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 // | |
| 17 /////////////////////////////////////////////////////////////////////// | |
| 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 | |
| 26 struct Pix; | |
| 27 | |
| 28 namespace tesseract { | |
| 29 | |
| 30 const 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. | |
| 40 int 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. | |
| 48 void 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. | |
| 54 int OtsuStats(const int *histogram, int *H_out, int *omega0_out); | |
| 55 | |
| 56 } // namespace tesseract. | |
| 57 | |
| 58 #endif // TESSERACT_CCMAIN_OTSUTHR_H_ |
