comparison mupdf-source/thirdparty/tesseract/src/classify/normfeat.cpp @ 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 ** Filename: normfeat.c
3 ** Purpose: Definition of char normalization features.
4 ** Author: Dan Johnson
5 **
6 ** (c) Copyright Hewlett-Packard Company, 1988.
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 #include "normfeat.h"
19
20 #include "featdefs.h"
21 #include "intfx.h"
22 #include "mfoutline.h"
23
24 namespace tesseract {
25
26 /** Return the length of the outline in baseline normalized form. */
27 float ActualOutlineLength(FEATURE Feature) {
28 return (Feature->Params[CharNormLength] * LENGTH_COMPRESSION);
29 }
30
31 /**
32 * Return the character normalization feature for a blob.
33 *
34 * The features returned are in a scale where the x-height has been
35 * normalized to live in the region y = [-0.25 .. 0.25]. Example ranges
36 * for English below are based on the Linux font collection on 2009-12-04:
37 *
38 * - Params[CharNormY]
39 * - The y coordinate of the grapheme's centroid.
40 * - English: [-0.27, 0.71]
41 *
42 * - Params[CharNormLength]
43 * - The length of the grapheme's outline (tiny segments discarded),
44 * divided by 10.0=LENGTH_COMPRESSION.
45 * - English: [0.16, 0.85]
46 *
47 * - Params[CharNormRx]
48 * - The radius of gyration about the x axis, as measured from CharNormY.
49 * - English: [0.011, 0.34]
50 *
51 * - Params[CharNormRy]
52 * - The radius of gyration about the y axis, as measured from
53 * the x center of the grapheme's bounding box.
54 * - English: [0.011, 0.31]
55 */
56 FEATURE_SET ExtractCharNormFeatures(const INT_FX_RESULT_STRUCT &fx_info) {
57 auto feature_set = new FEATURE_SET_STRUCT(1);
58 auto feature = new FEATURE_STRUCT(&CharNormDesc);
59
60 feature->Params[CharNormY] = MF_SCALE_FACTOR * (fx_info.Ymean - kBlnBaselineOffset);
61 feature->Params[CharNormLength] = MF_SCALE_FACTOR * fx_info.Length / LENGTH_COMPRESSION;
62 feature->Params[CharNormRx] = MF_SCALE_FACTOR * fx_info.Rx;
63 feature->Params[CharNormRy] = MF_SCALE_FACTOR * fx_info.Ry;
64
65 AddFeature(feature_set, feature);
66
67 return feature_set;
68 } /* ExtractCharNormFeatures */
69
70 } // namespace tesseract