Tesseract  3.02
tesseract-ocr/classify/speckle.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  **     Filename:    speckle.c
00003  **     Purpose:     Routines used by classifier to filter out speckle.
00004  **     Author:      Dan Johnson
00005  **     History:     Mon Mar 11 10:06:14 1991, DSJ, Created.
00006  **
00007  **     (c) Copyright Hewlett-Packard Company, 1988.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  ******************************************************************************/
00018 /*-----------------------------------------------------------------------------
00019           Include Files and Type Defines
00020 -----------------------------------------------------------------------------*/
00021 #include "speckle.h"
00022 
00023 #include "blobs.h"
00024 #include "ratngs.h"
00025 #include "params.h"
00026 
00027 /*-----------------------------------------------------------------------------
00028         Global Data Definitions and Declarations
00029 -----------------------------------------------------------------------------*/
00031 double_VAR(speckle_large_max_size, 0.30, "Max large speckle size");
00032 
00033 double_VAR(speckle_small_penalty, 10.0, "Small speckle penalty");
00034 
00035 double_VAR(speckle_large_penalty, 10.0, "Large speckle penalty");
00036 
00037 double_VAR(speckle_small_certainty, -1.0, "Small speckle certainty");
00038 
00039 /*-----------------------------------------------------------------------------
00040               Public Code
00041 -----------------------------------------------------------------------------*/
00042 /*---------------------------------------------------------------------------*/
00062 void AddLargeSpeckleTo(BLOB_CHOICE_LIST *Choices) {
00063   assert(Choices != NULL);
00064   BLOB_CHOICE *blob_choice;
00065   BLOB_CHOICE_IT temp_it;
00066   temp_it.set_to_list(Choices);
00067 
00068   // If there are no other choices, use the small speckle penalty plus
00069   // the large speckle penalty.
00070   if (Choices->length() == 0) {
00071     blob_choice =
00072       new BLOB_CHOICE(0, speckle_small_certainty + speckle_large_penalty,
00073                       speckle_small_certainty, -1, -1, NULL, 0, 0, false);
00074     temp_it.add_to_end(blob_choice);
00075     return;
00076   }
00077 
00078   // If there are other choices,  add a null choice that is slightly worse
00079   // than the worst choice so far.
00080   temp_it.move_to_last();
00081   blob_choice = temp_it.data();  // pick the worst choice
00082   temp_it.add_to_end(
00083       new BLOB_CHOICE(0, blob_choice->rating() + speckle_large_penalty,
00084                       blob_choice->certainty(), -1, -1, NULL, 0, 0, false));
00085 }                                /* AddLargeSpeckleTo */
00086 
00087 
00088 /*---------------------------------------------------------------------------*/
00103 BOOL8 LargeSpeckle(TBLOB *blob) {
00104   double speckle_size = BASELINE_SCALE * speckle_large_max_size;
00105   TBOX bbox = blob->bounding_box();
00106   return (bbox.width() < speckle_size && bbox.height() < speckle_size);
00107 }                                /* LargeSpeckle */