2007-03-08 04:03:40 +08:00
|
|
|
/******************************************************************************
|
|
|
|
** 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.
|
|
|
|
******************************************************************************/
|
2010-07-27 21:23:23 +08:00
|
|
|
/*-----------------------------------------------------------------------------
|
2007-03-08 04:03:40 +08:00
|
|
|
Include Files and Type Defines
|
2010-07-27 21:23:23 +08:00
|
|
|
-----------------------------------------------------------------------------*/
|
2007-03-08 04:03:40 +08:00
|
|
|
#include "speckle.h"
|
2009-07-11 10:17:36 +08:00
|
|
|
|
2007-03-08 04:03:40 +08:00
|
|
|
#include "blobs.h"
|
2009-07-11 10:17:36 +08:00
|
|
|
#include "ratngs.h"
|
2010-11-24 02:34:14 +08:00
|
|
|
#include "params.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2010-07-27 21:23:23 +08:00
|
|
|
/*-----------------------------------------------------------------------------
|
2007-03-08 04:03:40 +08:00
|
|
|
Global Data Definitions and Declarations
|
2010-07-27 21:23:23 +08:00
|
|
|
-----------------------------------------------------------------------------*/
|
|
|
|
/** define control knobs for adjusting definition of speckle*/
|
2009-07-11 10:17:36 +08:00
|
|
|
double_VAR(speckle_large_max_size, 0.30, "Max large speckle size");
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2009-07-11 10:17:36 +08:00
|
|
|
double_VAR(speckle_small_penalty, 10.0, "Small speckle penalty");
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2009-07-11 10:17:36 +08:00
|
|
|
double_VAR(speckle_large_penalty, 10.0, "Large speckle penalty");
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2009-07-11 10:17:36 +08:00
|
|
|
double_VAR(speckle_small_certainty, -1.0, "Small speckle certainty");
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2010-07-27 21:23:23 +08:00
|
|
|
/*-----------------------------------------------------------------------------
|
2007-03-08 04:03:40 +08:00
|
|
|
Public Code
|
2010-07-27 21:23:23 +08:00
|
|
|
-----------------------------------------------------------------------------*/
|
2007-03-08 04:03:40 +08:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-07-27 21:23:23 +08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Globals:
|
|
|
|
* - #speckle_small_penalty rating for a small speckle
|
|
|
|
* - #speckle_large_penalty rating penalty for a large speckle
|
|
|
|
* - #speckle_small_certainty certainty for a small speckle
|
|
|
|
*
|
|
|
|
* @param Choices choices to add a speckle choice to
|
|
|
|
*
|
|
|
|
* @return New Choices list with null choice added to end.
|
|
|
|
*
|
|
|
|
* Exceptions: none
|
|
|
|
* History: Mon Mar 11 11:08:11 1991, DSJ, Created.
|
2007-03-08 04:03:40 +08:00
|
|
|
*/
|
2010-07-27 21:23:23 +08:00
|
|
|
void AddLargeSpeckleTo(BLOB_CHOICE_LIST *Choices) {
|
2009-07-11 10:17:36 +08:00
|
|
|
assert(Choices != NULL);
|
|
|
|
BLOB_CHOICE *blob_choice;
|
|
|
|
BLOB_CHOICE_IT temp_it;
|
|
|
|
temp_it.set_to_list(Choices);
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2009-07-11 10:17:36 +08:00
|
|
|
// If there are no other choices, use the small speckle penalty plus
|
|
|
|
// the large speckle penalty.
|
|
|
|
if (Choices->length() == 0) {
|
|
|
|
blob_choice =
|
|
|
|
new BLOB_CHOICE(0, speckle_small_certainty + speckle_large_penalty,
|
2012-02-02 10:57:42 +08:00
|
|
|
speckle_small_certainty, -1, -1, NULL, 0, 0, false);
|
2009-07-11 10:17:36 +08:00
|
|
|
temp_it.add_to_end(blob_choice);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2009-07-11 10:17:36 +08:00
|
|
|
// If there are other choices, add a null choice that is slightly worse
|
|
|
|
// than the worst choice so far.
|
|
|
|
temp_it.move_to_last();
|
|
|
|
blob_choice = temp_it.data(); // pick the worst choice
|
|
|
|
temp_it.add_to_end(
|
|
|
|
new BLOB_CHOICE(0, blob_choice->rating() + speckle_large_penalty,
|
2012-02-02 10:57:42 +08:00
|
|
|
blob_choice->certainty(), -1, -1, NULL, 0, 0, false));
|
2007-03-08 04:03:40 +08:00
|
|
|
} /* AddLargeSpeckleTo */
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-07-27 21:23:23 +08:00
|
|
|
/**
|
|
|
|
* This routine returns TRUE if both the width of height
|
|
|
|
* of Blob are less than the MaxLargeSpeckleSize.
|
|
|
|
*
|
|
|
|
* Globals:
|
|
|
|
* - #speckle_large_max_size largest allowed speckle
|
|
|
|
*
|
|
|
|
* Exceptions: none
|
|
|
|
* History: Mon Mar 11 10:06:49 1991, DSJ, Created.
|
|
|
|
*
|
2012-03-30 23:42:06 +08:00
|
|
|
* @param blob blob to test against speckle criteria
|
2010-07-27 21:23:23 +08:00
|
|
|
*
|
2012-03-30 23:42:06 +08:00
|
|
|
* @return TRUE if blob is speckle, FALSE otherwise.
|
2007-03-08 04:03:40 +08:00
|
|
|
*/
|
2012-02-02 10:57:42 +08:00
|
|
|
BOOL8 LargeSpeckle(TBLOB *blob) {
|
|
|
|
double speckle_size = BASELINE_SCALE * speckle_large_max_size;
|
|
|
|
TBOX bbox = blob->bounding_box();
|
|
|
|
return (bbox.width() < speckle_size && bbox.height() < speckle_size);
|
2007-03-08 04:03:40 +08:00
|
|
|
} /* LargeSpeckle */
|