31 using namespace KKMLL;
126 "TransparancyConvexHull",
127 "TransparancyPixelCount",
133 "TransparancyClose3",
134 "TransparancyClose5",
135 "TransparancyClose7",
177 totPixsForMorphOps (4000000),
178 workRaster1Area (NULL),
179 workRaster2Area (NULL),
180 workRaster3Area (NULL),
181 workRaster1Rows (NULL),
182 workRaster2Rows (NULL),
183 workRaster3Rows (NULL)
185 workRaster1Area =
new uchar[totPixsForMorphOps];
186 workRaster2Area =
new uchar[totPixsForMorphOps];
187 workRaster3Area =
new uchar[totPixsForMorphOps];
195 delete workRaster1Area; workRaster1Area = NULL;
196 delete workRaster2Area; workRaster2Area = NULL;
197 delete workRaster3Area; workRaster3Area = NULL;
198 delete workRaster1Rows; workRaster1Rows = NULL;
199 delete workRaster2Rows; workRaster2Rows = NULL;
200 delete workRaster3Rows; workRaster3Rows = NULL;
214 kkint32 destHeight = (srcHeight + multiple - 1) / multiple;
215 kkint32 destWidth = (srcWidth + multiple - 1) / multiple;
225 kkint32 heightOffset = (srcHeight % multiple) / 2;
226 kkint32 widthOffset = (srcWidth % multiple) / 2;
228 srcRow = -heightOffset;
232 for (destRow = 0; destRow < destHeight; ++destRow)
234 srcCol = -widthOffset;
235 for (destCol = 0; destCol < destWidth; ++destCol)
239 kkint32 srcRowStart = Max (0, srcRow);
240 kkint32 srcRowEnd = Min (srcRow + multiple, srcHeight);
241 kkint32 srcColStart = Max (0, srcCol);
242 kkint32 srcColEnd = Min (srcCol + multiple, srcWidth);
246 for (r = srcRowStart; r <srcRowEnd; ++r)
248 for (c = srcColStart; c <srcColEnd; ++c)
250 total += srcMatrix[r][c];
254 destMatrix[destRow][destCol] = (
uchar)(total / count);
269 if (!intermediateImages)
272 RasterPtr newRaster = NULL;
274 kkint32 largestDim = Max (raster.Height (), raster.Width ());
275 if (largestDim < 300)
282 while ((largestDim / reductionMultiple) > 300)
288 intermediateImages->PushOnBack (newRaster);
304 memset (destData, 0, totPixels);
307 for (x = 0; x < totPixels; ++x)
309 if ((srcData[x] >= lower) && (srcData[x] < upper))
317 const MLClassPtr knownClass,
319 float priorReductionFactor,
330 kkint32 areaBeforeReduction = 0;
331 float weighedSizeBeforeReduction = 0.0f;
338 weighedSizeBeforeReduction
, 345 kkint32 reducedHeight = srcHeight;
346 kkint32 reducedWidth = srcWidth;
348 kkint32 reducedSquareArea = reducedHeight * reducedWidth;
352 while (reducedSquareArea > totPixsForMorphOps)
355 reducedHeight = (srcHeight + reductionMultiple - 1) / reductionMultiple;
356 reducedWidth = (srcWidth + reductionMultiple - 1) / reductionMultiple;
357 reducedSquareArea = reducedHeight * reducedWidth;
360 kkint32 reductionMultipleSquared = reductionMultiple * reductionMultiple;
362 float totalReductionMultiple = priorReductionFactor * reductionMultiple;
363 float totalReductionMultipleSquared = totalReductionMultiple * totalReductionMultiple;
365 delete workRaster1Rows; workRaster1Rows =
new uchar*[reducedHeight];
366 delete workRaster2Rows; workRaster2Rows =
new uchar*[reducedHeight];
367 delete workRaster3Rows; workRaster3Rows =
new uchar*[reducedHeight];
369 uchar* wp1 = workRaster1Area;
370 uchar* wp2 = workRaster2Area;
371 uchar* wp3 = workRaster3Area;
373 for (row = 0; row < reducedHeight; ++row)
375 workRaster1Rows[row] = wp1;
376 workRaster2Rows[row] = wp2;
377 workRaster3Rows[row] = wp3;
383 Raster workRaster1
(reducedHeight
, reducedWidth
, workRaster1Area
, workRaster1Rows
);
384 Raster workRaster2
(reducedHeight
, reducedWidth
, workRaster2Area
, workRaster2Rows
);
385 Raster workRaster3
(reducedHeight
, reducedWidth
, workRaster3Area
, workRaster3Rows
);
387 Raster const * initRaster = NULL;
388 RasterPtr wr1 = NULL;
389 RasterPtr wr2 = NULL;
391 if (reductionMultiple > 1)
395 ReductionByMultiple (reductionMultiple, srcImage, workRaster1);
399 runLog.Level (-1) << endl <<
"GrayScaleImagesFVProducer::ComputeFeatureVector ***ERROR*** Exception calling 'ReductionByMultiple'." << endl << endl;
402 initRaster = &workRaster1;
408 initRaster = &srcImage;
413 if (areaBeforeReduction < 20)
415 for (
kkint32 tp = 0; tp < maxNumOfFeatures; tp++)
416 featureData[tp] = 9999999;
421 float centralMoments[9];
422 float centralMomentsWeighted[9];
425 float pixelCountWeightedReduced = 0.0f;
430 float edgeMomentf[9];
439 if (intermediateImages)
442 SaveIntermediateImage (*wr2,
"Edge_Image_" + StrFormatInt (numEdgePixelsFound
, "ZZZZ0"), intermediateImages);
451 if (intermediateImages)
453 KKStr convexImageFileName =
"ConvexHull_" + 455 SaveIntermediateImage (*wr1, convexImageFileName, intermediateImages);
467 if (intermediateImages)
474 if (intermediateImages)
480 if (intermediateImages)
486 if (intermediateImages)
492 if (intermediateImages)
497 if (intermediateImages)
503 if (intermediateImages)
509 if (intermediateImages)
513 featureData[SizeIndex] =
float (areaBeforeReduction * priorReductionFactor);
514 featureData[Moment1Index] =
float (centralMoments[1]);
515 featureData[Moment2Index] =
float (centralMoments[2]);
516 featureData[Moment3Index] =
float (centralMoments[3]);
517 featureData[Moment4Index] =
float (centralMoments[4]);
518 featureData[Moment5Index] =
float (centralMoments[5]);
519 featureData[Moment6Index] =
float (centralMoments[6]);
520 featureData[Moment7Index] =
float (centralMoments[7]);
521 featureData[Moment8Index] =
float (centralMoments[8]);
523 featureData[WeighedMoment0Index] = centralMomentsWeighted[0] * totalReductionMultiple;
524 featureData[WeighedMoment1Index] = centralMomentsWeighted[1];
525 featureData[WeighedMoment2Index] = centralMomentsWeighted[2];
526 featureData[WeighedMoment3Index] = centralMomentsWeighted[3];
527 featureData[WeighedMoment4Index] = centralMomentsWeighted[4];
528 featureData[WeighedMoment5Index] = centralMomentsWeighted[5];
529 featureData[WeighedMoment6Index] = centralMomentsWeighted[6];
530 featureData[WeighedMoment7Index] = centralMomentsWeighted[7];
531 featureData[WeighedMoment8Index] = centralMomentsWeighted[8];
533 featureData[EdgeSizeIndex] = (
float)edgeMomentf[0] * totalReductionMultiple;
534 featureData[EdgeMoment1Index] = (
float)edgeMomentf[1];
535 featureData[EdgeMoment2Index] = (
float)edgeMomentf[2];
536 featureData[EdgeMoment3Index] = (
float)edgeMomentf[3];
537 featureData[EdgeMoment4Index] = (
float)edgeMomentf[4];
538 featureData[EdgeMoment5Index] = (
float)edgeMomentf[5];
539 featureData[EdgeMoment6Index] = (
float)edgeMomentf[6];
540 featureData[EdgeMoment7Index] = (
float)edgeMomentf[7];
541 featureData[EdgeMoment8Index] = (
float)edgeMomentf[8];
550 if ((area > convexf) && (convexf > 0))
551 featureData[TransparancyConvexHullIndex] = 1.0;
553 featureData[TransparancyConvexHullIndex] = (
float)area / (
float)convexf;
555 featureData[TransparancyPixelCountIndex] = (
float)area / (
float)tranf;
556 featureData[TransparancyOpen3Index] = (
float)(area - areaOpen3) / (
float)area;
557 featureData[TransparancyOpen5Index] = (
float)(area - areaOpen5) / (
float)area;
558 featureData[TransparancyOpen7Index] = (
float)(area - areaOpen7) / (
float)area;
559 featureData[TransparancyOpen9Index] = (
float)(area - areaOpen9) / (
float)area;
560 featureData[TransparancyClose3Index] = (
float)(area - areaClose3) / (
float)area;
561 featureData[TransparancyClose5Index] = (
float)(area - areaClose5) / (
float)area;
562 featureData[TransparancyClose7Index] = (
float)(area - areaClose7) / (
float)area;
570 featureData[ConvexAreaIndex] = convexf * totalReductionMultipleSquared;
571 featureData[TransparancySizeIndex] = (
float)(centralMoments[0] / convexf);
572 featureData[TransparancyWtdIndex] = (
float)(centralMomentsWeighted[0] / convexf);
574 float areaD =
float (areaBeforeReduction);
576 featureData[IntensityHist1Index] = ((
float)intensityHistBuckets[1] / areaD);
577 featureData[IntensityHist2Index] = ((
float)intensityHistBuckets[2] / areaD);
578 featureData[IntensityHist3Index] = ((
float)intensityHistBuckets[3] / areaD);
579 featureData[IntensityHist4Index] = ((
float)intensityHistBuckets[4] / areaD);
580 featureData[IntensityHist5Index] = ((
float)intensityHistBuckets[5] / areaD);
581 featureData[IntensityHist6Index] = ((
float)intensityHistBuckets[6] / areaD);
582 featureData[IntensityHist7Index] = ((
float)intensityHistBuckets[7] / areaD);
586 RasterPtr darkSpots = NULL;
588 BinarizeImageByThreshold (200, 255, *initRaster, *wr1);
595 int darkSpotFreq[10];
597 for (x = 0; x < 10; ++x)
600 KKB::BlobList::iterator idx;
601 for (idx = blobs->begin (); idx != blobs->end (); ++idx)
607 double logOfThree = ::log (3.0);
609 int index = (
int)floor (l / logOfThree);
610 index = Min (Max (0, index), 9);
611 ++(darkSpotFreq[index]);
614 featureData[DarkSpotCount0] = (
float)darkSpotFreq[0];
615 featureData[DarkSpotCount1] = (
float)darkSpotFreq[1];
616 featureData[DarkSpotCount2] = (
float)darkSpotFreq[2];
617 featureData[DarkSpotCount3] = (
float)darkSpotFreq[3];
618 featureData[DarkSpotCount4] = (
float)darkSpotFreq[4];
619 featureData[DarkSpotCount5] = (
float)darkSpotFreq[5];
620 featureData[DarkSpotCount6] = (
float)darkSpotFreq[6];
621 featureData[DarkSpotCount7] = (
float)darkSpotFreq[7];
622 featureData[DarkSpotCount8] = (
float)darkSpotFreq[8];
623 featureData[DarkSpotCount9] = (
float)darkSpotFreq[9];
629 if (intermediateImages)
632 SaveIntermediateImage (*thinnedImage,
"_Thinned", intermediateImages);
637 featureData[0] = (
float)areaBeforeReduction;
670 if (existingFileDesc)
671 return existingFileDesc;
674 if (!existingFileDesc)
676 bool alreadyExists =
false;
678 for (
kkint32 fieldNum = 0; fieldNum < maxNumOfFeatures; ++fieldNum)
690 return existingFileDesc;
710 FactoryFVProducer("GrayScaleImagesFVProducerFactory", "FeatureVector", "General Purpose Grayscale Image Feature Computer") __int16 kkint16
16 bit signed integer.
void Erosion(RasterPtr dest) const
Place into destination a eroded version of this instances image.
virtual ~GrayScaleImagesFVProducerFactory()
A Factory can never be deleted until the application terminates; the atexit method will perform the d...
void CentralMoments(float features[9]) const
returns in 'features' the 8 central moments as defined by Hu plus eccentricity in the eight bucket...
Provides a detailed description of the attributes of a dataset.
static FileDescPtr GetExistingFileDesc(FileDescPtr fileDesc)
Returns a pointer to an existing instance of 'fileDesc' if it exists, otherwise will use one being pa...
static FeatureFileIOC45Ptr Driver()
virtual const type_info * FeatureVectorTypeId() const
Returns the 'type_info' of the Feature Vector that this instance of 'FeatureComputer' creates...
void AddAAttribute(const KKB::KKStr &_name, KKMLL::AttributeType _type, bool &alreadyExists)
virtual GrayScaleImagesFVProducerPtr ManufactureInstance(RunLog &runLog)
FactoryFVProducer(const KKStr &_name, const KKStr &_fvClassName, const KKStr &_description)
FeatureVector(kkint32 _numOfFeatures)
BlobListPtr ExtractBlobs(kkint32 dist)
Will extract a list of connected components from this instance.
Supports the reading and writing of feature data from C45 formated feature files. ...
A class that is used by to represent a single image in memory.
GrayScaleImagesFVProducer(FactoryFVProducerPtr factory)
ConvexHull * ConvexHullPtr
FileDescConstPtr FileDesc() const
Returns back a "FileDesc" instance that describes the features that this instance of 'FeatureVectorPr...
static void RegisterFactory(FactoryFVProducerPtr factory, RunLog *runLog)
This is where you register newly instantiated instances of 'FactoryFVProducer' derived classes...
virtual FeatureVectorListPtr ManufacturFeatureVectorList(bool owner, RunLog &runLog) const
Manufactures a instance of a derived 'FeatureVectorList' class that is appropriate for containing ins...
void Version(kkint16 _version)
#define _GrayScaleImagesFVProducer_VersionNum_
unsigned __int32 kkuint32
virtual FeatureVectorListPtr ManufacturFeatureVectorList(bool owner, RunLog &runLog) const
Manufactures a instance of a 'LarcosFeatureVectorList' class that will own its contents.
static FileDescPtr DefineFileDescStatic()
FeatureVectorList(FileDescPtr _fileDesc, bool _owner)
Will create a new empty list of FeatureVector's.
virtual FileDescPtr FileDesc() const
void Edge(RasterPtr dest)
Container class for FeatureVector derived objects.
void FillHole(RasterPtr mask)
Fills holes in the image using the 'mask' raster as a work area.
RasterList * RasterListPtr
RasterPtr Filter(const Raster &src, RasterPtr dest)
KKStr operator+(const char *left, const KKStr &right)
virtual ~GrayScaleImagesFVProducer()
virtual const type_info * FeatureVectorListTypeId() const
Returns the 'type_info' of the FeatureVectorList that this instance of 'FactoryFVProducer' will creat...
void CalcAreaAndIntensityFeatures(kkint32 &area, float &weightedSize, kkuint32 intensityHistBuckets[8]) const
Calculates both Intensity Histograms, one not including internal background pixels and one with plus ...
virtual const type_info * FeatureVectorTypeId() const
Returns the 'type_info' of the FeatureVector that this instance of 'FactoryFVProducer' works with...
void Dilation(RasterPtr dest) const
RasterPtr ReduceByEvenMultiple(kkint32 multiple) const
unsigned char uchar
Unsigned character.
kkint32 ForegroundPixelCount() const
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
void Dilation(RasterPtr dest, MaskTypes mask) const
void Erosion(RasterPtr dest, MaskTypes mask) const
void MLClass(MLClassPtr _mlClass)
Assign a class to this example.
kkint32 TotPixels() const
KKStr StrFormatInt(kkint32 val, const char *mask)
GrayScaleImagesFVProducer * GrayScaleImagesFVProducerPtr
uchar * GreenArea() const
virtual FeatureFileIOPtr DefaultFeatureFileIO() const
void Version(kkint16 _version)
virtual FeatureVectorPtr ComputeFeatureVector(const Raster &srcImage, const MLClassPtr knownClass, RasterListPtr intermediateImages, float priorReductionFactor, RunLog &runLog)
Compute a FeatureVector for the supplied 'image'.
void ComputeCentralMoments(kkint32 &foregroundPixelCount, float &weightedPixelCount, float centralMoments[9], float centralMomentsWeighted[9]) const
Computes central moments; one set where each pixel is treated as 1 or 0(Foreground/Background) and th...
FeatureVectorProducer(const KKStr &_name, FactoryFVProducerPtr _factory)
void OrigSize(float _origSize)
The value of Feature[0] before normalization.
Operator that will create a Convex Hull of a supplied image.
Raster(kkint32 _height, kkint32 _width, uchar *_Data, uchar **_Rows)
Construct a raster object that will utilize a image already in memory.
Base class for all Morphological operations.
Used for logging messages.
void EncodeProblem(const struct svm_paramater ¶m, struct svm_problem &prob_in, struct svm_problem &prob_out)
virtual FileDescPtr DefineFileDesc() const
Raster(const Raster &_raster)
Copy Constructor.
Responsible for creating a FeatureFectorProducer instance.
virtual kkint16 Version() const
static GrayScaleImagesFVProducerFactory * Factory(RunLog *runLog)
Returns instance of "GrayScaleImagesFVProducerFactory" that is registered with "FactoryFVProducer::Re...
void FileName(const KKStr &_fileName)
kkint32 PixelCount()
Number of pixels that are part of this blob.
RasterPtr ThinContour() const
Represents a Feature Vector of a single example, labeled or unlabeled.
Maintains one instance of a GoalKeeper object that can be used anywhere in the application.
float * FeatureDataAlter()
Same as 'FeatureData() except you can modify the data.
A abstract class that is meant to compute a FeatureVector from a source image.
virtual const type_info * FeatureVectorListTypeId() const
Returns the 'type_info' of the FeatureVectorList derived class that can contain instances in 'Feature...