Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
speckle.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: speckle.c
3  ** Purpose: Routines used by classifier to filter out speckle.
4  ** Author: Dan Johnson
5  ** History: Mon Mar 11 10:06:14 1991, DSJ, Created.
6  **
7  ** (c) Copyright Hewlett-Packard Company, 1988.
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  Include Files and Type Defines
20 -----------------------------------------------------------------------------*/
21 #include "speckle.h"
22 
23 #include "blobs.h"
24 #include "ratngs.h"
25 #include "params.h"
26 
27 /*-----------------------------------------------------------------------------
28  Global Data Definitions and Declarations
29 -----------------------------------------------------------------------------*/
31 double_VAR(speckle_large_max_size, 0.30, "Max large speckle size");
32 
33 double_VAR(speckle_small_penalty, 10.0, "Small speckle penalty");
34 
35 double_VAR(speckle_large_penalty, 10.0, "Large speckle penalty");
36 
37 double_VAR(speckle_small_certainty, -1.0, "Small speckle certainty");
38 
39 /*-----------------------------------------------------------------------------
40  Public Code
41 -----------------------------------------------------------------------------*/
42 /*---------------------------------------------------------------------------*/
62 void AddLargeSpeckleTo(BLOB_CHOICE_LIST *Choices) {
63  assert(Choices != NULL);
64  BLOB_CHOICE *blob_choice;
65  BLOB_CHOICE_IT temp_it;
66  temp_it.set_to_list(Choices);
67 
68  // If there are no other choices, use the small speckle penalty plus
69  // the large speckle penalty.
70  if (Choices->length() == 0) {
71  blob_choice =
73  speckle_small_certainty, -1, -1, NULL, 0, 0, false);
74  temp_it.add_to_end(blob_choice);
75  return;
76  }
77 
78  // If there are other choices, add a null choice that is slightly worse
79  // than the worst choice so far.
80  temp_it.move_to_last();
81  blob_choice = temp_it.data(); // pick the worst choice
82  temp_it.add_to_end(
83  new BLOB_CHOICE(0, blob_choice->rating() + speckle_large_penalty,
84  blob_choice->certainty(), -1, -1, NULL, 0, 0, false));
85 } /* AddLargeSpeckleTo */
86 
87 
88 /*---------------------------------------------------------------------------*/
104  double speckle_size = BASELINE_SCALE * speckle_large_max_size;
105  TBOX bbox = blob->bounding_box();
106  return (bbox.width() < speckle_size && bbox.height() < speckle_size);
107 } /* LargeSpeckle */