Lda train with images, reshaped(1,1) and integers labels.
1 | initial version |
Lda train with images, reshaped(1,1) and integers labels.
Lda train with images, reshaped(1,1) and integers labels.
vector<Mat> train_vect;
Mat labels;
Mat test, test_label;
vector<Mat> test_vect;
int SI = 60;
for (int i = 1; i <= 4; i++) {
String name = names[0];
string file_name = name + to_string(i) + ".pgm";
Mat img = imread("test_images\\" + file_name, CV_LOAD_IMAGE_GRAYSCALE);
resize(img, img, Size(SI, SI));
img.convertTo(img, CV_32FC1);
vector<Mat> fusion = get_layers_fusion(img);
if (i < 3) {
for (Mat cur : fusion) train_vect.push_back(cur), labels.push_back(1);
}
else {
for (Mat cur : fusion) test_vect.push_back(cur), test_label.push_back(1);
}
}
for (int i = 1; i <= 4; i++) {
String name = names[1];
string file_name = name + to_string(i) + ".pgm";
Mat img = imread("test_images\\" + file_name, CV_LOAD_IMAGE_GRAYSCALE);
resize(img, img, Size(SI, SI));
img.convertTo(img, CV_32FC1);
vector<Mat> fusion = get_layers_fusion(img);
if (i < 3) {
for (Mat cur : fusion) train_vect.push_back(cur), labels.push_back(2);
}
else {
for (Mat cur : fusion) test_vect.push_back(cur), test_label.push_back(2);
}
}
for (int i = 0; i < train_vect.size(); i++) { train.push_back(train_vect[i].reshape(1, 1)); } for (int i = 0; i < test_vect.size(); i++) { test.push_back(test_vect[i].reshape(1, 1)); } LDA lda(train, labels , 2);
cout << "fin compute " << endl;
Mat project_train = lda.project(train);
Mat test_projection = lda.project(test);
cout << "project_Train " << project_train << endl;
cout << "prject_test " << test_projection << endl;