Blame view

stim/cuda/bsds500/textons.cuh 2.47 KB
018b00d6   David Mayerich   adapted bsds500 f...
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  #ifndef STIM_CUDA_TEXONS_CUH
  #define STIM_CUDA_TEXONS_CUH
  
  #include <stim/image/image.h>
  //#include <cmath>
  #include <stim/visualization/colormap.h>
  //#include <stim/image/image_contour_detection.h>
  #include <sstream>
  
  /// 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<float> textons(stim::image<float> 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<float> textons(w, h, 1, theta_n*2+1);    // allocate space for textons
  	stim::image<float> temp(w, h);						 // allocate space for temp
  
  	int sigma = 1;     // set sigma for odd-symmetric, even-symmetric and center-surround filter 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 = dG1_theta_conv2(image, sigma, theta);     // return dG1_theta_conv2 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 = dG2_d2x_theta_conv2(image, sigma, theta);  // return dG2_d2x_theta_conv2 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 = laplacian_conv2(image, sigma);  // return laplacian_conv2 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;
  
  }
  
  #endif