comparison mupdf-source/thirdparty/tesseract/src/textord/imagefind.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: imagefind.h
3 // Description: Class to find image and drawing regions in an image
4 // and create a corresponding list of empty blobs.
5 // Author: Ray Smith
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 //
18 ///////////////////////////////////////////////////////////////////////
19
20 #ifndef TESSERACT_TEXTORD_IMAGEFIND_H_
21 #define TESSERACT_TEXTORD_IMAGEFIND_H_
22
23 #include "debugpixa.h"
24
25 #include <cstdint>
26
27 namespace tesseract {
28
29 class ColPartitionGrid;
30 class ColPartition_LIST;
31 class TabFind;
32 class TBOX;
33 class FCOORD;
34 class TO_BLOCK;
35
36 // The ImageFind class is a simple static function wrapper class that
37 // exposes the FindImages function and some useful helper functions.
38 class ImageFind {
39 public:
40 // Finds image regions within the BINARY source pix (page image) and returns
41 // the image regions as a mask image.
42 // The returned pix may be nullptr, meaning no images found.
43 // If not nullptr, it must be PixDestroyed by the caller.
44 // If textord_tabfind_show_images, debug images are appended to pixa_debug.
45 static Image FindImages(Image pix, DebugPixa *pixa_debug);
46
47 // Given an input pix, and a bounding rectangle, the sides of the rectangle
48 // are shrunk inwards until they bound any black pixels found within the
49 // original rectangle. Returns false if the rectangle contains no black
50 // pixels at all.
51 static bool BoundsWithinRect(Image pix, int *x_start, int *y_start, int *x_end, int *y_end);
52
53 // Given a point in 3-D (RGB) space, returns the squared Euclidean distance
54 // of the point from the given line, defined by a pair of points in the 3-D
55 // (RGB) space, line1 and line2.
56 static double ColorDistanceFromLine(const uint8_t *line1, const uint8_t *line2,
57 const uint8_t *point);
58
59 // Returns true if there are no black pixels in between the boxes.
60 // The im_box must represent the bounding box of the pix in tesseract
61 // coordinates, which may be negative, due to rotations to make the textlines
62 // horizontal. The boxes are rotated by rotation, which should undo such
63 // rotations, before mapping them onto the pix.
64 static bool BlankImageInBetween(const TBOX &box1, const TBOX &box2, const TBOX &im_box,
65 const FCOORD &rotation, Image pix);
66
67 // Returns the number of pixels in box in the pix.
68 // The im_box must represent the bounding box of the pix in tesseract
69 // coordinates, which may be negative, due to rotations to make the textlines
70 // horizontal. The boxes are rotated by rotation, which should undo such
71 // rotations, before mapping them onto the pix.
72 static int CountPixelsInRotatedBox(TBOX box, const TBOX &im_box, const FCOORD &rotation,
73 Image pix);
74
75 // Locates all the image partitions in the part_grid, that were found by a
76 // previous call to FindImagePartitions, marks them in the image_mask,
77 // removes them from the grid, and deletes them. This makes it possible to
78 // call FindImagePartitions again to produce less broken-up and less
79 // overlapping image partitions.
80 // rerotation specifies how to rotate the partition coords to match
81 // the image_mask, since this function is used after orientation correction.
82 static void TransferImagePartsToImageMask(const FCOORD &rerotation, ColPartitionGrid *part_grid,
83 Image image_mask);
84
85 // Runs a CC analysis on the image_pix mask image, and creates
86 // image partitions from them, cutting out strong text, and merging with
87 // nearby image regions such that they don't interfere with text.
88 // Rotation and rerotation specify how to rotate image coords to match
89 // the blob and partition coords and back again.
90 // The input/output part_grid owns all the created partitions, and
91 // the partitions own all the fake blobs that belong in the partitions.
92 // Since the other blobs in the other partitions will be owned by the block,
93 // ColPartitionGrid::ReTypeBlobs must be called afterwards to fix this
94 // situation and collect the image blobs.
95 static void FindImagePartitions(Image image_pix, const FCOORD &rotation, const FCOORD &rerotation,
96 TO_BLOCK *block, TabFind *tab_grid, DebugPixa *pixa_debug,
97 ColPartitionGrid *part_grid, ColPartition_LIST *big_parts);
98 };
99
100 } // namespace tesseract.
101
102 #endif // TESSERACT_TEXTORD_LINEFIND_H_