-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageReaderUCI.cpp
43 lines (41 loc) · 1.31 KB
/
ImageReaderUCI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "ImageReaderUCI.hpp"
#include <sstream>
#include <string>
//ImageReaderUCI::ImageReaderUCI(){}
void ImageReaderUCI::readData(ifstream& inputImageFile, ifstream& inputLabelFile){
string line;
int tempLabel;
int lineCounter = 0;
int nImages = 0;
while (getline(inputImageFile, line)){
lineCounter ++;
if (lineCounter < DATASTARTLINE){
istringstream iss(line);
if (line.find("ndigit = ") != string::npos){
string tmp1, tmp2;
iss >> tmp1 >> tmp2 >> nImages;
images.resize(nImages);
}
continue;
}
if ((lineCounter - DATASTARTLINE + 1) % (SIZE+1) == 0){
istringstream iss(line);
iss >> tempLabel;
labels.push_back(tempLabel);
continue;
}
int imageNo = (lineCounter - DATASTARTLINE)/(SIZE + 1);
int row = (lineCounter - DATASTARTLINE) % (SIZE+1);
if (images[imageNo].size() == 0) images[imageNo].resize(SIZE);
images[imageNo][row].resize(SIZE);
for (int i=0; i < SIZE; ++i){
images[imageNo][row][i] = ((int) line[i]) - 48;
}
}
}
vector<vector<vector<int>>>& ImageReaderUCI::getImages(){
return images;
}
vector<int>& ImageReaderUCI::getLabels(){
return labels;
}