#include "mfdefs.h"
#include "variables.h"
#include "sigmenu.h"
#include "mfoutline.h"
#include "clusttool.h"
#include "const.h"
#include "intfx.h"
#include <math.h>
Go to the source code of this file.
#define angle_of | ( | x1, | |||
y1, | |||||
x2, | |||||
y2 | ) |
#define MAX_SLOPE 2.414213562 |
#define MIN_SLOPE 0.414213562 |
** (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 35 of file mfx.cpp.
Referenced by InitMicroFxVars().
#define NOISE_SEGMENT_LENGTH (0.00) |
#define NormalizeAngle | ( | A | ) | ( (((A)<0)?((A)+2*PI):(A)) / (2*PI) ) |
#define scale_angle | ( | x | ) | (((x<0) ? (2.0 * PI + x) : (x)) * 0.5 / PI) \ |
CHAR_FEATURES BlobMicroFeatures | ( | TBLOB * | Blob, | |
LINE_STATS * | LineStats | |||
) |
Extracts micro-features from the specified blob.
Blob | Blob to extract micro-features from | |
LineStats | Statistics for text line normalization |
Definition at line 150 of file mfx.cpp.
References CharNormalizeOutline(), ConvertBlob(), ConvertToMicroFeatures(), ExtractIntFeat(), FilterEdgeNoise(), FindDirectionChanges(), first, FreeOutlines(), iterate, MarkDirectionChanges(), MaxSlope, MinSlope, NIL, NoiseSegmentLength, NULL, Outline, INT_FX_RESULT_STRUCT::Rx, INT_FX_RESULT_STRUCT::Ry, SmearBulges(), SmearExtremities(), INT_FX_RESULT_STRUCT::Xmean, and INT_FX_RESULT_STRUCT::Ymean.
Referenced by ExtractMicros().
00150 { 00151 MICROFEATURES MicroFeatures = NIL; 00152 FLOAT32 XScale, YScale; 00153 LIST Outlines; 00154 LIST RemainingOutlines; 00155 MFOUTLINE Outline; 00156 INT_FEATURE_ARRAY blfeatures; 00157 INT_FEATURE_ARRAY cnfeatures; 00158 INT_FX_RESULT_STRUCT results; 00159 00160 if (Blob != NULL) { 00161 Outlines = ConvertBlob (Blob); 00162 // NormalizeOutlines(Outlines, LineStats, &XScale, &YScale); 00163 ExtractIntFeat(Blob, blfeatures, cnfeatures, &results); 00164 XScale = 0.2f / results.Ry; 00165 YScale = 0.2f / results.Rx; 00166 00167 RemainingOutlines = Outlines; 00168 iterate(RemainingOutlines) { 00169 Outline = (MFOUTLINE) first (RemainingOutlines); 00170 CharNormalizeOutline (Outline, 00171 results.Xmean, results.Ymean, 00172 XScale, YScale); 00173 } 00174 00175 RemainingOutlines = Outlines; 00176 iterate(RemainingOutlines) { 00177 Outline = (MFOUTLINE) first (RemainingOutlines); 00178 FindDirectionChanges(Outline, MinSlope, MaxSlope); 00179 FilterEdgeNoise(Outline, NoiseSegmentLength); 00180 MarkDirectionChanges(Outline); 00181 SmearExtremities(Outline, XScale, YScale); 00182 MicroFeatures = ConvertToMicroFeatures (Outline, MicroFeatures); 00183 } 00184 SmearBulges(MicroFeatures, XScale, YScale); 00185 FreeOutlines(Outlines); 00186 } 00187 return ((CHAR_FEATURES) MicroFeatures); 00188 } /* BlobMicroFeatures */
void ComputeBulges | ( | MFOUTLINE | Start, | |
MFOUTLINE | End, | |||
MICROFEATURE | MicroFeature | |||
) |
Computes the size of the "bulges" of the specified micro-feature.
Start | Starting point of micro-feature | |
End | Ending point of micro-feature | |
MicroFeature | Micro-feature whose bulges are to be computed |
This routine assumes that Start and End are not the same point. It also assumes that the orientation and length parameters of the micro-feature have already been computed.
Definition at line 240 of file mfx.cpp.
References BULGENORMALIZER, CopyPoint, FillPoint, FirstBulgeOf, InitMatrix, LengthOf, MapPoint, NextPointAfter, OrientationOf, PI, PointAt, PositionOf, RotateMatrix(), SecondBulgeOf, TranslateMatrix, XIntersectionOf, Xof, XPositionOf, and YPositionOf.
Referenced by ExtractMicroFeature().
00240 { 00241 MATRIX_2D Matrix; 00242 MFEDGEPT *Origin; 00243 MFOUTLINE SegmentStart, SegmentEnd; 00244 FPOINT CurrentPoint, LastPoint; 00245 FLOAT32 BulgePosition; 00246 00247 /* check for simple case */ 00248 if (End == NextPointAfter (Start)) 00249 FirstBulgeOf (MicroFeature) = SecondBulgeOf (MicroFeature) = 0; 00250 else { 00251 Origin = PointAt (Start); 00252 00253 InitMatrix(&Matrix); 00254 RotateMatrix (&Matrix, OrientationOf (MicroFeature) * -2.0 * PI); 00255 TranslateMatrix (&Matrix, -XPositionOf (Origin), -YPositionOf (Origin)); 00256 00257 SegmentEnd = Start; 00258 FillPoint (CurrentPoint, 0, 0); 00259 BulgePosition = LengthOf (MicroFeature) / 3; 00260 CopyPoint(CurrentPoint, LastPoint); 00261 while (Xof (CurrentPoint) < BulgePosition) { 00262 SegmentStart = SegmentEnd; 00263 SegmentEnd = NextPointAfter (SegmentStart); 00264 CopyPoint(CurrentPoint, LastPoint); 00265 MapPoint (&Matrix, PositionOf (PointAt (SegmentEnd)), CurrentPoint); 00266 } 00267 FirstBulgeOf (MicroFeature) = 00268 XIntersectionOf(LastPoint, CurrentPoint, BulgePosition); 00269 00270 BulgePosition *= 2; 00271 00272 // Prevents from copying the points before computing the bulge if 00273 // CurrentPoint will not change. (Which would cause to output nan 00274 // for the SecondBulge.) 00275 if (Xof (CurrentPoint) < BulgePosition) 00276 CopyPoint(CurrentPoint, LastPoint); 00277 while (Xof (CurrentPoint) < BulgePosition) { 00278 SegmentStart = SegmentEnd; 00279 SegmentEnd = NextPointAfter (SegmentStart); 00280 CopyPoint(CurrentPoint, LastPoint); 00281 MapPoint (&Matrix, PositionOf (PointAt (SegmentEnd)), CurrentPoint); 00282 } 00283 SecondBulgeOf (MicroFeature) = 00284 XIntersectionOf(LastPoint, CurrentPoint, BulgePosition); 00285 00286 FirstBulgeOf (MicroFeature) /= BULGENORMALIZER * 00287 LengthOf(MicroFeature); 00288 SecondBulgeOf (MicroFeature) /= BULGENORMALIZER * 00289 LengthOf(MicroFeature); 00290 } 00291 } /* ComputeBulges */
Computes the orientation parameter of the specified micro-feature.
Start | Starting edge point of micro-feature | |
End | Ending edge point of micro-feature |
This routine assumes that Start and End are not the same point.
Definition at line 314 of file mfx.cpp.
References AngleFrom, NormalizeAngle, and PositionOf.
00314 { 00315 FLOAT32 Orientation; 00316 00317 Orientation = NormalizeAngle (AngleFrom (PositionOf (Start), 00318 PositionOf (End))); 00319 00320 /* ensure that round-off errors do not put circular param out of range */ 00321 if ((Orientation < 0) || (Orientation >= 1)) 00322 Orientation = 0; 00323 return (Orientation); 00324 } /* ComputeOrientation */
MICROFEATURES ConvertToMicroFeatures | ( | MFOUTLINE | Outline, | |
MICROFEATURES | MicroFeatures | |||
) |
Extracts micro-features from Outline and adds them to MicroFeatures.
Outline | Outline to extract micro-features from | |
MicroFeatures | List of micro-features to add to |
Definition at line 337 of file mfx.cpp.
References DegenerateOutline, ExtractMicroFeature(), NewFeature(), NextExtremity(), NULL, and push().
Referenced by BlobMicroFeatures().
00338 { 00339 MFOUTLINE Current; 00340 MFOUTLINE Last; 00341 MFOUTLINE First; 00342 MICROFEATURE NewFeature; 00343 00344 if (DegenerateOutline (Outline)) 00345 return (MicroFeatures); 00346 00347 First = NextExtremity (Outline); 00348 Last = First; 00349 do { 00350 Current = NextExtremity (Last); 00351 NewFeature = ExtractMicroFeature (Last, Current); 00352 if (NewFeature != NULL) 00353 MicroFeatures = push (MicroFeatures, NewFeature); 00354 Last = Current; 00355 } 00356 while (Last != First); 00357 00358 return (MicroFeatures); 00359 } /* ConvertToMicroFeatures */
MICROFEATURE ExtractMicroFeature | ( | MFOUTLINE | Start, | |
MFOUTLINE | End | |||
) |
Computes the feature parameters which describe the micro-feature that starts and Start and ends at End.
Start | Starting point of micro-feature | |
End | Ending point of micro-feature |
Definition at line 380 of file mfx.cpp.
References AverageOf, CenterX, CenterY, ComputeBulges(), DistanceBetween, LengthOf, NewFeature(), NewMicroFeature(), NormalizedAngleFrom(), OrientationOf, PointAt, PositionOf, XPositionOf, and YPositionOf.
Referenced by ConvertToMicroFeatures().
00380 { 00381 MICROFEATURE NewFeature; 00382 MFEDGEPT *P1, *P2; 00383 00384 P1 = PointAt (Start); 00385 P2 = PointAt (End); 00386 00387 NewFeature = NewMicroFeature (); 00388 CenterX (NewFeature) = AverageOf (XPositionOf (P1), XPositionOf (P2)); 00389 CenterY (NewFeature) = AverageOf (YPositionOf (P1), YPositionOf (P2)); 00390 LengthOf (NewFeature) = DistanceBetween (PositionOf (P1), PositionOf (P2)); 00391 OrientationOf (NewFeature) = 00392 NormalizedAngleFrom (&(PositionOf (P1)), &(PositionOf (P2)), 1.0); 00393 ComputeBulges(Start, End, NewFeature); 00394 return (NewFeature); 00395 } /* ExtractMicroFeature */
void InitMicroFxVars | ( | ) |
Initialize the micro-feature extractor variables (knobs) that can be tuned without recompiling.
none |
Definition at line 126 of file mfx.cpp.
References dummy, float_variable, MAX_SLOPE, MaxSlope, MIN_SLOPE, MinSlope, NOISE_SEGMENT_LENGTH, and NoiseSegmentLength.
Referenced by InitMicroFXVars().
00126 { 00127 VALUE dummy; 00128 00129 float_variable (MinSlope, "MinSlope", MIN_SLOPE); 00130 float_variable (MaxSlope, "MaxSlope", MAX_SLOPE); 00131 float_variable (NoiseSegmentLength, "NoiseSegmentLength", 00132 NOISE_SEGMENT_LENGTH); 00133 } /* InitMicroFxVars */
void SmearBulges | ( | MICROFEATURES | MicroFeatures, | |
FLOAT32 | XScale, | |||
FLOAT32 | YScale | |||
) |
Add a random amount to each bulge parameter of each feature.
MicroFeatures | Features to be smeared | |
XScale | Number of normalized units per pixel in x dir | |
YScale | Number of normalized units per pixel in y dir |
Definition at line 413 of file mfx.cpp.
References BULGENORMALIZER, FirstBulgeOf, iterate, LengthOf, NextFeatureOf, OrientationOf, PI, SecondBulgeOf, and UniformRandomNumber().
Referenced by BlobMicroFeatures().
00413 { 00414 MICROFEATURE MicroFeature; 00415 FLOAT32 MinSmear; 00416 FLOAT32 MaxSmear; 00417 FLOAT32 Cos, Sin; 00418 FLOAT32 Scale; 00419 00420 iterate(MicroFeatures) { 00421 MicroFeature = NextFeatureOf (MicroFeatures); 00422 00423 Cos = fabs (cos (2.0 * PI * OrientationOf (MicroFeature))); 00424 Sin = fabs (sin (2.0 * PI * OrientationOf (MicroFeature))); 00425 Scale = YScale * Cos + XScale * Sin; 00426 00427 MinSmear = -0.5 * Scale / (BULGENORMALIZER * LengthOf (MicroFeature)); 00428 MaxSmear = 0.5 * Scale / (BULGENORMALIZER * LengthOf (MicroFeature)); 00429 00430 FirstBulgeOf (MicroFeature) += UniformRandomNumber (MinSmear, MaxSmear); 00431 SecondBulgeOf (MicroFeature) += UniformRandomNumber (MinSmear, MaxSmear); 00432 } 00433 } /* SmearBulges */
FLOAT32 NoiseSegmentLength [static] |