42 using namespace KKMLL;
46 using namespace KKMLL;
67 centroidCol (_fv.centroidCol),
68 centroidRow (_fv.centroidRow),
69 numOfEdgePixels (_fv.numOfEdgePixels)
137 FeatureExtraction (_fvProducerFactory, _dirName, _fileName, _mlClass, _log);
144 FeatureVectorList (examples.FileDesc (), examples.Owner ())
147 for (idx = examples.begin (); idx != examples.end (); idx
++)
149 const GrayScaleImagesFVPtr imageExample =
*idx;
151 PushOnBack (
new GrayScaleImagesFV (*imageExample));
153 PushOnBack (imageExample);
167 for (idx = examples.begin (); idx != examples.end (); idx
++)
169 const GrayScaleImagesFVPtr imageExample =
*idx;
171 PushOnBack (
new GrayScaleImagesFV (*imageExample));
173 PushOnBack (imageExample);
195 FeatureVectorList::const_iterator idx;
196 for (idx = featureVectorList.begin (); idx != featureVectorList.end (); idx++)
198 FeatureVectorPtr featureVector = *idx;
208 PushOnBack (example);
216 FeatureVectorList::const_iterator idx;
217 for (idx = featureVectorList.begin (); idx != featureVectorList.end (); idx++)
219 FeatureVectorPtr featureVector = *idx;
223 GrayScaleImagesFVPtr example =
dynamic_cast<GrayScaleImagesFVPtr>(featureVector);
224 PushOnBack (example);
229 KKStr errMSsg =
"GrayScaleImagesFVList One of the elements in 'featureVectorList' is not of 'GrayScaleImagesFV' type.";
231 <<
"GrayScaleImagesFVList::GrayScaleImagesFVList (const FeatureVectorList& featureVectorList) ***ERROR***" << endl
232 <<
" " << errMSsg << endl
233 <<
" FileName[" << featureVector->ExampleFileName () <<
"]" << endl
277 if (featureVectorList.Owner ())
279 FeatureVectorList::const_iterator idx;
280 for (idx = featureVectorList.begin (); idx != featureVectorList.end (); idx++)
282 FeatureVectorPtr featureVector = *idx;
291 GrayScaleImagesFVPtr example =
new GrayScaleImagesFV (*featureVector);
292 PushOnBack (example);
300 FeatureVectorList::const_iterator idx;
301 for (idx = featureVectorList.begin (); idx != featureVectorList.end (); idx++)
303 FeatureVectorPtr featureVector = *idx;
305 if (
typeid (*featureVector) ==
typeid (GrayScaleImagesFV))
307 GrayScaleImagesFVPtr example =
dynamic_cast<GrayScaleImagesFVPtr>(featureVector);
308 PushOnBack (example);
314 errMsg <<
"GrayScaleImagesFVList ***ERROR*** One of the elements in 'featureVectorList' is not of 'GrayScaleImagesFV' type. We can not recast this element" 315 <<
" FileName[" << featureVector->ExampleFileName () <<
"]";
317 cerr << endl << errMsg << endl << endl;
318 throw KKException (errMsg);
344 return (GrayScaleImagesFVPtr)FeatureVectorList::IdxToPtr (idx);
356 FeatureVectorPtr fv = back ();
359 return dynamic_cast<GrayScaleImagesFVPtr> (fv);
361 KKStr errMsg =
"GrayScaleImagesFVList::BackOfQueue () ***ERROR*** Entry at back of Queue is not a 'GrayScaleImagesFV' object.";
362 cerr << endl << errMsg << endl << endl;
371 if (size () < 1)
return NULL;
373 FeatureVectorPtr fv = back ();
377 KKStr errMsg =
"GrayScaleImagesFVList::PopFromBack () ***ERROR*** Entry at back of Queue is not a 'GrayScaleImagesFV' object.";
378 cerr << endl << errMsg << endl << endl;
382 return dynamic_cast<GrayScaleImagesFVPtr> (FeatureVectorList::PopFromBack ());
392 FeatureVectorList::AddQueue (imagesToAdd);
402 return (GrayScaleImagesFVPtr)FeatureVectorList::BinarySearchByName (_imageFileName);
411 return (GrayScaleImagesFVPtr)FeatureVectorList::LookUpByRootName (_rootName);
421 return (GrayScaleImagesFVPtr)FeatureVectorList::LookUpByImageFileName (_imageFileName);
429 return new GrayScaleImagesFVList (FileDesc (), _owner);
440 examples->Owner (
false);
443 return orderedImages;
459 _log.Level (10) <<
"FeatureExtraction, dirName [" << _dirName <<
"]." << endl;
460 _log.Level (10) <<
" fileName [" << _fileName <<
"]." << endl;
461 _log.Level (10) <<
" className [" << className <<
"]." << endl;
463 bool cancelFlag =
false;
464 bool successful =
false;
469 KKStr fullFeatureFileName
(_dirName
);
470 fullFeatureFileName << _fileName;
472 KKStrListPtr fileNameList;
483 KKStrList::iterator fnIDX = fileNameList->begin ();
485 KKStrPtr imageFileName = NULL;
487 kkint32 numOfImages = fileNameList->QueueSize ();
490 for (fnIDX = fileNameList->begin (); fnIDX != fileNameList->end (); ++fnIDX)
492 if ((count % 100) == 0)
493 cout << className <<
" " << count <<
" of " << numOfImages << endl;
495 imageFileName = *fnIDX;
499 if (!validImageFileFormat)
508 msg <<
"GrayScaleImagesFVList::FeatureExtraction ***ERROR*** Could not Allocate GrayScaleImagesFV object" << endl
509 <<
"for FileName[" << fullFileName <<
"].";
510 _log.Level (-1) << endl << msg << endl << endl;
514 GrayScaleImagesFVPtr larcosFeatureVector = NULL;
517 larcosFeatureVector =
dynamic_cast<GrayScaleImagesFVPtr>(featureVector);
518 featureVector = NULL;
523 delete featureVector;
524 featureVector = NULL;
528 _log.Level (30) << larcosFeatureVector->ExampleFileName () <<
" " << larcosFeatureVector->OrigSize () << endl;
529 PushOnBack (larcosFeatureVector);
534 Version (fvProducer->Version ());
536 delete fvProducer; fvProducer = NULL;
542 FeatureFileIOC45::Driver ()->SaveFeatureFile (fullFeatureFileName,
543 FeatureNumList::AllFeatures (FileDesc ()),
567 for (
kkint32 idx = 0; idx < QueueSize (); idx++)
569 GrayScaleImagesFVPtr curImage = (GrayScaleImagesFVPtr)
IdxToPtr (idx
);
570 copyiedList->PushOnBack (
new GrayScaleImagesFV (*curImage));
573 copyiedList->Version (Version ());
584 const KKStr& rootDir,
589 log.Level (20) <<
"RecalcFeatureValuesFromImagesInDirTree RootDir[" << rootDir <<
"]." << endl;
595 if (QueueSize () < 1)
603 log.Level (10) <<
"RecalcFeatureValuesFromImagesInDirTree No Image Files in[" << rootDir <<
"]" << endl;
609 KKStrConstPtr dirPath = NULL;
612 GrayScaleImagesFVPtr example = NULL;
614 for (idx = begin (); idx != end (); idx
++)
620 log.Level (10) <<
"RecalcFeatureValuesFromImagesInDirTree Could not locate Image[" << example->ExampleFileName () <<
"] in Subdirectory Tree." << endl;
632 delete raster; raster = NULL;
633 log.Level (-1) <<
"GrayScaleImagesFVList::RecalcFeatureValuesFromImagesInDirTree ***ERROR*** Unable to load image: " << fullFileName << endl << endl;
641 kkint32 featureCount = Min (fv->NumOfFeatures (), example->NumOfFeatures ());
642 for (x = 0; x < featureCount; ++x)
650 GrayScaleImagesFVPtr lfv =
dynamic_cast<GrayScaleImagesFVPtr>(fv);
659 delete raster; raster = NULL;
673 FeatureVectorListPtr duplicateFeatureVectorObjects = FeatureVectorList::ExtractDuplicatesByRootImageFileName ();
675 duplicateFeatureVectorObjects->Owner (
false);
676 delete duplicateFeatureVectorObjects; duplicateFeatureVectorObjects = NULL;
677 return duplicateImageFeaturesObjects;
690 FeatureVectorListPtr featureVectorList = FeatureVectorList::ExtractExamplesForAGivenClass (_mlClass, _maxToExtract, _minSize);
692 featureVectorList->Owner (
false);
693 delete featureVectorList; featureVectorList = NULL;
694 return imageFeaturesList;
707 FeatureVectorListPtr stratifiedFeatureVectors = FeatureVectorList::StratifyAmoungstClasses (mlClasses, maxImagesPerClass, numOfFolds, log);
709 stratifiedFeatureVectors->Owner (
false);
710 delete stratifiedFeatureVectors; stratifiedFeatureVectors = NULL;
711 return stratifiedImagefeatures;
723 FeatureVectorListPtr stratifiedFeatureVectors = FeatureVectorList::StratifyAmoungstClasses (classes, -1, numOfFolds, log);
726 stratifiedFeatureVectors->Owner (
false);
728 delete stratifiedFeatureVectors; stratifiedFeatureVectors = NULL;
729 delete classes; classes = NULL;
731 return stratifiedImagefeatures;
GrayScaleImagesFV(const GrayScaleImagesFV &_fv)
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for 'size' characters.
void ExampleFileName(const KKStr &_exampleFileName)
Name of source of feature vector, ex: file name of image that the feature vector was computed from...
GrayScaleImagesFVList(FileDescPtr _fileDesc, bool _owner)
kkuint32 Size()
returns the number of image files found the sub-directory tree.
GrayScaleImagesFVListPtr StratifyAmoungstClasses(kkint32 numOfFolds, RunLog &log)
const_iterator & operator++(int x)
GrayScaleImagesFVListPtr ExtractDuplicatesByRootImageFileName()
GrayScaleImagesFVList(const FeatureVectorList &featureVectorList, bool _owner)
Creates a duplicate List of examples, in the same order, and depending on '_owner' will create new in...
GrayScaleImagesFVPtr PopFromBack()
void AddQueue(GrayScaleImagesFVList &imagesToAdd)
float FeatureData(kkint32 featureNum) const
GrayScaleImagesFVPtr LookUpByImageFileName(const KKStr &_imageFileName) const
FeatureVector(kkint32 _numOfFeatures)
Raster(const KKStr &fileName, bool &validFile)
Constructs a Raster image from by reading an existing image File such as a BMP file.
float OrigSize() const
The value of Feature[0] before normalization.
GrayScaleImagesFVList(MLClassList &_mlClasses, GrayScaleImagesFVList &_examples)
constructor that will create a list of examples from _examples that are assigned one of the classes l...
A class that is used by to represent a single image in memory.
float CentroidRow() const
const FileDescPtr FileDesc() const
GrayScaleImagesFVPtr LookUpByRootName(const KKStr &_rootName)
GrayScaleImagesFVList(const GrayScaleImagesFVList &_examples, bool _owner)
Creates a duplicate List of examples, in the same order, and depending on '_owner' will create new in...
float CentroidCol() const
Creates a index of all images in a specified directory structure.
GrayScaleImagesFV(const FeatureVector &featureVector)
Smart copy constructor that will detect the underlying type of the source instance.
KKStrListPtr osGetListOfFiles(const KKStr &fileSpec)
Returns a list of files that match the provided file specification.
bool SupportedImageFileFormat(const KKStr &imageFileName)
unsigned __int32 kkuint32
virtual GrayScaleImagesFVListPtr ManufactureEmptyList(bool _owner) const
Creates an instance of a Empty FeatureVectorList.
FeatureVectorList(FileDescPtr _fileDesc, bool _owner)
Will create a new empty list of FeatureVector's.
virtual GrayScaleImagesFVListPtr DuplicateListAndContents() const
Creates a duplicate of list and also duplicates it contents.
FeatureVector(const FeatureVector &_example)
Container class for FeatureVector derived objects.
KKB::KKStr osAddSlash(const KKStr &fileSpec)
GrayScaleImagesFVList(FactoryFVProducerPtr _fvProducerFactory, MLClassPtr _mlClass, KKStr _dirName, KKStr _fileName, RunLog &_log)
Constructor that will extract a list of feature vectors for all the image files in the specified dire...
bool operator==(const FeatureVectorList::iterator &right) const
GrayScaleImagesFVPtr BinarySearchByName(const KKStr &_imageFileName) const
Specialized version of KKMLL::FeatureVector that will be used to represent the features of a Shrimp...
KKStr(const KKStr &str)
Copy Constructor.
virtual FeatureVectorProducerPtr ManufactureInstance(RunLog &runLog)=0
Derived classes will instantiate appropriate instances of 'FeatureVectorProducer'.
iterator & operator++(int x)
void CentroidCol(float _centroidCol)
KKStrConstPtr LocateImage(const KKStr &fileName)
Locate image specified by 'fileName' and return the directory where it is located.
GrayScaleImagesFVPtr BackOfQueue()
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of 'std::string' strings.
virtual FeatureVectorPtr ComputeFeatureVector(const Raster &image, const MLClassPtr knownClass, RasterListPtr intermediateImages, float priorReductionFactor, RunLog &runLog)=0
Compute a FeatureVector for the supplied 'image'.
void CentroidRow(float _centroidRow)
virtual FeatureVectorPtr ComputeFeatureVectorFromImage(const KKStr &fileName, const MLClassPtr knownClass, RasterListPtr intermediateImages, RunLog &runLog)
Compute a FeatureVector from the image file specified by 'fileName'.
MLClassPtr MLClass() const
Class that is example is assigned to.
void NumOfEdgePixels(kkint32 _numOfEdgePixels)
GrayScaleImagesFVPtr operator*()
void FeatureData(kkint32 _featureNum, float _featureValue)
Assign a value to a specific feature number for the feature vector.
GrayScaleImagesFVListPtr OrderUsingNamesFromAFile(const KKStr &fileName, RunLog &log)
Using list of ImageFileNames in a file('fileName') create a new GrayScaleImagesFVList instance with e...
virtual ~GrayScaleImagesFVList()
const KKStr & Name() const
virtual ~GrayScaleImagesFV()
KKStr operator+(const KKStr &right) const
void Version(kkint16 _version)
GrayScaleImagesFV(kkint32 _numOfFeatures)
GrayScaleImagesFVListPtr ExtractExamplesForAGivenClass(MLClassPtr _mlClass, kkint32 _maxToExtract=-1, float _minSize=-1.0f) const
ImageDirTree(KKStr _subDir)
Construct a Index of images for a specified SubDirectory structure. details Given a specified directo...
void OrigSize(float _origSize)
The value of Feature[0] before normalization.
Used for logging messages.
void EncodeProblem(const struct svm_paramater ¶m, struct svm_problem &prob_in, struct svm_problem &prob_out)
MLClassList * MLClassListPtr
GrayScaleImagesFVList * GrayScaleImagesFVListPtr
virtual GrayScaleImagesFVPtr Duplicate() const
iterator(const FeatureVectorList::iterator &idx)
virtual GrayScaleImagesFVListPtr Duplicate(bool _owner) const
Creates a duplicate of list using the same container.
kkint32 NumOfEdgePixels() const
FeatureVectorProducer * FeatureVectorProducerPtr
KKException(const KKStr &_exceptionStr)
Maintains a list of MLClass instances.
Represents a Feature Vector of a single example, labeled or unlabeled.
virtual FileDescPtr FileDesc() const =0
GrayScaleImagesFVPtr IdxToPtr(kkint32 idx) const
const GrayScaleImagesFVPtr operator*()
FeatureVectorList * FeatureVectorListPtr
GrayScaleImagesFVList(const FeatureVectorList &featureVectorList)
const KKStr & ExampleFileName() const
Name of file that this FeatureVector was computed from.
GrayScaleImagesFVListPtr StratifyAmoungstClasses(MLClassListPtr mlClasses, kkint32 maxImagesPerClass, kkint32 numOfFolds, RunLog &log)
void osAddLastSlash(KKStr &fileSpec)
Will add the appropriate Directory separator character to the end of fileSpec if one is not there alr...
void RecalcFeatureValuesFromImagesInDirTree(FactoryFVProducerPtr fvProducerFactory, const KKStr &rootDir, bool &successful, RunLog &log)