Fixed initialization using dictionary file.

parent 20b70700
......@@ -24,7 +24,7 @@ bool force_residual_mosaic = true;
const char* iname = "";
const char* mname = "";
const char* dname = "";
const char* dname = 0;
void list_choices(const char* prefix, const char* opts[]) {
size_t i = 0;
......@@ -79,7 +79,7 @@ void parse_args(int argc, char **argv) {
// dictionary can be initialized with a file name or with an algorithm,
// which is selected using a number from 0 to 9, as with the rest of the
// algorithms.
if (isalpha(val[0])) {
if (!isdigit(val[0])) {
dname = val;
mi_algo = -1;
} else {
......@@ -244,9 +244,6 @@ int main(int argc, char **argv) {
N = I.get_rows();
}
binary_matrix D(K,M);
binary_matrix A(N,K);
std::cout << "M=" << M << " N=" << N << " K=" << K << std::endl;
//
// set up different aspects of learning algorithm
// the overall algorithm delegates parts to other algorithms.
......@@ -255,27 +252,32 @@ int main(int argc, char **argv) {
//
// initialize model
//
binary_matrix D,A;
if (dname) {
fimg = fopen(dname,"r");
if (!dname) {
std::cerr << "Error opening dictionary file " << dname << std::endl;
return -1;
}
res = read_pbm_header(fimg,rows,cols);
std::cout << "rows=" << rows << " cols=" << cols << std::endl;
res = read_pbm_header(fimg,K,M);
//std::cout << "rows=" << K << " cols=" << M << std::endl;
// load a predefined dictionary
D.destroy();
D.allocate(rows,cols);
D.allocate(K,M);
A.allocate(N,K);
res = read_pbm_data(fimg,D);
if (res !=PBM_OK) {
std::cerr << "Error " << res << " reading dictionary." << std::endl;
std::exit(1);
}
fclose(fimg);
}
if (initialize_dictionary) {
} else {
D.allocate(K,M);
A.allocate(N,K);
initialize_dictionary(X,H,D,A);
}
std::cout << "M=" << M << " N=" << N << " K=" << K << std::endl;
write_pbm(D,"__initial_dict__.pbm");
if (image_mode || force_mosaic) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment