KSquare Utilities
GrayScaleImagesFV.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 
3 #include <ctype.h>
4 #include <math.h>
5 #include <time.h>
6 
7 #include <string>
8 #include <iostream>
9 #include <fstream>
10 #include <map>
11 #include <vector>
12 #include <string.h>
13 #include <typeinfo>
14 
15 #include "MemoryDebug.h"
16 
17 using namespace std;
18 
19 
20 #include "KKBaseTypes.h"
21 #include "Blob.h"
22 #include "BMPImage.h"
23 #include "ContourFollower.h"
24 #include "ConvexHull.h"
25 #include "DateTime.h"
26 #include "ImageIO.h"
27 #include "KKException.h"
28 #include "OSservices.h"
29 #include "Raster.h"
30 #include "RunLog.h"
31 #include "KKStr.h"
32 using namespace KKB;
33 
34 
35 #include "FactoryFVProducer.h"
36 #include "FeatureNumList.h"
37 #include "FeatureFileIO.h"
38 #include "FeatureFileIOC45.h"
40 #include "MLClass.h"
41 #include "ImageDirTree.h"
42 using namespace KKMLL;
43 
44 
45 #include "GrayScaleImagesFV.h"
46 using namespace KKMLL;
47 
48 
49 
50 
51 
52 
54  FeatureVector (_numOfFeatures),
55 
56  centroidCol (-1),
57  centroidRow (-1),
58  numOfEdgePixels (-1)
59 {
60 }
61 
62 
63 
65  FeatureVector (_fv),
66 
67  centroidCol (_fv.centroidCol),
68  centroidRow (_fv.centroidRow),
69  numOfEdgePixels (_fv.numOfEdgePixels)
70 
71 {
72 }
73 
74 
75 
76 
77 
79  FeatureVector (featureVector),
80  centroidCol (-1),
81  centroidRow (-1),
82  numOfEdgePixels (-1)
83 
84 {
85  //if (strcmp (featureVector.UnderlyingClass (), "GrayScaleImagesFV") == 0)
86  if (typeid (featureVector) == typeid(GrayScaleImagesFV))
87  {
88  // The underlying class is another GrayScaleImagesFV object.
89  const GrayScaleImagesFV& example = dynamic_cast<const GrayScaleImagesFV&>(featureVector);
90 
91  centroidCol = example.CentroidCol ();
92  centroidRow = example.CentroidRow ();
93  numOfEdgePixels = example.NumOfEdgePixels ();
94  }
95 }
96 
97 
98 
100 {
101 }
102 
103 
104 
105 
106 GrayScaleImagesFVPtr GrayScaleImagesFV::Duplicate () const
107 {
108  return new GrayScaleImagesFV (*this);
109 }
110 
111 
112 
113 
114 
116  bool _owner
117  ):
118 
119  FeatureVectorList (_fileDesc, _owner)
120 {
121 
122 }
123 
124 
125 
126 
127 GrayScaleImagesFVList::GrayScaleImagesFVList (FactoryFVProducerPtr _fvProducerFactory,
128  MLClassPtr _mlClass,
129  KKStr _dirName,
130  KKStr _fileName,
131  RunLog& _log
132  ):
133 
134  FeatureVectorList (_fvProducerFactory->FileDesc (), true)
135 
136 {
137  FeatureExtraction (_fvProducerFactory, _dirName, _fileName, _mlClass, _log);
138 }
139 
140 
141 
142 
143 GrayScaleImagesFVList::GrayScaleImagesFVList (const GrayScaleImagesFVList& examples):
144  FeatureVectorList (examples.FileDesc (), examples.Owner ())
145 {
146  const_iterator idx;
147  for (idx = examples.begin (); idx != examples.end (); idx++)
148  {
149  const GrayScaleImagesFVPtr imageExample = *idx;
150  if (Owner ())
151  PushOnBack (new GrayScaleImagesFV (*imageExample));
152  else
153  PushOnBack (imageExample);
154  }
155 }
156 
157 
158 
159 
161  bool _owner
162  ):
163 
165 {
166  const_iterator idx;
167  for (idx = examples.begin (); idx != examples.end (); idx++)
168  {
169  const GrayScaleImagesFVPtr imageExample = *idx;
170  if (Owner ())
171  PushOnBack (new GrayScaleImagesFV (*imageExample));
172  else
173  PushOnBack (imageExample);
174  }
175 }
176 
177 
179  bool _owner
180  ):
181 
182  FeatureVectorList (featureVectorList.FileDesc (),
183  _owner
184  )
185 {
186  //if (strcmp (featureVectorList.UnderlyingClass (), "GrayScaleImagesFVList") == 0)
187  if (typeid (featureVectorList) == typeid (GrayScaleImagesFVList))
188  {
189  const GrayScaleImagesFVList& examples = dynamic_cast<const GrayScaleImagesFVList&> (featureVectorList);
190  }
191 
192 
193  if (_owner)
194  {
195  FeatureVectorList::const_iterator idx;
196  for (idx = featureVectorList.begin (); idx != featureVectorList.end (); idx++)
197  {
198  FeatureVectorPtr featureVector = *idx;
199 
200  // The constructor below will detect what the underlying type of 'featureVector' is.
201  // If (underlying type is a 'GrayScaleImagesFV' object) then
202  // | Information that is particular to a 'GrayScaleImagesFV' object will be extracted
203  // | from the 'FeatureVector' object being passed in.
204  // else
205  // | info that is particular to a 'GrayScaleImagesFV' object will be set to
206  // | default values.
207  GrayScaleImagesFVPtr example = new GrayScaleImagesFV (*featureVector);
208  PushOnBack (example);
209  }
210  }
211  else
212  {
213  // Since we will not own the contents but just point to an existing instances we will
214  // have to make sure that the existing instances of 'FeatureVector' objects have a
215  // underlying type of 'GrayScaleImagesFV'.
216  FeatureVectorList::const_iterator idx;
217  for (idx = featureVectorList.begin (); idx != featureVectorList.end (); idx++)
218  {
219  FeatureVectorPtr featureVector = *idx;
220  //if (strcmp (featureVector->UnderlyingClass (), "GrayScaleImagesFV") == 0)
221  if (typeid (*featureVector) == typeid (GrayScaleImagesFV))
222  {
223  GrayScaleImagesFVPtr example = dynamic_cast<GrayScaleImagesFVPtr>(featureVector);
224  PushOnBack (example);
225  }
226  else
227  {
228  // **** ERROR ****
229  KKStr errMSsg = "GrayScaleImagesFVList One of the elements in 'featureVectorList' is not of 'GrayScaleImagesFV' type.";
230  cerr << endl
231  << "GrayScaleImagesFVList::GrayScaleImagesFVList (const FeatureVectorList& featureVectorList) ***ERROR***" << endl
232  << " " << errMSsg << endl
233  << " FileName[" << featureVector->ExampleFileName () << "]" << endl
234  << endl;
235  throw KKException (errMSsg);
236  }
237  }
238  }
239 }
240 
241 
242 
243 
244 
245 
246 
247 
248 
249 //****************************************************************************
250 //* Will Create a list of examples that are a subset of the ones in _examples. *
251 //* The subset will consist of the examples who's mlClass is one of the *
252 //* ones in mlClasses. *
253 //****************************************************************************
255  GrayScaleImagesFVList& _examples
256  ):
258 
259 {
260 }
261 
262 
263 
264 
268  )
269 {
270  //if (strcmp (featureVectorList.UnderlyingClass (), "GrayScaleImagesFVList") == 0)
271  if (typeid (featureVectorList) == typeid (GrayScaleImagesFVList))
272  {
273  const GrayScaleImagesFVList& examples = dynamic_cast<const GrayScaleImagesFVList&> (featureVectorList);
274  }
275 
276 
277  if (featureVectorList.Owner ())
278  {
279  FeatureVectorList::const_iterator idx;
280  for (idx = featureVectorList.begin (); idx != featureVectorList.end (); idx++)
281  {
282  FeatureVectorPtr featureVector = *idx;
283 
284  // The constructor below will detect what the underlying type of 'featureVector' is.
285  // If (underlying type is a 'GrayScaleImagesFV' object) then
286  // | Information that is particular to a 'GrayScaleImagesFV' object will be extracted
287  // | from the 'FeatureVector' object being passed in.
288  // else
289  // | info that is particular to a 'GrayScaleImagesFV' object will be set to
290  // | default values.
291  GrayScaleImagesFVPtr example = new GrayScaleImagesFV (*featureVector);
292  PushOnBack (example);
293  }
294  }
295  else
296  {
297  // Since we will not own the contents but just point to existing instances we will
298  // have to make sure that the existing instances of 'FeatureVector' objects have a
299  // underlying type of 'GrayScaleImagesFV'.
300  FeatureVectorList::const_iterator idx;
301  for (idx = featureVectorList.begin (); idx != featureVectorList.end (); idx++)
302  {
303  FeatureVectorPtr featureVector = *idx;
304  //if (strcmp (featureVector->UnderlyingClass (), "GrayScaleImagesFV") == 0)
305  if (typeid (*featureVector) == typeid (GrayScaleImagesFV))
306  {
307  GrayScaleImagesFVPtr example = dynamic_cast<GrayScaleImagesFVPtr>(featureVector);
308  PushOnBack (example);
309  }
310  else
311  {
312  // **** ERROR ****
313  KKStr errMsg;
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 () << "]";
316 
317  cerr << endl << errMsg << endl << endl;
318  throw KKException (errMsg);
319  }
320  }
321  }
322 }
323 
324 
325 
326 
328 {
329 }
330 
331 
332 
333 GrayScaleImagesFVListPtr GrayScaleImagesFVList::Duplicate (bool _owner) const
334 {
335  return new GrayScaleImagesFVList (*this, _owner);
336 }
337 
338 
339 
340 
341 
342 GrayScaleImagesFVPtr GrayScaleImagesFVList::IdxToPtr (kkint32 idx) const
343 {
344  return (GrayScaleImagesFVPtr)FeatureVectorList::IdxToPtr (idx);
345 } /* IdxToPtr */
346 
347 
348 
349 
350 
351 GrayScaleImagesFVPtr GrayScaleImagesFVList::BackOfQueue ()
352 {
353  if (size () < 1)
354  return NULL;
355 
356  FeatureVectorPtr fv = back ();
357  //if (strcmp (fv->UnderlyingClass (), "GrayScaleImagesFV") == 0)
358  if (typeid (*fv) == typeid (GrayScaleImagesFV))
359  return dynamic_cast<GrayScaleImagesFVPtr> (fv);
360 
361  KKStr errMsg = "GrayScaleImagesFVList::BackOfQueue () ***ERROR*** Entry at back of Queue is not a 'GrayScaleImagesFV' object.";
362  cerr << endl << errMsg << endl << endl;
363  throw KKException (errMsg);
364 } /* BackOfQueue */
365 
366 
367 
368 
369 GrayScaleImagesFVPtr GrayScaleImagesFVList::PopFromBack ()
370 {
371  if (size () < 1) return NULL;
372 
373  FeatureVectorPtr fv = back ();
374  //if (strcmp (fv->UnderlyingClass (), "GrayScaleImagesFV") != 0)
375  if (typeid (*fv) == typeid (GrayScaleImagesFV))
376  {
377  KKStr errMsg = "GrayScaleImagesFVList::PopFromBack () ***ERROR*** Entry at back of Queue is not a 'GrayScaleImagesFV' object.";
378  cerr << endl << errMsg << endl << endl;
379  throw KKException (errMsg);
380  }
381 
382  return dynamic_cast<GrayScaleImagesFVPtr> (FeatureVectorList::PopFromBack ());
383 } /* PopFromBack */
384 
385 
386 
387 
388 
389 
391 {
392  FeatureVectorList::AddQueue (imagesToAdd);
393 } /* AddQueue */
394 
395 
396 
397 
398 
399 
400 GrayScaleImagesFVPtr GrayScaleImagesFVList::BinarySearchByName (const KKStr& _imageFileName) const
401 {
402  return (GrayScaleImagesFVPtr)FeatureVectorList::BinarySearchByName (_imageFileName);
403 } /* BinarySearchByName */
404 
405 
406 
407 
408 
409 GrayScaleImagesFVPtr GrayScaleImagesFVList::LookUpByRootName (const KKStr& _rootName)
410 {
411  return (GrayScaleImagesFVPtr)FeatureVectorList::LookUpByRootName (_rootName);
412 } /* LookUpByRootName */
413 
414 
415 
416 
417 
418 
419 GrayScaleImagesFVPtr GrayScaleImagesFVList::LookUpByImageFileName (const KKStr& _imageFileName) const
420 {
421  return (GrayScaleImagesFVPtr)FeatureVectorList::LookUpByImageFileName (_imageFileName);
422 } /* LookUpByImageFileName */
423 
424 
425 
426 
427 GrayScaleImagesFVListPtr GrayScaleImagesFVList::ManufactureEmptyList (bool _owner) const
428 {
429  return new GrayScaleImagesFVList (FileDesc (), _owner);
430 }
431 
432 
433 
434 
435 GrayScaleImagesFVListPtr GrayScaleImagesFVList::OrderUsingNamesFromAFile (const KKStr& fileName,
436  RunLog& log
437  )
438 {
439  FeatureVectorListPtr examples = FeatureVectorList::OrderUsingNamesFromAFile (fileName, log);
440  examples->Owner (false);
441  GrayScaleImagesFVListPtr orderedImages = new GrayScaleImagesFVList (*examples);
442  delete examples;
443  return orderedImages;
444 } /* OrderUsingNamesFromAFile */
445 
446 
447 
448 
449 
450 
451 void GrayScaleImagesFVList::FeatureExtraction (FactoryFVProducerPtr _fvProducerFactory,
452  KKStr _dirName,
453  KKStr _fileName,
454  MLClassPtr _mlClass,
455  RunLog& _log
456  )
457 {
458  KKStr className = _mlClass->Name ();
459  _log.Level (10) << "FeatureExtraction, dirName [" << _dirName << "]." << endl;
460  _log.Level (10) << " fileName [" << _fileName << "]." << endl;
461  _log.Level (10) << " className [" << className << "]." << endl;
462 
463  bool cancelFlag = false;
464  bool successful = false;
465 
466  if (_dirName.LastChar () != DSchar)
467  _dirName << DS;
468 
469  KKStr fullFeatureFileName (_dirName);
470  fullFeatureFileName << _fileName;
471 
472  KKStrListPtr fileNameList;
473 
474  KKStr fileSpec (_dirName);
475  fileSpec << "*.*";
476 
477  fileNameList = osGetListOfFiles (fileSpec);
478  if (!fileNameList)
479  return;
480 
481  FeatureVectorProducerPtr fvProducer = _fvProducerFactory->ManufactureInstance (_log);
482 
483  KKStrList::iterator fnIDX = fileNameList->begin ();
484 
485  KKStrPtr imageFileName = NULL;
486 
487  kkint32 numOfImages = fileNameList->QueueSize ();
488  kkint32 count = 0;
489 
490  for (fnIDX = fileNameList->begin (); fnIDX != fileNameList->end (); ++fnIDX)
491  {
492  if ((count % 100) == 0)
493  cout << className << " " << count << " of " << numOfImages << endl;
494 
495  imageFileName = *fnIDX;
496 
497  bool validImageFileFormat = SupportedImageFileFormat (*imageFileName);
498 
499  if (!validImageFileFormat)
500  continue;
501 
502  KKStr fullFileName = osAddSlash (_dirName) + (*imageFileName);
503 
504  FeatureVectorPtr featureVector = fvProducer->ComputeFeatureVectorFromImage (fullFileName, _mlClass, NULL, _log);
505  if (!featureVector)
506  {
507  KKStr msg (100);
508  msg << "GrayScaleImagesFVList::FeatureExtraction ***ERROR*** Could not Allocate GrayScaleImagesFV object" << endl
509  << "for FileName[" << fullFileName << "].";
510  _log.Level (-1) << endl << msg << endl << endl;
511  }
512  else
513  {
514  GrayScaleImagesFVPtr larcosFeatureVector = NULL;
515  if (typeid(*featureVector) == typeid(GrayScaleImagesFV))
516  {
517  larcosFeatureVector = dynamic_cast<GrayScaleImagesFVPtr>(featureVector);
518  featureVector = NULL;
519  }
520  else
521  {
522  larcosFeatureVector = new GrayScaleImagesFV (*featureVector);
523  delete featureVector;
524  featureVector = NULL;
525  }
526 
527  larcosFeatureVector->ExampleFileName (*imageFileName);
528  _log.Level (30) << larcosFeatureVector->ExampleFileName () << " " << larcosFeatureVector->OrigSize () << endl;
529  PushOnBack (larcosFeatureVector);
530  count++;
531  }
532  }
533 
534  Version (fvProducer->Version ());
535 
536  delete fvProducer; fvProducer = NULL;
537 
538 
539  kkuint32 numExamplesWritten = 0;
540 
541  // WriteImageFeaturesToFile (fullFeatureFileName, RawFormat, FeatureNumList::AllFeatures (fileDesc));
542  FeatureFileIOC45::Driver ()->SaveFeatureFile (fullFeatureFileName,
543  FeatureNumList::AllFeatures (FileDesc ()),
544  *this,
545  numExamplesWritten,
546  cancelFlag,
547  successful,
548  _log
549  );
550  delete fileNameList;
551  fileNameList = NULL;
552 } /* FeatureExtraction */
553 
554 
555 
556 
557 
558 
559 /**
560  * @brief Creates a duplicate of list and also duplicates it contents.
561  * @return Duplicated list with hard copy of its contents.
562  */
563 GrayScaleImagesFVListPtr GrayScaleImagesFVList::DuplicateListAndContents () const
564 {
565  GrayScaleImagesFVListPtr copyiedList = new GrayScaleImagesFVList (FileDesc (), true);
566 
567  for (kkint32 idx = 0; idx < QueueSize (); idx++)
568  {
569  GrayScaleImagesFVPtr curImage = (GrayScaleImagesFVPtr)IdxToPtr (idx);
570  copyiedList->PushOnBack (new GrayScaleImagesFV (*curImage));
571  }
572 
573  copyiedList->Version (Version ());
574 
575  return copyiedList;
576 } /* DuplicateListAndContents */
577 
578 
579 
580 
581 
582 
583 void GrayScaleImagesFVList::RecalcFeatureValuesFromImagesInDirTree (FactoryFVProducerPtr fvProducerFactory,
584  const KKStr& rootDir,
585  bool& successful,
586  RunLog& log
587  )
588 {
589  log.Level (20) << "RecalcFeatureValuesFromImagesInDirTree RootDir[" << rootDir << "]." << endl;
590 
591  successful = false;
592 
593  ImageDirTree fileDirectory (rootDir);
594 
595  if (QueueSize () < 1)
596  {
597  successful = true;
598  return;
599  }
600 
601  if (fileDirectory.Size () < 1)
602  {
603  log.Level (10) << "RecalcFeatureValuesFromImagesInDirTree No Image Files in[" << rootDir << "]" << endl;
604  return;
605  }
606 
607  FeatureVectorProducerPtr fvProducer = fvProducerFactory->ManufactureInstance (log);
608 
609  KKStrConstPtr dirPath = NULL;
610 
611  iterator idx;
612  GrayScaleImagesFVPtr example = NULL;
613 
614  for (idx = begin (); idx != end (); idx++)
615  {
616  example = *idx;
617  dirPath = fileDirectory.LocateImage (example->ExampleFileName ());
618  if (!dirPath)
619  {
620  log.Level (10) << "RecalcFeatureValuesFromImagesInDirTree Could not locate Image[" << example->ExampleFileName () << "] in Subdirectory Tree." << endl;
621  return;
622  }
623 
624  KKStr fullFileName (*dirPath);
625  osAddLastSlash (fullFileName);
626  fullFileName << example->ExampleFileName ();
627 
628  bool validFile;
629  RasterPtr raster = new Raster (fullFileName, validFile);
630  if (!validFile)
631  {
632  delete raster; raster = NULL;
633  log.Level (-1) << "GrayScaleImagesFVList::RecalcFeatureValuesFromImagesInDirTree ***ERROR*** Unable to load image: " << fullFileName << endl << endl;
634  }
635  else
636  {
637  FeatureVectorPtr fv = fvProducer->ComputeFeatureVector (*raster, example->MLClass (), NULL, 1.0f, log);
638  if (fv)
639  {
640  kkint32 x;
641  kkint32 featureCount = Min (fv->NumOfFeatures (), example->NumOfFeatures ());
642  for (x = 0; x < featureCount; ++x)
643  example->FeatureData (x, fv->FeatureData (x));
644 
645  example->OrigSize (fv->OrigSize ());
646  example->Version (fv->Version ());
647 
648  if (typeid(*fv) == typeid(GrayScaleImagesFV))
649  {
650  GrayScaleImagesFVPtr lfv = dynamic_cast<GrayScaleImagesFVPtr>(fv);
651  example->CentroidCol (lfv->CentroidCol ());
652  example->CentroidRow (lfv->CentroidRow ());
654  }
655 
656  delete fv;
657  fv = NULL;
658  }
659  delete raster; raster = NULL;
660  }
661  }
662 
663  delete fvProducer;
664  fvProducer = NULL;
665 } /* RecalcFeatureValuesFromImagesInDirTree */
666 
667 
668 
669 
670 
672 {
673  FeatureVectorListPtr duplicateFeatureVectorObjects = FeatureVectorList::ExtractDuplicatesByRootImageFileName ();
674  GrayScaleImagesFVListPtr duplicateImageFeaturesObjects = new GrayScaleImagesFVList (*duplicateFeatureVectorObjects);
675  duplicateFeatureVectorObjects->Owner (false);
676  delete duplicateFeatureVectorObjects; duplicateFeatureVectorObjects = NULL;
677  return duplicateImageFeaturesObjects;
678 } /* ExtractDuplicatesByRootImageFileName */
679 
680 
681 
682 
683 
684 
686  kkint32 _maxToExtract,
687  float _minSize
688  ) const
689 {
690  FeatureVectorListPtr featureVectorList = FeatureVectorList::ExtractExamplesForAGivenClass (_mlClass, _maxToExtract, _minSize);
691  GrayScaleImagesFVListPtr imageFeaturesList = new GrayScaleImagesFVList (*featureVectorList);
692  featureVectorList->Owner (false);
693  delete featureVectorList; featureVectorList = NULL;
694  return imageFeaturesList;
695 } /* ExtractExamplesForAGivenClass */
696 
697 
698 
699 
700 
701 GrayScaleImagesFVListPtr GrayScaleImagesFVList::StratifyAmoungstClasses (MLClassListPtr mlClasses,
702  kkint32 maxImagesPerClass,
703  kkint32 numOfFolds,
704  RunLog& log
705  )
706 {
707  FeatureVectorListPtr stratifiedFeatureVectors = FeatureVectorList::StratifyAmoungstClasses (mlClasses, maxImagesPerClass, numOfFolds, log);
708  GrayScaleImagesFVListPtr stratifiedImagefeatures = new GrayScaleImagesFVList (*stratifiedFeatureVectors);
709  stratifiedFeatureVectors->Owner (false);
710  delete stratifiedFeatureVectors; stratifiedFeatureVectors = NULL;
711  return stratifiedImagefeatures;
712 } /* StratifyAmoungstClasses */
713 
714 
715 
716 
717 GrayScaleImagesFVListPtr GrayScaleImagesFVList::StratifyAmoungstClasses (kkint32 numOfFolds,
718  RunLog& log
719  )
720 {
721  MLClassListPtr classes = ExtractListOfClasses ();
722 
723  FeatureVectorListPtr stratifiedFeatureVectors = FeatureVectorList::StratifyAmoungstClasses (classes, -1, numOfFolds, log);
724  GrayScaleImagesFVListPtr stratifiedImagefeatures = new GrayScaleImagesFVList (*stratifiedFeatureVectors);
725 
726  stratifiedFeatureVectors->Owner (false);
727 
728  delete stratifiedFeatureVectors; stratifiedFeatureVectors = NULL;
729  delete classes; classes = NULL;
730 
731  return stratifiedImagefeatures;
732 } /* StratifyAmoungstClasses */
GrayScaleImagesFV(const GrayScaleImagesFV &_fv)
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for &#39;size&#39; characters.
Definition: KKStr.cpp:655
void ExampleFileName(const KKStr &_exampleFileName)
Name of source of feature vector, ex: file name of image that the feature vector was computed from...
Definition: FeatureVector.h:75
GrayScaleImagesFVList(FileDescPtr _fileDesc, bool _owner)
kkuint32 Size()
returns the number of image files found the sub-directory tree.
Definition: ImageDirTree.h:43
MLClass * MLClassPtr
Definition: MLClass.h:46
GrayScaleImagesFVListPtr StratifyAmoungstClasses(kkint32 numOfFolds, RunLog &log)
Raster * RasterPtr
Definition: BMPImage.h:25
GrayScaleImagesFVListPtr ExtractDuplicatesByRootImageFileName()
__int32 kkint32
Definition: KKBaseTypes.h:88
GrayScaleImagesFVList(const FeatureVectorList &featureVectorList, bool _owner)
Creates a duplicate List of examples, in the same order, and depending on &#39;_owner&#39; 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.
Definition: Raster.cpp:622
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.
Definition: Raster.h:108
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 &#39;_owner&#39; will create new in...
Creates a index of all images in a specified directory structure.
Definition: ImageDirTree.h:22
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)
Definition: ImageIO.cpp:948
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
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&#39;s.
#define DS
Definition: OSservices.h:505
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)
char LastChar() const
Definition: KKStr.cpp:2007
KKTHread * KKTHreadPtr
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...
kkint16 Version() const
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.
Definition: KKStr.cpp:561
virtual FeatureVectorProducerPtr ManufactureInstance(RunLog &runLog)=0
Derived classes will instantiate appropriate instances of &#39;FeatureVectorProducer&#39;.
void CentroidCol(float _centroidCol)
KKStrConstPtr LocateImage(const KKStr &fileName)
Locate image specified by &#39;fileName&#39; and return the directory where it is located.
GrayScaleImagesFVPtr BackOfQueue()
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
virtual FeatureVectorPtr ComputeFeatureVector(const Raster &image, const MLClassPtr knownClass, RasterListPtr intermediateImages, float priorReductionFactor, RunLog &runLog)=0
Compute a FeatureVector for the supplied &#39;image&#39;.
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 &#39;fileName&#39;.
MLClassPtr MLClass() const
Class that is example is assigned to.
void NumOfEdgePixels(kkint32 _numOfEdgePixels)
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(&#39;fileName&#39;) create a new GrayScaleImagesFVList instance with e...
const KKStr & Name() const
Definition: MLClass.h:154
KKStr operator+(const KKStr &right) const
Definition: KKStr.cpp:3998
void Version(kkint16 _version)
Definition: FeatureVector.h:80
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.
Definition: FeatureVector.h:77
Used for logging messages.
Definition: RunLog.h:49
void EncodeProblem(const struct svm_paramater &param, struct svm_problem &prob_in, struct svm_problem &prob_out)
MLClassList * MLClassListPtr
Definition: MLClass.h:49
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)
Definition: KKException.cpp:45
Maintains a list of MLClass instances.
Definition: MLClass.h:233
#define DSchar
Definition: OSservices.h:506
Represents a Feature Vector of a single example, labeled or unlabeled.
Definition: FeatureVector.h:59
virtual FileDescPtr FileDesc() const =0
GrayScaleImagesFVPtr IdxToPtr(kkint32 idx) const
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)