File: speckle.cpp

package info (click to toggle)
tesseract 2.04-2%2Bsqueeze1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 7,336 kB
  • ctags: 6,860
  • sloc: cpp: 81,388; sh: 3,446; java: 1,220; makefile: 376
file content (127 lines) | stat: -rw-r--r-- 5,057 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/******************************************************************************
 **	Filename:    speckle.c
 **	Purpose:     Routines used by classifier to filter out speckle.
 **	Author:      Dan Johnson
 **	History:     Mon Mar 11 10:06:14 1991, DSJ, Created.
 **
 **	(c) Copyright Hewlett-Packard Company, 1988.
 ** Licensed under the Apache License, Version 2.0 (the "License");
 ** you may not use this file except in compliance with the License.
 ** You may obtain a copy of the License at
 ** http://www.apache.org/licenses/LICENSE-2.0
 ** Unless required by applicable law or agreed to in writing, software
 ** distributed under the License is distributed on an "AS IS" BASIS,
 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 ** See the License for the specific language governing permissions and
 ** limitations under the License.
 ******************************************************************************/
/**----------------------------------------------------------------------------
          Include Files and Type Defines
----------------------------------------------------------------------------**/
#include "speckle.h"
#include "debug.h"
#include "blobs.h"

/**----------------------------------------------------------------------------
        Global Data Definitions and Declarations
----------------------------------------------------------------------------**/
/* define control knobs for adjusting definition of speckle*/
make_float_var (MaxLargeSpeckleSize, 0.30, MakeMaxLargeSpeckleSize,
16, 2, SetMaxLargeSpeckleSize, "Max Large Speckle Size ...");

make_float_var (SmallSpecklePenalty, 10.0, MakeSmallSpecklePenalty,
16, 3, SetSmallSpecklePenalty, "Small Speckle Penalty ...");

make_float_var (LargeSpecklePenalty, 10.0, MakeLargeSpecklePenalty,
16, 4, SetLargeSpecklePenalty, "Large Speckle Penalty ...");

make_float_var (SmallSpeckleCertainty, -1.0, MakeSmallSpeckleCertainty,
16, 5, SetSmallSpeckleCertainty,
"Small Speckle Certainty ...");

/**----------------------------------------------------------------------------
              Public Code
----------------------------------------------------------------------------**/
/*---------------------------------------------------------------------------*/
LIST AddLargeSpeckleTo(LIST Choices) {
/*
 **	Parameters:
 **		Choices		choices to add a speckle choice to
 **	Globals:
 **		SmallSpecklePenalty	rating for a small speckle
 **		LargeSpecklePenalty	rating penalty for a large speckle
 **		SmallSpeckleCertainty	certainty for a small speckle
 **	Operation: This routine adds a null choice to Choices with a
 **		rating equal to the worst rating in Choices plus a pad.
 **		The certainty of the new choice is the same as the
 **		certainty of the worst choice in Choices.  The new choice
 **		is added to the end of Choices.
 **	Return: New Choices list with null choice added to end.
 **	Exceptions: none
 **	History: Mon Mar 11 11:08:11 1991, DSJ, Created.
 */
  LIST WorstChoice;
  char empty_lengths[] = {0};

  /* if there are no other choices, use the small speckle penalty plus
     the large speckle penalty */
  if (Choices == NIL)
    return (append_choice (NIL, "", empty_lengths, SmallSpecklePenalty + LargeSpecklePenalty,
      SmallSpeckleCertainty, -1));

  /* if there are other choices,  add a null choice that is slightly worse
     than the worst choice so far */
  WorstChoice = last (Choices);
  return (append_choice (Choices, "", empty_lengths,
    best_probability (WorstChoice) + LargeSpecklePenalty,
    best_certainty (WorstChoice), -1));

}                                /* AddLargeSpeckleTo */


/*---------------------------------------------------------------------------*/
void InitSpeckleVars() {
/*
 **	Parameters: none
 **	Globals: none
 **	Operation: Install the control variables needed for the speckle
 **		filters.
 **	Return: none
 **	Exceptions: none
 **	History: Mon Mar 11 12:04:59 1991, DSJ, Created.
 */
  MakeMaxLargeSpeckleSize();
  MakeSmallSpecklePenalty();
  MakeLargeSpecklePenalty();
  MakeSmallSpeckleCertainty();
}                                /* InitSpeckleVars */


/*---------------------------------------------------------------------------*/
BOOL8 LargeSpeckle(TBLOB *Blob, TEXTROW *Row) {
/*
 **	Parameters:
 **		Blob		blob to test against speckle criteria
 **		Row		text row that blob is in
 **	Globals:
 **		MaxLargeSpeckleSize	largest allowed speckle
 **	Operation: This routine returns TRUE if both the width of height
 **		of Blob are less than the MaxLargeSpeckleSize.
 **	Return: TRUE if Blob is speckle, FALSE otherwise.
 **	Exceptions: none
 **	History: Mon Mar 11 10:06:49 1991, DSJ, Created.
 */
  FLOAT32 SpeckleSize;
  TPOINT TopLeft;
  TPOINT BottomRight;

  SpeckleSize = RowHeight (Row) * MaxLargeSpeckleSize;
  blob_bounding_box(Blob, &TopLeft, &BottomRight);

  if (TopLeft.y - BottomRight.y < SpeckleSize &&
    BottomRight.x - TopLeft.x < SpeckleSize)
    return (TRUE);
  else
    return (FALSE);

}                                /* LargeSpeckle */