#include "general.h"
#include "oldlist.h"
#include "fpoint.h"
#include "fxdefs.h"
#include "baseline.h"
Go to the source code of this file.
#define AverageOf | ( | A, | |||
B | ) | (((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, | |||
X | ) | (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 | ) | ((P)->ExtremityMark = FALSE) |
#define ComputeScaleFactor | ( | L | ) |
Value:
(NORMAL_X_HEIGHT / ((is_baseline_normalized ())? \ (BASELINE_SCALE): \ ((L)->xheight)))
Definition at line 116 of file mfoutline.h.
Referenced by ExtractCharNormFeatures(), GetIntBaselineFeatures(), GetIntCharNormFeatures(), NormalizeOutline(), and NormalizeOutlines().
#define DegenerateOutline | ( | O | ) | (((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 | ) | ((P)->Direction) |
Definition at line 131 of file mfoutline.h.
Referenced by ChangeDirection(), FilterEdgeNoise(), and NextDirectionChange().
#define IsExtremity | ( | P | ) | ((P)->ExtremityMark) |
#define IsHidden | ( | E | ) | ((E)->Hidden) |
#define IsVisible | ( | E | ) | (! IsHidden(E)) |
Definition at line 137 of file mfoutline.h.
Referenced by ConvertToOutlineFeatures(), and ConvertToPicoFeatures2().
#define MakeOutlineCircular | ( | O | ) | (set_rest (last (O), (O))) |
#define MarkPoint | ( | P | ) | ((P)->ExtremityMark = TRUE) |
#define NextPointAfter | ( | E | ) | (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) |
#define NORMAL_X_HEIGHT (0.5) |
** (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 | ( | P | ) | (!IsExtremity(P)) |
#define PointAt | ( | O | ) | ((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 | ) | ((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 | ) | ((P)->PreviousDirection) |
#define XPositionOf | ( | P | ) | (PositionOf(P).x) |
Definition at line 129 of file mfoutline.h.
Referenced by CharNormalizeOutline(), ComputeBulges(), ComputeOutlineStats(), ConvertOutline(), ExtractMicroFeature(), NormalizeOutline(), and SmearExtremities().
#define YPositionOf | ( | P | ) | (PositionOf(P).y) |
Definition at line 130 of file mfoutline.h.
Referenced by CharNormalizeOutline(), ComputeBulges(), ComputeOutlineStats(), ConvertOutline(), ExtractMicroFeature(), NormalizeOutline(), and SmearExtremities().
enum DIRECTION |
enum NORM_METHOD |
FIX:.
Definition at line 97 of file mfoutline.h.
00097 { 00098 baseline, character 00099 } NORM_METHOD;
enum OUTLINETYPE |
Outline type: outer or hole.
Definition at line 75 of file mfoutline.h.
00075 { 00076 outer, hole 00077 } OUTLINETYPE;
Change the direction of every vector in the specified outline segment to Direction.
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 |
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.
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 |
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 */
Computes the center point of the specified blob using the bounding box of all top level outlines in the blob.
Blob | Blob to compute centerpoint of | |
BlobCenter | Data struct to place results in |
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 */
Computes the slope from Start to Finish and and then computes the approximate direction of the line segment from Start to Finish.
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 |
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.
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.
Outlines | List of outlines to compute stats for | |
OutlineStats | Place to put results |
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 */
Convert Blob into a list of outlines.
Blob | blob to be converted |
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 */
Converts the specified outline into a special data structure which is used for extracting micro-features.
Outline | outline to be converted |
If the outline is not expanded, then the compressed form is used.
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.
Outline | First outline to be converted | |
ConvertedOutlines | List to add converted outlines to | |
OutlineType | Are the outlines outer or holes? |
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 */
Filter out noise from the specified outline.
Outline | Outline to be filtered | |
NoiseSegmentLength | Maximum length of a "noise" segment |
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 */
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:.
Outline | Micro-feature outline to analyze | |
MinSlope | Controls "snapping" of segments to horizontal | |
MaxSlope | Controls "snapping" of segments to vertical |
NW N NE \ / W E / \ SW S SE
This information is then stored in the outline and the outline is returned.
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.
OutlineStats | Statistics about a set of outlines |
Exceptions: none
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.
arg | Micro-feature outline to be freed |
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.
Outlines | List of mf-outlines to be freed |
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.
none |
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.
OutlineStats | Stats data structure to be initialized |
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.
Outline | Micro-feature outline to analyze |
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.
none |
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 */
Returns the next point in the micro-feature outline that has a direction different than EdgePoint.
EdgePoint | start search from this point |
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 */
Returns the next point in the micro-feature outline that is an extremity.
EdgePoint | Start search from this point |
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.
Outline | outline to be normalized | |
LineStats | statistics for text line normalization | |
XOrigin | x-origin of text |
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.
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 |
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.
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.
Blob | Blob that is to be converted |
Definition at line 773 of file mfoutline.cpp.
References BlobCenter, and ComputeBlobCenter().
Referenced by ConvertBlob().
00773 { 00774 ComputeBlobCenter(Blob, &BlobCenter); 00775 00776 } /* SettupBlobConversion */
Smears the extremities of the specified outline.
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 |
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.
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 |
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 */
int NormMethod |
Normalization Method ..., defaults to character, of type int.
Referenced by ComputeIntFeatures(), ExtractOutlineFeatures(), ExtractPicoFeatures(), GetAdaptiveFeatures(), GetBaselineFeatures(), MakeNewAdaptedClass(), NormalizeOutlines(), ShowBestMatchFor(), ShowMatchDisplay(), and tess_training_tester().