classify/mfoutline.h File Reference

#include "general.h"
#include "oldlist.h"
#include "fpoint.h"
#include "fxdefs.h"
#include "baseline.h"

Go to the source code of this file.

Classes

Defines

Typedefs

Enumerations

Functions

Variables


Define Documentation

#define AverageOf ( A,
 )     (((A) + (B)) / 2)

macro for average of 2 things

Definition at line 110 of file mfoutline.h.

Referenced by AddOutlineFeatureToSet(), and ExtractMicroFeature().

#define BaselineAt ( L,
 )     (BASELINE_OFFSET)

macro for computing the baseline of a row of text at an x position

Definition at line 113 of file mfoutline.h.

Referenced by ExtractCharNormFeatures(), GetIntCharNormFeatures(), and NormalizeOutline().

#define ClearMark (  )     ((P)->ExtremityMark = FALSE)

Definition at line 133 of file mfoutline.h.

Referenced by ConvertOutline().

#define ComputeScaleFactor (  ) 

Value:

(NORMAL_X_HEIGHT / ((is_baseline_normalized ())?         \
            (BASELINE_SCALE):             \
            ((L)->xheight)))
macro for computing the scale factor to use to normalize characters

Definition at line 116 of file mfoutline.h.

Referenced by ExtractCharNormFeatures(), GetIntBaselineFeatures(), GetIntCharNormFeatures(), NormalizeOutline(), and NormalizeOutlines().

#define DegenerateOutline (  )     (((O) == NIL) || ((O) == rest(O)))

macros for manipulating micro-feature outlines

Definition at line 122 of file mfoutline.h.

Referenced by ConvertToMicroFeatures(), ConvertToOutlineFeatures(), ConvertToPicoFeatures2(), FilterEdgeNoise(), FindDirectionChanges(), and MarkDirectionChanges().

#define DirectionOf (  )     ((P)->Direction)

Definition at line 131 of file mfoutline.h.

Referenced by ChangeDirection(), FilterEdgeNoise(), and NextDirectionChange().

#define IsExtremity (  )     ((P)->ExtremityMark)

Definition at line 135 of file mfoutline.h.

Referenced by SmearExtremities().

#define IsHidden (  )     ((E)->Hidden)

Definition at line 138 of file mfoutline.h.

Referenced by ConvertOutline().

#define IsVisible (  )     (! IsHidden(E))

Definition at line 137 of file mfoutline.h.

Referenced by ConvertToOutlineFeatures(), and ConvertToPicoFeatures2().

#define MakeOutlineCircular (  )     (set_rest (last (O), (O)))

Definition at line 125 of file mfoutline.h.

Referenced by ConvertOutline().

#define MarkPoint (  )     ((P)->ExtremityMark = TRUE)

Definition at line 134 of file mfoutline.h.

Referenced by MarkDirectionChanges().

#define NextPointAfter (  )     (rest (E))

Definition at line 124 of file mfoutline.h.

Referenced by ChangeDirection(), CharNormalizeOutline(), ComputeBulges(), ComputeOutlineStats(), ConvertToOutlineFeatures(), ConvertToPicoFeatures2(), FindDirectionChanges(), NextDirectionChange(), NextExtremity(), NormalizeOutline(), and SmearExtremities().

#define NORMAL_BASELINE   (0.0)

Definition at line 32 of file mfoutline.h.

Referenced by NormalizeOutline().

#define NORMAL_X_HEIGHT   (0.5)

Note:
File: mfoutline.h
Interface spec for fx outline structures
Author:
Dan Johnson
Date:
Thu May 17 08:55:32 1990, 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.

Definition at line 31 of file mfoutline.h.

Referenced by NormalizeOutline().

#define NotExtremity (  )     (!IsExtremity(P))

Definition at line 136 of file mfoutline.h.

Referenced by NextExtremity().

#define PointAt (  )     ((MFEDGEPT *) first (O))

Definition at line 123 of file mfoutline.h.

Referenced by ChangeDirection(), CharNormalizeOutline(), ComputeBulges(), ComputeOutlineStats(), ConvertToOutlineFeatures(), ConvertToPicoFeatures2(), ExtractMicroFeature(), FilterEdgeNoise(), FindDirectionChanges(), MarkDirectionChanges(), NextDirectionChange(), NextExtremity(), NormalizeOutline(), and SmearExtremities().

#define PositionOf (  )     ((P)->Point)

macros for manipulating micro-feature outline edge points

Definition at line 128 of file mfoutline.h.

Referenced by ComputeBulges(), ComputeOrientation(), ConvertOutline(), ConvertToOutlineFeatures(), ConvertToPicoFeatures2(), ExtractMicroFeature(), and FilterEdgeNoise().

#define PreviousDirectionOf (  )     ((P)->PreviousDirection)

Definition at line 132 of file mfoutline.h.

Referenced by ChangeDirection(), and FilterEdgeNoise().

#define XPositionOf (  )     (PositionOf(P).x)

Definition at line 129 of file mfoutline.h.

Referenced by CharNormalizeOutline(), ComputeBulges(), ComputeOutlineStats(), ConvertOutline(), ExtractMicroFeature(), NormalizeOutline(), and SmearExtremities().

#define YPositionOf (  )     (PositionOf(P).y)

Definition at line 130 of file mfoutline.h.

Referenced by CharNormalizeOutline(), ComputeBulges(), ComputeOutlineStats(), ConvertOutline(), ExtractMicroFeature(), NormalizeOutline(), and SmearExtremities().


Typedef Documentation

MFOUTLINE

FIX: list of fx outline structures ?

Definition at line 38 of file mfoutline.h.


Enumeration Type Documentation

enum DIRECTION

Basic 8 compass directions.

Enumerator:
north 
south 
east 
west 
northeast 
northwest 
southeast 
southwest 

Definition at line 44 of file mfoutline.h.

enum NORM_METHOD

FIX:.

Enumerator:
baseline 
character 
baseline 
character 

Definition at line 97 of file mfoutline.h.

00097              {
00098   baseline, character
00099 } NORM_METHOD;

enum OUTLINETYPE

Outline type: outer or hole.

Enumerator:
outer 
hole 

Definition at line 75 of file mfoutline.h.

00075              {
00076   outer, hole
00077 } OUTLINETYPE;


Function Documentation

void ChangeDirection ( MFOUTLINE  Start,
MFOUTLINE  End,
DIRECTION  Direction 
)

Change the direction of every vector in the specified outline segment to Direction.

Parameters:
Start Start of segment of outline to be modified
End End of segment of outline to be modified
Direction new direction to assign to segment
Returns:
none
The segment to be changed starts at Start and ends at End. Note that the previous direction of End must also be changed to reflect the change in direction of the point before it.
Note:
Exceptions: none
Date:
Fri May 4 10:42:04 1990, DSJ, Created.

Definition at line 844 of file mfoutline.cpp.

References DirectionOf, NextPointAfter, PointAt, and PreviousDirectionOf.

Referenced by FilterEdgeNoise().

00844                                                                           { 
00845   MFOUTLINE Current;
00846 
00847   for (Current = Start; Current != End; Current = NextPointAfter (Current))
00848     DirectionOf (PointAt (Current)) = Direction;
00849 
00850   PreviousDirectionOf (PointAt (End)) = Direction;
00851 
00852 }                                /* ChangeDirection */

void CharNormalizeOutline ( MFOUTLINE  Outline,
FLOAT32  XCenter,
FLOAT32  YCenter,
FLOAT32  XScale,
FLOAT32  YScale 
)

Normalizes each point in Outline by translating it to the specified center and scaling it anisotropically according to the given scale factors.

Parameters:
Outline Outline to be character normalized
XCenter X of center point for normalization
YCenter Y of center point for normalization
XScale X of scale factors for normalization
YScale Y of scale factors for normalization
Returns:
none
Note:
Exceptions: none
Date:
Fri Dec 14 10:27:11 1990, DSJ, Created.

Definition at line 870 of file mfoutline.cpp.

References NextPointAfter, NIL, PointAt, XPositionOf, and YPositionOf.

Referenced by BlobMicroFeatures(), and NormalizeOutlines().

00874                                           {
00875   MFOUTLINE First, Current;
00876   MFEDGEPT *CurrentPoint;
00877 
00878   if (Outline == NIL)
00879     return;
00880 
00881   First = Outline;
00882   Current = First;
00883   do {
00884     CurrentPoint = PointAt (Current);
00885     XPositionOf (CurrentPoint) =
00886       (XPositionOf (CurrentPoint) - XCenter) * XScale;
00887     YPositionOf (CurrentPoint) =
00888       (YPositionOf (CurrentPoint) - YCenter) * YScale;
00889 
00890     Current = NextPointAfter (Current);
00891   }
00892   while (Current != First);
00893 
00894 }                                /* CharNormalizeOutline */

void ComputeBlobCenter ( TBLOB Blob,
TPOINT BlobCenter 
)

Computes the center point of the specified blob using the bounding box of all top level outlines in the blob.

Parameters:
Blob Blob to compute centerpoint of
BlobCenter Data struct to place results in
Returns:
none
The center point is computed in a coordinate system which is scaled up by VECSCALE from the page coordinate system.
Note:
Exceptions: none
Date:
Fri Sep 8 10:45:39 1989, DSJ, Created.

Definition at line 154 of file mfoutline.cpp.

References blob_bounding_box(), VECSCALE, TPOINT::x, and TPOINT::y.

Referenced by SettupBlobConversion().

00154                                                         { 
00155   TPOINT TopLeft;
00156   TPOINT BottomRight;
00157 
00158   blob_bounding_box(Blob, &TopLeft, &BottomRight); 
00159 
00160   BlobCenter->x = ((TopLeft.x << VECSCALE) + (BottomRight.x << VECSCALE)) / 2;
00161   BlobCenter->y = ((TopLeft.y << VECSCALE) + (BottomRight.y << VECSCALE)) / 2;
00162 
00163 }                                /* ComputeBlobCenter */

void ComputeDirection ( MFEDGEPT Start,
MFEDGEPT Finish,
FLOAT32  MinSlope,
FLOAT32  MaxSlope 
)

Computes the slope from Start to Finish and and then computes the approximate direction of the line segment from Start to Finish.

Parameters:
Start Starting point to compute direction from
Finish Finishing point to compute direction to
MinSlope Slope below which lines are horizontal
MaxSlope Slope above which lines are vertical
Returns:
none
The direction is quantized into 8 buckets:

N, S, E, W, NE, NW, SE, SW

Both the slope and the direction are then stored into the appropriate fields of the Start edge point. The direction is also stored into the PreviousDirection field of the Finish edge point.

Note:
Exceptions: none
Date:
7/25/89, DSJ, Created.

Definition at line 920 of file mfoutline.cpp.

References MFEDGEPT::Direction, east, MAX_FLOAT32, north, northeast, northwest, MFEDGEPT::Point, MFEDGEPT::PreviousDirection, MFEDGEPT::Slope, south, southeast, southwest, west, FPOINT::x, and FPOINT::y.

Referenced by FindDirectionChanges().

00923                                         {
00924   FVECTOR Delta;
00925 
00926   Delta.x = Finish->Point.x - Start->Point.x;
00927   Delta.y = Finish->Point.y - Start->Point.y;
00928   if (Delta.x == 0)
00929   if (Delta.y < 0) {
00930     Start->Slope = -MAX_FLOAT32;
00931     Start->Direction = south;
00932   }
00933   else {
00934     Start->Slope = MAX_FLOAT32;
00935     Start->Direction = north;
00936   }
00937   else {
00938     Start->Slope = Delta.y / Delta.x;
00939     if (Delta.x > 0)
00940       if (Delta.y > 0)
00941         if (Start->Slope > MinSlope)
00942           if (Start->Slope < MaxSlope)
00943             Start->Direction = northeast;
00944     else
00945       Start->Direction = north;
00946     else
00947       Start->Direction = east;
00948     else if (Start->Slope < -MinSlope)
00949     if (Start->Slope > -MaxSlope)
00950       Start->Direction = southeast;
00951     else
00952       Start->Direction = south;
00953     else
00954       Start->Direction = east;
00955     else if (Delta.y > 0)
00956     if (Start->Slope < -MinSlope)
00957       if (Start->Slope > -MaxSlope)
00958         Start->Direction = northwest;
00959     else
00960       Start->Direction = north;
00961     else
00962       Start->Direction = west;
00963     else if (Start->Slope > MinSlope)
00964     if (Start->Slope < MaxSlope)
00965       Start->Direction = southwest;
00966     else
00967       Start->Direction = south;
00968     else
00969       Start->Direction = west;
00970   }
00971   Finish->PreviousDirection = Start->Direction;
00972 }                                /* ComputeDirection */

void ComputeOutlineStats ( LIST  Outlines,
OUTLINE_STATS OutlineStats 
)

Computes several statistics about the outlines in Outlines.

Parameters:
Outlines List of outlines to compute stats for
OutlineStats Place to put results
Returns:
none (results are returned in OutlineStats)
These statistics are usually used to perform anistropic normalization of all of the outlines. The statistics generated are:
See page 14 of Patent 5,237,627 for the WHY.
Note:
Exceptions: none
Date:
Fri Dec 14 08:32:03 1990, DSJ, Created.

Definition at line 357 of file mfoutline.cpp.

References FinishOutlineStats(), first, InitOutlineStats(), iterate, NextPointAfter, Outline, PointAt, UpdateOutlineStats(), XPositionOf, and YPositionOf.

Referenced by NormalizeOutlines().

00357                                                                      { 
00358   MFOUTLINE Outline;
00359   MFOUTLINE EdgePoint;
00360   MFEDGEPT *Current;
00361   MFEDGEPT *Last;
00362 
00363   InitOutlineStats(OutlineStats); 
00364   iterate(Outlines) { 
00365     Outline = (MFOUTLINE) first (Outlines);
00366 
00367     Last = PointAt (Outline);
00368     Outline = NextPointAfter (Outline);
00369     EdgePoint = Outline;
00370     do {
00371       Current = PointAt (EdgePoint);
00372 
00373       UpdateOutlineStats (OutlineStats,
00374         XPositionOf (Last), YPositionOf (Last),
00375         XPositionOf (Current), YPositionOf (Current));
00376 
00377       Last = Current;
00378       EdgePoint = NextPointAfter (EdgePoint);
00379     }
00380     while (EdgePoint != Outline);
00381   }
00382   FinishOutlineStats(OutlineStats); 
00383 
00384 }                                /* ComputeOutlineStats */

LIST ConvertBlob ( TBLOB Blob  ) 

Convert Blob into a list of outlines.

Parameters:
Blob blob to be converted
Returns:
List of outlines representing blob.
Note:
Exceptions: none
Date:
Thu Dec 13 15:40:17 1990, DSJ, Created.

Definition at line 175 of file mfoutline.cpp.

References ConvertOutlines(), NIL, NULL, outer, and SettupBlobConversion().

Referenced by BlobMicroFeatures(), ExtractCharNormFeatures(), ExtractOutlineFeatures(), and ExtractPicoFeatures().

00175                               { 
00176   LIST ConvertedOutlines = NIL;
00177 
00178   if (Blob != NULL) {
00179     SettupBlobConversion(Blob);  //ComputeBlobCenter (Blob, &BlobCenter);
00180     ConvertedOutlines = ConvertOutlines (Blob->outlines,
00181       ConvertedOutlines, outer);
00182   }
00183 
00184   return (ConvertedOutlines);
00185 }                                /* ConvertBlob */

MFOUTLINE ConvertOutline ( TESSLINE Outline  ) 

Converts the specified outline into a special data structure which is used for extracting micro-features.

Parameters:
Outline outline to be converted
Note:
Globals: BlobCenter pre-computed center of current blob
Returns:
Outline converted into special micro-features format.
If the outline has been pre-normalized by the splitter, then it is assumed to be in expanded form and all we must do is copy the points. Otherwise, if the outline is expanded, then the expanded form is used and the coordinates of the points are returned to page coordinates using the global variable BlobCenter and the scaling factor REALSCALE.

If the outline is not expanded, then the compressed form is used.

Note:
Exceptions: none
Date:
8/2/89, DSJ, Created. 9/8/89, DSJ, Added ability to convert expanded blobs. 1/11/90, DSJ, Changed to use REALSCALE instead of VECSCALE to eliminate round-off problems. 2/21/91, DSJ, Added ability to work with pre-normalized blobs. 4/30/91, DSJ, Added concept of "hidden" segments.

Definition at line 213 of file mfoutline.cpp.

References BlobCenter, ClearMark, CopyPoint, BYTEVEC::dx, BYTEVEC::dy, FALSE, is_baseline_normalized, is_hidden_edge, IsHidden, MakeOutlineCircular, NewEdgePoint(), edgeptstruct::next, NIL, NULL, Outline, edgeptstruct::pos, PositionOf, push(), REALSCALE, TRUE, TPOINT::x, Xof, XPositionOf, TPOINT::y, Yof, and YPositionOf.

Referenced by ConvertOutlines().

00213                                             { 
00214   register BYTEVEC *Vector;
00215   TPOINT Position;
00216   TPOINT StartPosition;
00217   MFEDGEPT *NewPoint;
00218   MFOUTLINE MFOutline = NIL;
00219   EDGEPT *EdgePoint;
00220   EDGEPT *StartPoint;
00221   EDGEPT *NextPoint;
00222 
00223   if (Outline == NULL ||
00224     (Outline->compactloop == NULL && Outline->loop == NULL))
00225     return (MFOutline);
00226 
00227   if (is_baseline_normalized ()) { // have outlines been prenormalized
00228     StartPoint = Outline->loop;
00229     EdgePoint = StartPoint;
00230     do {
00231       NextPoint = EdgePoint->next;
00232 
00233       // filter out duplicate points
00234       if (EdgePoint->pos.x != NextPoint->pos.x ||
00235       EdgePoint->pos.y != NextPoint->pos.y) {
00236         NewPoint = NewEdgePoint ();
00237         ClearMark(NewPoint); 
00238         IsHidden (NewPoint) = is_hidden_edge (EdgePoint) ? TRUE : FALSE;
00239         XPositionOf (NewPoint) = EdgePoint->pos.x;
00240         YPositionOf (NewPoint) = EdgePoint->pos.y;
00241         MFOutline = push (MFOutline, NewPoint);
00242       }
00243       EdgePoint = NextPoint;
00244     }
00245     while (EdgePoint != StartPoint);
00246   }
00247                                  /* use compressed version of outline */
00248   else if (Outline->loop == NULL) {
00249     Xof (Position) = Xof (StartPosition) = Outline->start.x;
00250     Yof (Position) = Yof (StartPosition) = Outline->start.y;
00251     Vector = Outline->compactloop;
00252     do {
00253       if (Vector->dx != 0 || Vector->dy != 0) {
00254         NewPoint = NewEdgePoint ();
00255         ClearMark(NewPoint); 
00256                                  /* all edges are visible */
00257         IsHidden (NewPoint) = FALSE;
00258         CopyPoint (Position, PositionOf (NewPoint));
00259         MFOutline = push (MFOutline, NewPoint);
00260       }
00261       Xof (Position) += Vector->dx;
00262       Yof (Position) += Vector->dy;
00263       Vector++;
00264     }
00265     while ((Xof (Position) != Xof (StartPosition)) ||
00266       (Yof (Position) != Yof (StartPosition)));
00267   }
00268   else {                         /* use expanded version of outline */
00269     StartPoint = Outline->loop;
00270     EdgePoint = StartPoint;
00271     do {
00272       NextPoint = EdgePoint->next;
00273 
00274       /* filter out duplicate points */
00275       if (EdgePoint->pos.x != NextPoint->pos.x ||
00276       EdgePoint->pos.y != NextPoint->pos.y) {
00277         NewPoint = NewEdgePoint ();
00278         ClearMark(NewPoint); 
00279         IsHidden (NewPoint) = is_hidden_edge (EdgePoint) ? TRUE : FALSE;
00280         XPositionOf (NewPoint) =
00281           (EdgePoint->pos.x + BlobCenter.x) / REALSCALE;
00282         YPositionOf (NewPoint) =
00283           (EdgePoint->pos.y + BlobCenter.y) / REALSCALE;
00284         MFOutline = push (MFOutline, NewPoint);
00285       }
00286       EdgePoint = NextPoint;
00287     }
00288     while (EdgePoint != StartPoint);
00289   }
00290 
00291   MakeOutlineCircular(MFOutline); 
00292   return (MFOutline);
00293 
00294 }                                /* ConvertOutline */

LIST ConvertOutlines ( TESSLINE Outline,
LIST  ConvertedOutlines,
OUTLINETYPE  OutlineType 
)

Converts all given outlines into a new format of outlines.

Parameters:
Outline First outline to be converted
ConvertedOutlines List to add converted outlines to
OutlineType Are the outlines outer or holes?
Returns:
Updated list of converted outlines.
Outline points to a list of the top level outlines to be converted. The children of these outlines are also recursively converted. All converted outlines are added to ConvertedOutlines. This is a list of outlines, one for each outline that was converted.
Note:
Exceptions: none
Date:
Thu Dec 13 15:57:38 1990, DSJ, Created.

Definition at line 314 of file mfoutline.cpp.

References ConvertOutline(), ConvertOutlines(), hole, NULL, outer, Outline, and push().

Referenced by ConvertBlob(), and ConvertOutlines().

00316                                               {
00317   MFOUTLINE MFOutline;
00318 
00319   while (Outline != NULL) {
00320     if (Outline->child != NULL)
00321       if (OutlineType == outer)
00322         ConvertedOutlines = ConvertOutlines (Outline->child,
00323           ConvertedOutlines, hole);
00324     else
00325       ConvertedOutlines = ConvertOutlines (Outline->child,
00326         ConvertedOutlines, outer);
00327 
00328     MFOutline = ConvertOutline (Outline);
00329     ConvertedOutlines = push (ConvertedOutlines, MFOutline);
00330     Outline = Outline->next;
00331   }
00332   return (ConvertedOutlines);
00333 }                                /* ConvertOutlines */

void FilterEdgeNoise ( MFOUTLINE  Outline,
FLOAT32  NoiseSegmentLength 
)

Filter out noise from the specified outline.

Parameters:
Outline Outline to be filtered
NoiseSegmentLength Maximum length of a "noise" segment
Returns:
none
This is done by changing the direction of short segments of the outline to the same direction as the preceding outline segment.
Note:
Exceptions: none
Date:
Fri May 4 10:23:45 1990, DSJ, Created.

Definition at line 400 of file mfoutline.cpp.

References ChangeDirection(), DegenerateOutline, DirectionOf, DistanceBetween, NextDirectionChange(), north, PointAt, PositionOf, and PreviousDirectionOf.

Referenced by BlobMicroFeatures().

00400                                                                     { 
00401   MFOUTLINE Current;
00402   MFOUTLINE Last;
00403   MFOUTLINE First;
00404   FLOAT32 Length;
00405   int NumFound = 0;
00406   DIRECTION DirectionOfFirst = north;
00407 
00408   if (DegenerateOutline (Outline))
00409     return;
00410 
00411   /* Find 2 segments of different orientation which are long enough to
00412      not be filtered.  If two cannot be found, leave the outline unchanged. */
00413   First = NextDirectionChange (Outline);
00414   Last = First;
00415   do {
00416     Current = NextDirectionChange (Last);
00417     Length = DistanceBetween (PositionOf (PointAt (Current)),
00418       PositionOf (PointAt (Last)));
00419     if (Length >= NoiseSegmentLength) {
00420       if (NumFound == 0) {
00421         NumFound = 1;
00422         DirectionOfFirst = DirectionOf (PointAt (Last));
00423       }
00424       else if (DirectionOfFirst != DirectionOf (PointAt (Last)))
00425         break;
00426     }
00427     Last = Current;
00428   }
00429   while (Last != First);
00430   if (Current == Last)
00431     return;
00432 
00433   /* Find each segment and filter it out if it is too short.  Note that
00434      the above code guarantees that the initial direction change will
00435      not be removed, therefore the loop will terminate. */
00436   First = Last;
00437   do {
00438     Current = NextDirectionChange (Last);
00439     Length = DistanceBetween (PositionOf (PointAt (Current)),
00440       PositionOf (PointAt (Last)));
00441     if (Length < NoiseSegmentLength)
00442       ChangeDirection (Last, Current, PreviousDirectionOf (PointAt (Last)));
00443 
00444     Last = Current;
00445   }
00446   while (Last != First);
00447 
00448 }                                /* FilterEdgeNoise */

void FindDirectionChanges ( MFOUTLINE  Outline,
FLOAT32  MinSlope,
FLOAT32  MaxSlope 
)

Searches thru the specified outline, computes a slope for each vector in the outline, and marks each vector as having one of the following directions:.

Parameters:
Outline Micro-feature outline to analyze
MinSlope Controls "snapping" of segments to horizontal
MaxSlope Controls "snapping" of segments to vertical
Returns:
none
          NW  N  NE
            \   /
          W       E
            /   \
          SW  S  SE

This information is then stored in the outline and the outline is returned.

Note:
Exceptions: none
Date:
7/21/89, DSJ, Created.

Definition at line 474 of file mfoutline.cpp.

References ComputeDirection(), DegenerateOutline, NextPointAfter, and PointAt.

Referenced by BlobMicroFeatures().

00476                                             {
00477   MFEDGEPT *Current;
00478   MFEDGEPT *Last;
00479   MFOUTLINE EdgePoint;
00480 
00481   if (DegenerateOutline (Outline))
00482     return;
00483 
00484   Last = PointAt (Outline);
00485   Outline = NextPointAfter (Outline);
00486   EdgePoint = Outline;
00487   do {
00488     Current = PointAt (EdgePoint);
00489     ComputeDirection(Last, Current, MinSlope, MaxSlope); 
00490 
00491     Last = Current;
00492     EdgePoint = NextPointAfter (EdgePoint);
00493   }
00494   while (EdgePoint != Outline);
00495 
00496 }                                /* FindDirectionChanges */

void FinishOutlineStats ( register OUTLINE_STATS OutlineStats  ) 

Use the preliminary statistics accumulated in OutlineStats to compute the final statistics.

Parameters:
OutlineStats Statistics about a set of outlines
Returns:
none
Note:
See Dan Johnson's Tesseract lab notebook #2, pgs. 74-78

Exceptions: none

Date:
Fri Dec 14 10:13:36 1990, DSJ, Created.

Definition at line 987 of file mfoutline.cpp.

References MIN_INERTIA.

Referenced by ComputeOutlineStats().

00987                                                               { 
00988   OutlineStats->x = 0.5 * OutlineStats->My / OutlineStats->L;
00989   OutlineStats->y = 0.5 * OutlineStats->Mx / OutlineStats->L;
00990 
00991   OutlineStats->Ix = (OutlineStats->Ix / 3.0 -
00992     OutlineStats->y * OutlineStats->Mx +
00993     OutlineStats->y * OutlineStats->y * OutlineStats->L);
00994 
00995   OutlineStats->Iy = (OutlineStats->Iy / 3.0 -
00996     OutlineStats->x * OutlineStats->My +
00997     OutlineStats->x * OutlineStats->x * OutlineStats->L);
00998 
00999   /* Ix and/or Iy could possibly be negative due to roundoff error */
01000   if (OutlineStats->Ix < 0.0)
01001     OutlineStats->Ix = MIN_INERTIA;
01002   if (OutlineStats->Iy < 0.0)
01003     OutlineStats->Iy = MIN_INERTIA;
01004 
01005   OutlineStats->Rx = sqrt (OutlineStats->Ix / OutlineStats->L);
01006   OutlineStats->Ry = sqrt (OutlineStats->Iy / OutlineStats->L);
01007 
01008   OutlineStats->Mx *= 0.5;
01009   OutlineStats->My *= 0.5;
01010 
01011 }                                /* FinishOutlineStats */

void FreeMFOutline ( void *  arg  ) 

Deallocates all of the memory consumed by a micro-feature outline.

Parameters:
arg Micro-feature outline to be freed
Returns:
none
Note:
Exceptions: none
Date:
7/27/89, DSJ, Created.

Definition at line 508 of file mfoutline.cpp.

References c_free_struct(), first, NIL, NULL, Outline, pop(), rest, and set_rest.

Referenced by FreeOutlines().

00508                               {  //MFOUTLINE  Outline)
00509   MFOUTLINE Start;
00510   MFOUTLINE Outline = (MFOUTLINE) arg;
00511 
00512   /* Break the circular outline so we can use std. techniques to deallocate */
00513   Start = rest (Outline);
00514   set_rest(Outline, NIL); 
00515   while (Start != NULL) {
00516     c_free_struct (first (Start), sizeof (MFEDGEPT), "MFEDGEPT");
00517     Start = pop (Start);
00518   }
00519 
00520 }                                /* FreeMFOutline */

void FreeOutlines ( LIST  Outlines  ) 

Release all memory consumed by the specified list of outlines.

Parameters:
Outlines List of mf-outlines to be freed
Returns:
none
Note:
Exceptions: none
Date:
Thu Dec 13 16:14:50 1990, DSJ, Created.

Definition at line 532 of file mfoutline.cpp.

References destroy_nodes(), and FreeMFOutline().

Referenced by BlobMicroFeatures(), ExtractCharNormFeatures(), ExtractOutlineFeatures(), and ExtractPicoFeatures().

00532                                  { 
00533   destroy_nodes(Outlines, FreeMFOutline); 
00534 }                                /* FreeOutlines */

void InitMFOutlineVars (  ) 

Initializes the global control knobs for all routines in this file.

Parameters:
none 
Returns:
none
Note:
Exceptions: none
Date:
Fri Dec 14 10:50:12 1990, DSJ, Created.

Definition at line 546 of file mfoutline.cpp.

Referenced by init_dj_debug().

00546                          { 
00547   MakeNormMethod(); 
00548   MakeCharNormRange(); 
00549   MakeMinNormScaleX(); 
00550   MakeMaxNormScaleX(); 
00551   MakeMinNormScaleY(); 
00552   MakeMaxNormScaleY(); 
00553 }                                /* InitMFOutlineVars */

void InitOutlineStats ( OUTLINE_STATS OutlineStats  ) 

Initialize the outline statistics data structure so that it is ready to start accumulating statistics.

Parameters:
OutlineStats Stats data structure to be initialized
Returns:
none
Note:
Exceptions: none
Date:
Fri Dec 14 08:55:22 1990, DSJ, Created.

Definition at line 1024 of file mfoutline.cpp.

References OUTLINE_STATS::Ix, OUTLINE_STATS::Iy, OUTLINE_STATS::L, OUTLINE_STATS::Mx, OUTLINE_STATS::My, OUTLINE_STATS::Rx, OUTLINE_STATS::Ry, OUTLINE_STATS::x, and OUTLINE_STATS::y.

Referenced by ComputeOutlineStats().

01024                                                    { 
01025   OutlineStats->Mx = 0.0;
01026   OutlineStats->My = 0.0;
01027   OutlineStats->L = 0.0;
01028   OutlineStats->x = 0.0;
01029   OutlineStats->y = 0.0;
01030   OutlineStats->Ix = 0.0;
01031   OutlineStats->Iy = 0.0;
01032   OutlineStats->Rx = 0.0;
01033   OutlineStats->Ry = 0.0;
01034 }                                /* InitOutlineStats */

void MarkDirectionChanges ( MFOUTLINE  Outline  ) 

Searches thru the specified outline and finds the points at which the outline changes direction.

Parameters:
Outline Micro-feature outline to analyze
Returns:
none
These points are then marked as "extremities". This routine is used as an alternative to FindExtremities(). It forces the endpoints of the microfeatures to be at the direction changes rather than at the midpoint between direction changes.
Note:
Exceptions: none
Date:
6/29/90, DSJ, Created.

Definition at line 572 of file mfoutline.cpp.

References DegenerateOutline, MarkPoint, NextDirectionChange(), and PointAt.

Referenced by BlobMicroFeatures().

00572                                              { 
00573   MFOUTLINE Current;
00574   MFOUTLINE Last;
00575   MFOUTLINE First;
00576 
00577   if (DegenerateOutline (Outline))
00578     return;
00579 
00580   First = NextDirectionChange (Outline);
00581   Last = First;
00582   do {
00583     Current = NextDirectionChange (Last);
00584     MarkPoint (PointAt (Current));
00585     Last = Current;
00586   }
00587   while (Last != First);
00588 
00589 }                                /* MarkDirectionChanges */

MFEDGEPT* NewEdgePoint (  ) 

Allocates and returns a new edge point for a micro-feature outline.

Parameters:
none 
Returns:
New edge point.
Note:
Exceptions: none
Date:
7/21/89, DSJ, Created.

Definition at line 601 of file mfoutline.cpp.

References c_alloc_struct().

Referenced by ConvertOutline().

00601                          { 
00602   return ((MFEDGEPT *) c_alloc_struct (sizeof (MFEDGEPT), "MFEDGEPT"));
00603 
00604 }                                /* NewEdgePoint */

MFOUTLINE NextDirectionChange ( MFOUTLINE  EdgePoint  ) 

Returns the next point in the micro-feature outline that has a direction different than EdgePoint.

Parameters:
EdgePoint start search from this point
Returns:
Point of next direction change in micro-feature outline.
The routine assumes that the outline being searched is not a degenerate outline (i.e. it must have 2 or more edge points).
Note:
Exceptions: none
Date:
7/25/89, DSJ, Created.

Definition at line 1050 of file mfoutline.cpp.

References DirectionOf, NextPointAfter, and PointAt.

Referenced by FilterEdgeNoise(), and MarkDirectionChanges().

01050                                                    { 
01051   DIRECTION InitialDirection;
01052 
01053   InitialDirection = DirectionOf (PointAt (EdgePoint));
01054 
01055   do
01056   EdgePoint = NextPointAfter (EdgePoint);
01057   while (DirectionOf (PointAt (EdgePoint)) == InitialDirection);
01058 
01059   return (EdgePoint);
01060 }                                /* NextDirectionChange */

MFOUTLINE NextExtremity ( MFOUTLINE  EdgePoint  ) 

Returns the next point in the micro-feature outline that is an extremity.

Parameters:
EdgePoint Start search from this point
Returns:
Next extremity in the outline after EdgePoint.
The search starts after EdgePoint. The routine assumes that the outline being searched is not a degenerate outline (i.e. it must have 2 or more edge points).
Note:
Exceptions: none
Date:
7/26/89, DSJ, Created.

Definition at line 620 of file mfoutline.cpp.

References NextPointAfter, NotExtremity, and PointAt.

Referenced by ConvertToMicroFeatures().

00620                                              { 
00621   EdgePoint = NextPointAfter (EdgePoint);
00622   while (NotExtremity (PointAt (EdgePoint)))
00623     EdgePoint = NextPointAfter (EdgePoint);
00624 
00625   return (EdgePoint);
00626 
00627 }                                /* NextExtremity */

void NormalizeOutline ( MFOUTLINE  Outline,
LINE_STATS LineStats,
FLOAT32  XOrigin 
)

Normalizes coordinates of outline to be deskewed, translated, and scaled.

Parameters:
Outline outline to be normalized
LineStats statistics for text line normalization
XOrigin x-origin of text
Returns:
none
Normalizes the coordinates of the specified outline so that the outline is deskewed down to the baseline, translated so that x=0 is at XOrigin, and scaled so that the height of a character cell from descender to ascender is 1. Of this height, 0.25 is for the descender, 0.25 for the ascender, and 0.5 for the x-height. The y coordinate of the baseline is 0.
Note:
Exceptions: none
Date:
8/2/89, DSJ, Created. 10/23/89, DSJ, Added ascender/descender stretching. 11/89, DSJ, Removed ascender/descender stretching.

Definition at line 652 of file mfoutline.cpp.

References BaselineAt, ComputeScaleFactor, NextPointAfter, NIL, NORMAL_BASELINE, NORMAL_X_HEIGHT, PointAt, XPositionOf, and YPositionOf.

Referenced by NormalizeOutlines().

00654                                        {
00655   MFEDGEPT *Current;
00656   MFOUTLINE EdgePoint;
00657   FLOAT32 ScaleFactor;
00658   FLOAT32 AscStretch;
00659   FLOAT32 DescStretch;
00660 
00661   if (Outline != NIL) {
00662     ScaleFactor = ComputeScaleFactor (LineStats);
00663     AscStretch = 1.0;
00664     DescStretch = 1.0;
00665 
00666     EdgePoint = Outline;
00667     do {
00668       Current = PointAt (EdgePoint);
00669 
00670       YPositionOf (Current) = ScaleFactor *
00671         (YPositionOf (Current) -
00672         BaselineAt (LineStats, XPositionOf (Current)));
00673 
00674       if (YPositionOf (Current) > NORMAL_X_HEIGHT)
00675         YPositionOf (Current) = NORMAL_X_HEIGHT +
00676           (YPositionOf (Current) - NORMAL_X_HEIGHT) / AscStretch;
00677 
00678       else if (YPositionOf (Current) < NORMAL_BASELINE)
00679         YPositionOf (Current) = NORMAL_BASELINE +
00680             (YPositionOf (Current) - NORMAL_BASELINE) / DescStretch;
00681 
00682       XPositionOf (Current) = ScaleFactor *
00683         (XPositionOf (Current) - XOrigin);
00684 
00685       EdgePoint = NextPointAfter (EdgePoint);
00686     }
00687     while (EdgePoint != Outline);
00688   }
00689 }                                /* NormalizeOutline */

void NormalizeOutlines ( LIST  Outlines,
LINE_STATS LineStats,
FLOAT32 XScale,
FLOAT32 YScale 
)

Normalizes every outline in Outlines according to the currently selected normalization method.

Parameters:
Outlines List of outlines to be normalized
LineStats Statistics for text line normalization
XScale x-direction scale factor used by routine
YScale y-direction scale factor used by routine
Note:
Globals:
  • NormMethod Method being used for normalization
  • CharNormRange Map radius of gyration to this value
Returns:
none (Outlines are changed and XScale and YScale are updated)
Checks blobs & limits scale factor to avoid overscaling small blobs (.,`'), thin blobs (l1ift), and merged blobs.

It also returns the scale factors that it used to do this scaling. The scale factors returned represent the x and y sizes in the normalized coordinate system that correspond to 1 pixel in the original coordinate system.

Note:
Exceptions: none
Date:
Fri Dec 14 08:14:55 1990, DSJ, Created.

Definition at line 716 of file mfoutline.cpp.

References baseline, character, CharNormalizeOutline(), ComputeOutlineStats(), ComputeScaleFactor, first, iterate, NormalizeOutline(), NormMethod, Outline, OUTLINE_STATS::Rx, OUTLINE_STATS::Ry, OUTLINE_STATS::x, and OUTLINE_STATS::y.

Referenced by ExtractOutlineFeatures(), and ExtractPicoFeatures().

00719                                         {
00720   MFOUTLINE Outline;
00721   OUTLINE_STATS OutlineStats;
00722   FLOAT32 BaselineScale;
00723 
00724   switch (NormMethod) {
00725     case character:
00726       ComputeOutlineStats(Outlines, &OutlineStats); 
00727 
00728       *XScale = *YScale = BaselineScale = ComputeScaleFactor (LineStats);
00729       *XScale *= OutlineStats.Ry;
00730       *YScale *= OutlineStats.Rx;
00731       if (*XScale < MinNormScaleX)
00732         *XScale = MinNormScaleX;
00733       if (*YScale < MinNormScaleY)
00734         *YScale = MinNormScaleY;
00735       if (*XScale > MaxNormScaleX && *YScale <= MaxNormScaleY)
00736         *XScale = MaxNormScaleX;
00737       *XScale = CharNormRange * BaselineScale / *XScale;
00738       *YScale = CharNormRange * BaselineScale / *YScale;
00739 
00740       iterate(Outlines) { 
00741         Outline = (MFOUTLINE) first (Outlines);
00742         CharNormalizeOutline (Outline,
00743           OutlineStats.x, OutlineStats.y,
00744           *XScale, *YScale);
00745       }
00746       break;
00747 
00748     case baseline:
00749       iterate(Outlines) { 
00750         Outline = (MFOUTLINE) first (Outlines);
00751         NormalizeOutline (Outline, LineStats, 0.0);
00752       }
00753       *XScale = *YScale = ComputeScaleFactor (LineStats);
00754       break;
00755   }
00756 }                                /* NormalizeOutlines */

void SettupBlobConversion ( TBLOB Blob  ) 

Compute the center of the blob's bounding box and save it in a global variable.

Parameters:
Blob Blob that is to be converted
Note:
Globals: BlobCenter Center of blob to be converted
Returns:
none

Definition at line 773 of file mfoutline.cpp.

References BlobCenter, and ComputeBlobCenter().

Referenced by ConvertBlob().

00773                                        { 
00774   ComputeBlobCenter(Blob, &BlobCenter); 
00775 
00776 }                                /* SettupBlobConversion */

void SmearExtremities ( MFOUTLINE  Outline,
FLOAT32  XScale,
FLOAT32  YScale 
)

Smears the extremities of the specified outline.

Parameters:
Outline Outline whose extremities are to be smeared
XScale Factor used to normalize outline in x dir
YScale Factor used to normalize outline in y dir
Returns:
none
It does this by adding a random number between -0.5 and 0.5 pixels (that is why X/YScale are needed) to the x and y position of the point. This is done so that the discrete nature of the original scanned image does not affect the statistical clustering used during training.
Note:
Exceptions: none
Date:
1/11/90, DSJ, Created.

Definition at line 796 of file mfoutline.cpp.

References IsExtremity, NextPointAfter, NIL, PointAt, UniformRandomNumber(), XPositionOf, and YPositionOf.

Referenced by BlobMicroFeatures().

00796                                                                          { 
00797   MFEDGEPT *Current;
00798   MFOUTLINE EdgePoint;
00799   FLOAT32 MinXSmear;
00800   FLOAT32 MaxXSmear;
00801   FLOAT32 MinYSmear;
00802   FLOAT32 MaxYSmear;
00803 
00804   if (Outline != NIL) {
00805     MinXSmear = -0.5 * XScale;
00806     MaxXSmear = 0.5 * XScale;
00807     MinYSmear = -0.5 * YScale;
00808     MaxYSmear = 0.5 * YScale;
00809     EdgePoint = Outline;
00810     do {
00811       Current = PointAt (EdgePoint);
00812       if (IsExtremity (Current)) {
00813         XPositionOf (Current) +=
00814           UniformRandomNumber(MinXSmear, MaxXSmear); 
00815         YPositionOf (Current) +=
00816           UniformRandomNumber(MinYSmear, MaxYSmear); 
00817       }
00818 
00819       EdgePoint = NextPointAfter (EdgePoint);
00820     }
00821     while (EdgePoint != Outline);
00822   }
00823 }                                /* SmearExtremities */

void UpdateOutlineStats ( register OUTLINE_STATS OutlineStats,
register FLOAT32  x1,
register FLOAT32  x2,
register FLOAT32  y1,
register FLOAT32  y2 
)

Adds the statistics for the specified line segment to OutlineStats.

Parameters:
OutlineStats Statistics to add this segment to
x1 X of start of segment to be added to statistics
y1 Y of start of segment to be added to statistics
x2 X of end of segment to be added to statistics
y2 Y of end of segment to be added to statistics
Returns:
none
The statistics kept are:
These numbers, once collected, can later be used to easily compute the center of mass, first and second moments, and radii of gyration. (see Dan Johnson's Tesseract lab notebook #2, pgs. 74-78).
Note:
Exceptions: none
Date:
Fri Dec 14 08:59:17 1990, DSJ, Created.

Definition at line 1088 of file mfoutline.cpp.

Referenced by ComputeOutlineStats().

01092                                              {
01093   register FLOAT64 L;
01094   register FLOAT64 Mx2;
01095   register FLOAT64 My2;
01096 
01097   /* compute length of segment */
01098   L = sqrt ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
01099   OutlineStats->L += L;
01100 
01101   /* compute 2Mx and 2My components */
01102   Mx2 = L * (y1 + y2);
01103   My2 = L * (x1 + x2);
01104   OutlineStats->Mx += Mx2;
01105   OutlineStats->My += My2;
01106 
01107   /* compute second moment component */
01108   OutlineStats->Ix += Mx2 * (y1 + y2) - L * y1 * y2;
01109   OutlineStats->Iy += My2 * (x1 + x2) - L * x1 * x2;
01110 
01111 }                                /* UpdateOutlineStats */


Variable Documentation

int NormMethod

NormMethod

Normalization Method ..., defaults to character, of type int.

Referenced by ComputeIntFeatures(), ExtractOutlineFeatures(), ExtractPicoFeatures(), GetAdaptiveFeatures(), GetBaselineFeatures(), MakeNewAdaptedClass(), NormalizeOutlines(), ShowBestMatchFor(), ShowMatchDisplay(), and tess_training_tester().


Generated on Wed Feb 28 19:49:20 2007 for Tesseract by  doxygen 1.5.1