MachineIntelligenceCore:Algorithms
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
IBMFontMatrixImporter.cpp
Go to the documentation of this file.
1 
24 
25 #include <importers/IBMFonts.hpp>
26 
27 namespace mic {
28 namespace importers {
29 
30 IBMFontMatrixImporter::IBMFontMatrixImporter(std::string node_name_) : Importer (node_name_),
31  font_type("font_type",font16x16_type)
32 {
33  // Register properties - so their values can be overridden (read from the configuration file).
34  registerProperty(font_type);
35 }
36 
38 
39  LOG(LSTATUS) << "Importing IBM VGA fonts of size " << ( font_type == font8x8_type ? "8x8" : "16x16");
40 
41  // Select adequate font table.
42 // const uint8_t* font_table = ( font_type == font8x8_type ? font8x8_table : font16x16_table );
43 
44 // const uint16_t* mask = ( font_type == font8x8_type ? mask8x8 : mask16x16 );
45 
46  // "Load font dataset with labels.
47  for(size_t i=1; i < 94; i++ ) {
48 
49  // Create new matrix of size font_type x font_type (8x8 v 16x16).
50  mic::types::MatrixXfPtr mat (new mic::types::MatrixXf((int)font_type, (int)font_type));
51 
52  if (font_type == font8x8_type) {
53  // Generate 8x8 characters - font_type = 8.
54 
55  for (size_t r = 0; r < 8; r++) {
56  // Get line.
57  uint8_t line = font8x8_table[8*i+r];
58  // Iterate through characters in given line.
59  for (size_t c = 0; c < 8; c++) {
60  (*mat)(r, c) = ((line & mask8x8[8-c]) != 0);
61  }//: for
62  }//: for
63  } else {
64  // Generate 16x16 characters - font_type = 16.
65 
66  for (size_t r = 0; r < 16; r++) {
67  uint16_t line = ((uint16_t*)font16x16_table)[16 *i+r];
68  for (size_t c = 0; c < 16; c++) {
69  (*mat)(r, c) = ((line & mask16x16[c]) != 0);
70  }//: for
71  }//: for
72 
73  }//: else
74 
75  // Add character and label to vectors.
76  sample_data.push_back(mat);
77  sample_labels.push_back(std::make_shared <char> (font_labels_table[i]) );
78 
79  }//: for
80  LOG(LINFO) << "Imported " << sample_data.size() << " fonts";
81 
82  // Fill the indices table(!)
83  for (size_t i=0; i < sample_data.size(); i++ )
84  sample_indices.push_back(i);
85 
86  // Count the classes.
87  countClasses();
88 
89  LOG(LINFO) << "Data import finished";
90 
91  return true;
92 }
93 
94 
95 } /* namespace importers */
96 } /* namespace mic */
Contains declaration of an importer responsible for importing/loading characters from IBM VGA font da...
std::shared_ptr< mic::types::MatrixXf > MatrixXfPtr
Shared pointer to matrix with single precision floats (of dynamic size).
std::vector< size_t > sample_indices
Stores sample indices (sample "positions" in original dataset).
Definition: Batch.hpp:460
mic::configuration::Property< IBMfont_t > font_type
const uint8_t font16x16_table[]
Table containing 8x8 characters. Originally created by Marcel Sondaar (IBM - VGA fonts).
Definition: IBMFonts.hpp:139
Parent class for all data importers.
Definition: Importer.hpp:51
std::vector< std::shared_ptr< mic::types::MatrixXf > > sample_data
Stores the data.
Definition: Batch.hpp:454
const char font_labels_table[]
Table encodng for labels (chars).
Definition: IBMFonts.hpp:256
const uint8_t font8x8_table[]
Table containing 8x8 characters. Originally created by Marcel Sondaar (IBM - VGA fonts).
Definition: IBMFonts.hpp:36
IBMFontMatrixImporter(std::string node_name_="ibm_font_matrix_importer")
Loads characters of size 16x16.
Contains characters bitmaps, originally created by Marcel Sondaar (IBM - VGA fonts).
std::vector< std::shared_ptr< char > > sample_labels
Stores labels.
Definition: Batch.hpp:457
const uint16_t mask8x8[]
Mask used during encoding of 8x8 characters.
Definition: IBMFonts.hpp:242
Loads characters of size 8x8.
Template-typed Matrix of dynamic size. Uses OpenBLAS if found by CMAKE - overloaded, specializations of * operator for types: float, double.
Definition: Matrix.hpp:64
const uint16_t mask16x16[]
Mask used during encoding of 8x8 characters.
Definition: IBMFonts.hpp:249