Blame view

stim/cuda/bsds500/cPb.cpp 2.35 KB
91d8912e   David Mayerich   moved bsds500 fil...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include <stim/image/image.h>
  #include <cmath>
  #include <stim/visualization/colormap.h>
  #include <stim/image/image_contour_detection.h>
  #include <sstream>
  
  
  void array_multiply(float* lhs, float rhs, unsigned int N);
  void array_add(float* ptr1, float* ptr2, float* sum, unsigned int N);
  
  /// This function evaluates the cPb given an multi-channel image
  
  /// @param img is the multi-channel image
  /// @param r is an array of radii for different scaled discs(filters)
  /// @param alpha is is an array of weights for different scaled discs(filters)
  /// @param s is the number of scales
  
afb1883d   Tianshu Cheng   fixed problem abo...
18
  stim::image<float> cPb(stim::image<float> img, int* sigma, float* alpha, int s){
91d8912e   David Mayerich   moved bsds500 fil...
19
20
21
22
23
24
25
26
27
28
29
30
  
  	unsigned int w = img.width();              // get the width of picture
  	unsigned int h = img.height();             // get the height of picture
  	unsigned int c = img.channels();		   // get the channels of picture
  
  
  	stim::image<float> cPb(w, h, 1);               // allocate space for cPb
  	unsigned size = cPb.size();                    // get the size of cPb
  	memset ( cPb.data(), 0, size * sizeof(float)); // initialize all the pixels of cPb to 0
  
  
  	unsigned int N = w * h;						// get the number of pixels
91d8912e   David Mayerich   moved bsds500 fil...
31
  
afb1883d   Tianshu Cheng   fixed problem abo...
32
  	//std::ostringstream ss;                      // (optional) set the stream to designate the test result file
91d8912e   David Mayerich   moved bsds500 fil...
33
34
35
36
37
38
  
  	stim::image<float> temp;                    // set the temporary image to store the addtion result
  
  	for (int i = 0; i < c; i++){
  		for (int j = 0; j < s; j++){
  
afb1883d   Tianshu Cheng   fixed problem abo...
39
40
  			//ss << "data_output/cPb_slice"<< i*s + j << ".bmp";  // set the name for test result file (optional)
  			//std::string sss = ss.str();
91d8912e   David Mayerich   moved bsds500 fil...
41
42
  		    
  			// get the gaussian gradient by convolving each image slice with the mask
afb1883d   Tianshu Cheng   fixed problem abo...
43
  			temp = Pb(img.channel(i), sigma[i*s + j]);
91d8912e   David Mayerich   moved bsds500 fil...
44
45
46
47
48
49
50
51
52
53
  
  			// output the test result of each slice (optional) 
  			//stim::cpu2image(temp.data(), sss, w, h, stim::cmBrewer);
  
  			// multiply each gaussian gradient with its weight
  			array_multiply(temp.data(), alpha[i*s + j], N);
  
  			// add up all the weighted gaussian gradients
  			array_add(cPb.data(), temp.data(), cPb.data(), N);
  
afb1883d   Tianshu Cheng   fixed problem abo...
54
  			//ss.str("");   //(optional) clear the space for stream
91d8912e   David Mayerich   moved bsds500 fil...
55
56
57
58
59
60
61
62
63
64
65
66
  
  		}	
  	}
  
  	float max = cPb.maxv();						// get the maximum of cPb used for normalization
  	array_multiply(cPb.data(), 1/max, N);		    // normalize the cPb
  
  	// output the test result of cPb (optional) 
  	//stim::cpu2image(cPb.data(),  "data_output/cPb_0916.bmp", w, h, stim::cmBrewer);
  
  	return cPb;
  }