#include //#include #include #include #include /// This function convolve the grayscale image with a set of oriented Gaussian /// derivative filters, and return a texton image with (theta_n*2+1) channels /// @param image is an one-channel grayscale image /// @param theta_n is the number of angles used for computing the gradient stim::image textons(stim::image image, unsigned int theta_n){ unsigned int w = image.width(); // get the width of picture unsigned int h = image.height(); // get the height of picture unsigned N = w * h; // get the number of pixels of picture stim::image textons(w, h, 1, theta_n*2+1); // allocate space for textons stim::image temp(w, h); // allocate space for temp unsigned int r_odd = 3; // set disc radii for odd-symmetric filter unsigned int sigma_n_odd = 3; // set sigma_n for odd-symmetric filter unsigned int r_even = 3; // set disc radii for even-symmetric filter unsigned int sigma_n_even = 3; // set sigma_n for even-symmetric filter unsigned int r_center = 3; // set disc radii for center-surround filter unsigned int sigma_n_center = 3; // set sigma_n for center-surround filter //std::ostringstream ss1, ss2; // (optional) set the stream to designate the test result file for (unsigned int i = 0; i < theta_n; i++){ //ss1 << "data_output/textons_channel_"<< i << ".bmp"; // set the name for test result file (optional) //std::string sss1 = ss1.str(); //ss2 << "data_output/textons_channel_"<< i+theta_n << ".bmp"; // set the name for test result file (optional) //std::string sss2 = ss2.str(); float theta = 180 * ((float)i/theta_n); // calculate the even-splited angle for each oriented filter temp = Gd_odd(image, r_odd, sigma_n_odd, theta); // return Gd_odd to temp //stim::cpu2image(temp.data(), sss1, w, h, stim::cmBrewer); textons.set_channel(i, temp.data()); // copy temp to ith channel of textons temp = Gd_even(image, r_even, sigma_n_even, theta); // return Gd_even to temp //stim::cpu2image(temp.data(), sss2, w, h, stim::cmBrewer); textons.set_channel(i + theta_n, temp.data()); // copy temp to (i+theta_n)th channel of textons //ss1.str(""); //(optional) clear the space for stream //ss2.str(""); //(optional) clear the space for stream } temp = Gd_center(image, r_center, sigma_n_center); // return Gd_center to temp //stim::cpu2image(temp.data(), "data_output/textons_channel_16.bmp", w, h, stim::cmBrewer); textons.set_channel(theta_n*2, temp.data()); // copy temp to (theta_n*2)th channel of textons return textons; }