Blame view

func_mPb.cpp 3.17 KB
b71cc8bb   Tianshu Cheng   mPb using 3 channels
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <stim/image/image.h>
  #include <cmath>
  #include <conio.h>
  #include <stim/visualization/colormap.h>
  #include <stim/image/image_contour_detection.h>
  #include <sstream>
  
  stim::image<float> func_mPb(stim::image<float> lab, unsigned int theta_n, unsigned int w, unsigned int h){
  
  	std::clock_t start;
  	start = std::clock();
  
  	//---------------pavel's suggesiton------------------------------------
  	std::ostringstream ss;
  	unsigned int N = w * h;
  	stim::image<float> mPb_theta(w,h), mPb(w,h);
  	unsigned size = mPb_theta.size();
  	memset ( mPb.data(), 0, size * sizeof(float));
  
  	float* ptr;
  	ptr = (float*) malloc(size * sizeof(float) * theta_n);
  
40d11588   Tianshu Cheng   2D inseparable co...
23
  	for (unsigned int n = 0; n < theta_n; n++){
b71cc8bb   Tianshu Cheng   mPb using 3 channels
24
  	
40d11588   Tianshu Cheng   2D inseparable co...
25
  		ss << "data_output/mPb_theta"<< n << "_conv2.bmp";
b71cc8bb   Tianshu Cheng   mPb using 3 channels
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  		float theta = 180 * ((float)n/theta_n); 
  
  		mPb_theta = func_mPb_theta(lab, theta, w, h);
  		//mPb_theta.load("101087.bmp");
  		float* ptr_n = &ptr[ n * w * h * 1 ];
  		mPb_theta.channel(0).data_noninterleaved(ptr_n);
  
  		double duration1 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  		std::cout<<"mPb_theta_"<< theta <<" complished   time:"<< duration1 <<"s"<<'\n';
  
  
  		unsigned long idx = n * w * h * 1;  //index for the nth slice
  
  		std::string sss = ss.str();
40d11588   Tianshu Cheng   2D inseparable co...
40
  		//stim::cpu2image(&ptr[idx], sss, w, h, stim::cmBrewer);
b71cc8bb   Tianshu Cheng   mPb using 3 channels
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  	 
  
  		for(unsigned long i = 0; i < N; i++){
  		
  			float pixel = ptr[i+idx];           //get the ith pixel in nth slice
  
  			if(pixel > mPb.data()[i]){
  				mPb.data()[i] = pixel;
  			}
  			
  			else{
  			}
  		}
  
  		
  
  		ss.str("");
  	}              
  
40d11588   Tianshu Cheng   2D inseparable co...
60
  	//stim::cpu2image(mPb.data(), "data_output/mPb_conv2.bmp", w, h, stim::cmBrewer);
b71cc8bb   Tianshu Cheng   mPb using 3 channels
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
  
  	double duration2 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  	std::cout<<"total time:"<< duration2 <<"s"<<'\n';
  	
  	getch();
  
  	return mPb; 
  
  	//---------------my first method------------------------------------
  	/*
  	std::clock_t start;
  	start = std::clock();
  
  	stim::image<float> mPb_stack(w,h,theta_n), mPb(w,h), mPb_theta(w,h), A, B, temp;
  	float* ptr[8];
  
  	for (unsigned int n = 0; n < theta_n; n++){
  
  		//int* x = new int(5);
          //int* y = x;
  		//*y = 1;
  		
  		float theta = 180 * ((float)n/theta_n); 
  		mPb_theta = func_mPb_theta(lab, theta, w, h);
  		mPb_stack.getslice(n) = mPb_theta;
  		float* ptr[n] = mPb_stack.getslice(n).data();
  
  		double duration1 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  		std::cout<<"mPb_theta, theta = "<< theta <<" time:"<< duration1 <<"s"<<'\n';
  		
  
  		for(unsigned long i = 0; i < N; i++){
  
  			*(ptr[n]+i) = mPb_theta.data()[i];
  		
  	       
  			//float a = mPb_theta.data()[i];
  			//float* B = ptr[n]+i;
  			//A.data()[i] = mPb_theta.data()[i];
  			//float* C = ptr[0]+1;
  			//*C = 1;
  
  	//		
  		}
  		stim::cpu2image(ptr[0], "data_output/mPb_theta.bmp", w, h, stim::cmBrewer);
  	}
  
  	for (unsigned long i = 0; i < N; i++){
  		
  		mPb.data()[i] = 0;
  		for (unsigned int n = 0; n < theta_n; n++){
  
  			float* ptr2 = ptr[i]+n;
  			float temp = *ptr2;
  
  			if(temp > mPb.data()[i]){
  				mPb.data()[i] = temp;
  			}	
  			else{
  			}
  	    }
  	}                  
  
  	stim::cpu2image(mPb.data(), "data_output/cmap_mPb.bmp", w, h, stim::cmBrewer);
  
  	double duration2 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  	std::cout<<"total time:"<< duration2 <<"s"<<'\n';
  	
  	getch();
  
  	return mPb; */
  
  
  
  }