Commit 2558ee864cdfc8006acd39b94eb2ee76a221b9a8

Authored by Laila Saadatifard
1 parent ae4cb7e9

updating ivote3 to get input parameters in the arguments

Showing 2 changed files with 82 additions and 204 deletions   Show diff stats
cpp/cudafunc.cu
1   -/*#include "circle_check.cuh"
2   -
3   -void test_3(float* gpu_out, float* gpu_grad, float rmax, float phi, int n, int x, int y, int z){
4   -gpu_test3(gpu_out, gpu_grad, rmax, phi, n, x, y, z);
5   -}
6   -*/
7   -
8 1  
9 2 #include "gaussian_blur3.cuh"
10 3 #include "gradient3.cuh"
... ... @@ -14,7 +7,7 @@ gpu_test3(gpu_out, gpu_grad, rmax, phi, n, x, y, z);
14 7 #include "local_max3.cuh"
15 8  
16 9  
17   -void ivote3(float* img, float sigma[], float anisotropy, float phi, float d_phi, unsigned int r[],
  10 +void ivote3(float* img, float sigma[], float phi, float d_phi, unsigned int r[],
18 11 int iter, float t, unsigned int conn[], unsigned int x, unsigned int y, unsigned int z){
19 12  
20 13  
... ... @@ -33,7 +26,7 @@ void ivote3(float* img, float sigma[], float anisotropy, float phi, float d_phi,
33 26 float* gpu_grad; //assign memory on the gpu for the gradient along the X, y, z.
34 27 cudaMalloc(&gpu_grad, bytes*3);
35 28  
36   - gpu_gradient3<float>(gpu_grad, gpuI0, anisotropy, x, y, z); //call the gradient function from the gpu.
  29 + gpu_gradient3<float>(gpu_grad, gpuI0, 1, x, y, z); //call the gradient function from the gpu.
37 30 cudaFree(gpuI0);
38 31  
39 32 float* gpu_vote;
... ... @@ -57,9 +50,9 @@ void ivote3(float* img, float sigma[], float anisotropy, float phi, float d_phi,
57 50  
58 51 }
59 52  
60   - cudaFree(gpu_grad);
  53 + cudaFree(gpu_grad);
61 54 cudaMemcpy(img, gpu_vote, bytes, cudaMemcpyDeviceToHost);
62   -
  55 +
63 56 //allocate space on the gpu for the final detected cells.
64 57 //float* gpu_output;
65 58 //cudaMalloc(&gpu_output, bytes);
... ...
cpp/main.cpp
... ... @@ -7,123 +7,19 @@
7 7 #include <stim/parser/filename.h>
8 8 #include <stim/visualization/colormap.h>
9 9 #include <stim/image/image.h>
10   -#define pi 3.14159
  10 +#include <stim/math/constants.h>
11 11  
12   -//#define M_PI 3.14159
13   -//#include <stim/math/circle.h>
14   -//#include <stim/math/vec3.h>
15   -//#include <stim/math/plane.h>
16   -//#include <stim/math/vector.h>
17   -//#include <stim/visualization/aabb3.h>
  12 +stim::arglist args;
  13 +int iter;
  14 +unsigned int rmax;
  15 +unsigned int nlmax;
  16 +float t;
  17 +float sigma;
  18 +float phi;
  19 +size_t x, y, z;
18 20  
19 21  
20   -
21   -/*void test_3(float* gpu_out, float* gpu_grad, float rmax, float phi, int n, int x, int y, int z);
22   -
23   -int main(){
24   -
25   - int n=20;
26   - float rmax;
27   - float phi_deg;
28   - float phi;
29   - rmax=4;
30   - phi_deg = 15;
31   - phi = phi_deg * pi/180;
32   - int x,y,z;
33   - x=y=z=1;
34   - unsigned int size = x*y*z*sizeof (float);
35   - float* cpu_grad = (float*) malloc(3*size);
36   - float* gpu_grad;
37   - cudaMalloc(&gpu_grad, 3*size);
38   - cpu_grad[0]=1;
39   - cpu_grad[1]=0;
40   - cpu_grad[2]=-0.5;
41   - cudaMemcpy(gpu_grad, cpu_grad, 3*size, cudaMemcpyHostToDevice);
42   - float* cpu_out = (float*) malloc(3*size*(n+1));
43   - float* gpu_out;
44   - cudaMalloc(&gpu_out, 3*size*(n+1));
45   - test_3(gpu_out, gpu_grad, rmax, phi, n, x, y, z);
46   - cudaMemcpy(cpu_out, gpu_out, 3*size*(n+1), cudaMemcpyDeviceToHost);
47   - std::ofstream list("circle_check_cuda1.txt");
48   - if (list.is_open()){
49   - for (int j=0; j<=n; ++j)
50   - list << cpu_out[3*j] << '\t' << cpu_out[3*j +1] << '\t' << cpu_out[3*j + 2] << '\n';
51   - }
52   - list.close();
53   - */
54   -/*
55   - int main(){
56   -
57   -
58   - stim::vec3<float> g(-44,-3.4,-0.005); // form a vec3 variable for the gradient vector
59   - stim::vec3<float> g_sph = g.cart2sph(); //convert cartesian coordinate to spherical for the gradient vector
60   - int n =36; //set the number of points to find the boundaries of the conical voting area
61   - int xi = 105;
62   - int yi = 17;
63   - int zi = 23;
64   - float xc = 12 * cos(g_sph[1]) * sin(g_sph[2]); //calculate the center point of the surface of the voting area for the voter
65   - float yc = 10 * sin(g_sph[1]) * sin(g_sph[2]) ;
66   - float zc = 10 * cos(g_sph[2]) ;
67   - float r = sqrt(xc*xc + yc*yc + zc*zc);
68   - xc+=xi;
69   - yc+=yi;
70   - zc+=zi;
71   - stim::vec3<float> center(xc,yc,zc);
72   -
73   - float d = 2 * r * tan(25*pi/180 ); //find the diameter of the conical voting area
74   - stim::vec3<float> norm = g.norm(); //compute the normalize gradient vector
75   - float step = 360.0/(float) n;
76   - stim::circle<float> cir(center, d, norm);
77   - stim::aabb3<int> bb(xi,yi,zi);
78   - bb.insert(xc,yc,zc);
79   - for(float j = 0; j <360.0; j += step){
80   - stim::vec3<float> out = cir.p(j);
81   - bb.insert(out[0], out[1], out[2]);
82   - }
83   -
84   - bb.trim_low(0,0,0);
85   - bb.trim_high(128-1, 128-1, 128-1);
86   -
87   - std::cout<< bb.low[0] << '\t' << bb.low[1] << '\t' << bb.low[2] << '\n';
88   - std::cout<< bb.high[0] << '\t' << bb.high[1] << '\t' << bb.high[2] << '\n';
89   - std::cin >> n;
90   -*/
91   - /*int n=10;
92   - stim::circle<float> cir;
93   - float* c0= (float*) malloc(3*sizeof(float));
94   - c0[0] =-4;
95   - c0[1]=0;
96   - c0[2] = 3;
97   - stim::vec3<float> c(c0[0],c0[1],c0[2]);
98   - float len = c.len();
99   - stim::vec3<float> norm(c0[0]/len,c0[1]/len,c0[2]/len);
100   - std::cout<< len << '\n';
101   - std::cout<< norm << '\n';
102   - cir.center(c);
103   - cir.normal(norm);
104   - cir.scale(2);
105   - stim::vec3<float> out = cir.p(45);
106   - std::vector<stim::vec3<float>> out2 = cir.getPoints(n);
107   -
108   - std::cout<< out << '\n';
109   - std::cout <<out[0] << '\t' << out[1] << '\t' << out[2] <<'\n';
110   - std::cout<< c << '\n';
111   -
112   - for (std::vector<stim::vec3<float>>::const_iterator i = out2.begin(); i != out2.end(); ++i)
113   - std::cout << *i << '\n';
114   - std::ofstream list("circle_check.txt");
115   - if (list.is_open()){
116   - for (std::vector<stim::vec3<float>>::const_iterator j = out2.begin(); j != out2.end(); ++j)
117   - list << *j << '\n';
118   - }
119   - list.close();
120   - std::cin >> n;
121   -
122   -}
123   -*/
124   -
125   -
126   -void ivote3(float* img, float std[], float anisotropy, float phi, float d_phi, unsigned int r[], int iter, float t, unsigned int conn[],
  22 +void ivote3(float* img, float std[], float phi, float d_phi, unsigned int r[], int iter, float t, unsigned int conn[],
127 23 unsigned int x, unsigned int y, unsigned int z);
128 24 void lmax(float* center, float* vote, float t1, unsigned int conn[], unsigned int x, unsigned int y, unsigned int z);
129 25  
... ... @@ -138,32 +34,20 @@ void invert_data(float* cpuI, unsigned int x, unsigned int y, unsigned int z){
138 34 }
139 35 }
140 36  
141   -int main(int argc, char** argv){
142 37  
143 38  
144   - cudaDeviceProp prop;
145   - int count;
146   - cudaGetDeviceCount(&count);
147   - //printf("cudadevicecount: %i\n", count);
148   - for (int i=0; i<count; i++){
149   - cudaGetDeviceProperties(&prop, i);
150   - printf("current device ID: %d\n", i);
151   - printf("device name: %s\n", prop.name);
152   - printf("total global mem: %lu\n", prop.totalGlobalMem);
153   - printf("shared memory per block: %lu\n", prop.sharedMemPerBlock);
154   - }
155   -
156   - //output advertisement
157   - std::cout<<std::endl<<std::endl;
158   - std::cout<<"========================================================================="<<std::endl;
159   - std::cout<<"Thank you for using the ivote3 segmentation tool!"<<std::endl;
160   - std::cout<<"Scalable Tissue Imaging and Modeling (STIM) Lab, University of Houston"<<std::endl;
161   - std::cout<<"Developers: Laila Saadatifard and David Mayerich"<<std::endl;
162   - std::cout<<"Source: https://git.stim.ee.uh.edu/segmentation/ivote3"<<std::endl;
163   - std::cout<<"========================================================================="<<std::endl<<std::endl;
  39 +void advertise() {
  40 + std::cout << std::endl << std::endl;
  41 + std::cout << "=========================================================================" << std::endl;
  42 + std::cout << "Thank you for using the ivote3 segmentation tool!" << std::endl;
  43 + std::cout << "Scalable Tissue Imaging and Modeling (STIM) Lab, University of Houston" << std::endl;
  44 + std::cout << "Developers: Laila Saadatifard and David Mayerich" << std::endl;
  45 + std::cout << "Source: https://git.stim.ee.uh.edu/segmentation/ivote3" << std::endl;
  46 + std::cout << "=========================================================================" << std::endl << std::endl;
164 47  
165   - stim::arglist args;
  48 +}
166 49  
  50 +void init_args(int argc, char* argv[]) {
167 51 #ifdef _WIN32
168 52 args.set_ansi(false);
169 53 #endif
... ... @@ -175,101 +59,106 @@ int main(int argc, char** argv){
175 59 args.add("z", "size of the dataset along Z axis", "positive value");
176 60 args.add("t", "threshold value for the final result", "positive valu");
177 61 args.add("invert", "to invert the input data set", "string");
178   - args.add("anisotropy", "anisotropy value of the imaging", "1");
  62 + args.add("rmax", "maximum possible radius of the cells in the input image", "10", "[positive value]");
  63 + args.add("phi", "starting angle for the vote region (in degrees)", "25.0", "0 <= phi < 180");
  64 + args.add("iter", "number of iterations for voting", "8", "i > 0");
  65 + args.add("sigma", "the gaussian blur standard deviation", "5", "s >=0 (s = 0, no blurring)");
  66 + args.add("conn", "the number of connected neighbors for calculating the local maxima", "5", "[positive value]");
179 67 //parse the command line arguments.
180 68 args.parse(argc, argv);
181 69  
182 70 //display the help text if requested
183   - if(args["help"].is_set()){
184   - std::cout<<std::endl<<"usage: ivote input_image output_list --option [A B C ...]"<<std::endl;
185   - std::cout<<std::endl<<std::endl
186   - << "examples: ivote blue.bmp list.txt "<<std::endl;
187   -
188   - std::cout<<std::endl<<std::endl;
189   - std::cout<<args.str()<<std::endl;
  71 + if (args["help"].is_set()) {
  72 + advertise();
  73 + std::cout << std::endl << "usage: ivote input_image output_list --option [A B C ...]" << std::endl;
  74 + std::cout << std::endl << std::endl
  75 + << "examples: ivote blue.bmp list.txt " << std::endl;
  76 +
  77 + std::cout << std::endl << std::endl;
  78 + std::cout << args.str() << std::endl;
190 79 exit(1);
191 80 }
192 81  
193 82 //if the input and output files aren't specified, throw an error and exit
194   - if(args.nargs() < 2){
195   - std::cout<<"ERROR: two files must be specified for segmentation, enter ivote --help for options."<<std::endl<<std::endl;
  83 + if (args.nargs() < 3) {
  84 + std::cout << "ERROR: three files must be specified for segmentation, enter ivote --help for options." << std::endl << std::endl;
196 85 exit(1);
197 86 }
198 87  
199   - //get the input image file
200   - stim::filename Ifilename(args.arg(0));
  88 + //set the x, y, z.
  89 + x = (size_t)args["x"].as_int();
  90 + y = (size_t)args["y"].as_int();
  91 + z = (size_t)args["z"].as_int();
  92 + iter = args["iter"].as_int();
  93 + rmax = (unsigned int)args["rmax"].as_int();
  94 + nlmax = (unsigned int)args["conn"].as_int();
  95 + t = args["t"].as_float();
  96 + sigma = args["sigma"].as_float();
  97 + phi = (float)args["phi"].as_float() * (float)stim::PI / 180;
  98 +
  99 +}
  100 +int main(int argc, char** argv){
201 101  
202   - //get the output file name
203   - stim::filename OutName(args.arg(1));
204 102  
205   - //set the x, y, z.
206   - int x = args["x"].as_int();
207   - int y = args["y"].as_int();
208   - int z = args["z"].as_int();
  103 + cudaDeviceProp prop;
  104 + int count;
  105 + cudaGetDeviceCount(&count);
  106 + for (int i=0; i<count; i++){
  107 + cudaGetDeviceProperties(&prop, i);
  108 + printf("current device ID: %d\n", i);
  109 + printf("device name: %s\n", prop.name);
  110 + printf("total global mem: %lu\n", prop.totalGlobalMem);
  111 + printf("shared memory per block: %lu\n", prop.sharedMemPerBlock);
  112 + }
  113 +
  114 + init_args(argc, argv);
209 115  
210   - //set the threshold.
211   - float t = args["t"].as_float();
212   - //set the anisotropy
213   - float anisotropy = args["anisotropy"].as_float();
214   - unsigned int rmax = 10;
215   - unsigned int r[3] = { 12, rmax, rmax};
216   - float std = 5;
217   - float sigma[3] = { std, std, std};
218   - unsigned int nlmax = 5;
  116 + unsigned int r[3] = { rmax , rmax, rmax};
  117 +
  118 + float sigma3[3] = { sigma, sigma, sigma};
219 119 unsigned int conn[3] = { nlmax, nlmax, nlmax};
220   - float phi_deg = 25.0;
221   - float phi = phi_deg * pi /180;
222   - int iter = 8;
223 120 float d_phi = phi/(iter+2);
224 121  
225   - std::string filename = Ifilename.str();
226   - unsigned int bytes = x*y*z*sizeof(float);
  122 + size_t bytes = x*y*z*sizeof(float);
227 123  
228 124 //allocate space on the cpu for the input data
229 125 float* cpuI = (float*) malloc(bytes);
230 126  
231 127 //load the input file into the cpuI
232   - std::ifstream nissl(filename, std::ios::in | std::ios::binary);
  128 + std::ifstream nissl(args.arg(0), std::ios::in | std::ios::binary);
233 129 nissl.read((char*)cpuI, bytes);
234 130 nissl.close();
235 131 if(args["invert"].is_set())
236 132 invert_data(cpuI, x, y, z);
237 133  
238 134 //write a new file from the cpuI.
239   - std::ofstream original("shared2D-v1/inv-128.vol", std::ofstream::out | std::ofstream::binary);
  135 + std::ofstream original("0-inv-128.vol", std::ofstream::out | std::ofstream::binary);
240 136 original.write((char*)cpuI, bytes);
241 137 original.close();
242 138  
243   - //allocate space on the cpu for the output result
244   - float* cpu_out = (float*) malloc(bytes);
245   -
246   - // call the ivote function
247   - //ivote3(cpu_out, cpuI, sigma, anisotropy, phi, d_phi, r, iter, t, conn, x, y, z);
248   - ivote3(cpuI, sigma, anisotropy, phi, d_phi, r, iter, t, conn, x, y, z);
249   - //write the blurred file from the cpuI.
250   - std::ofstream fblur("shared2D-v8/vote8.vol", std::ofstream::out | std::ofstream::binary);
251   - fblur.write((char*)cpuI, bytes);
252   - fblur.close();
253 139  
254   - //stim::image<float>imgrad3;
255   - //imgrad3.set_interleaved3(cpu_out, 128,128,128,3);
256   - //std::ofstream fgx("syn/gx-128.vol", std::ofstream::out | std::ofstream::binary);
257   - //fgx.write((char*)imgrad3.channel(0).data(), bytes);
258   - //fgx.close();
  140 + ivote3(cpuI, sigma3, phi, d_phi, r, iter, t, conn, x, y, z); // call the ivote function
  141 +
  142 + std::ofstream fvote("0-vote8.vol", std::ofstream::out | std::ofstream::binary);
  143 + fvote.write((char*)cpuI, bytes);
  144 + fvote.close();
259 145  
  146 + //allocate space on the cpu for the output result
  147 + float* cpu_out = (float*)malloc(bytes * 3);
  148 +
260 149 //write the output file.
261 150 //for (int t0=0; t0<=5000; t0+=100){
262 151 // float t1 = t0;
263 152 int t0 = t;
264 153 lmax(cpu_out, cpuI, t, conn, x, y, z);
265 154 //std::ofstream fo("shared2D-v8/" + OutName.str(), std::ofstream::out | std::ofstream::binary);
266   - std::ofstream fo( OutName.str()+std::to_string(t0)+".vol", std::ofstream::out | std::ofstream::binary);
  155 + std::ofstream fo( args.arg(1), std::ofstream::out | std::ofstream::binary);
267 156 fo.write((char*)cpu_out, bytes);
268 157 fo.close();
269 158  
270 159 // creat a file for saving the list centers
271 160  
272   - std::ofstream list(OutName.str()+std::to_string(t0)+".obj");
  161 + std::ofstream list(args.arg(2));
273 162 // set the number of detected cells to zero.
274 163 int nod = 0;
275 164 if (list.is_open()){
... ... @@ -281,17 +170,13 @@ int main(int argc, char** argv){
281 170 int idx = iz * x * y + iy * x + ix;
282 171 if (cpu_out[idx]>0){
283 172 nod++;
284   - list << "v" << "\t" << ix << "\t" << iy << "\t"<< iz << "\t" << cpu_out[idx] << '\n' ;
  173 + list << ix << " " << iy << " "<< iz << " " << cpu_out[idx] << '\n' ;
285 174  
286 175 }
287 176 }
288 177 }
289 178 }
290   - list << "p" << "\t";
291   - for (unsigned int i_nod =1 ; i_nod <=nod; i_nod++){
292   - list << i_nod << "\t";
293   - }
294   -
  179 +
295 180 list.close();
296 181 }
297 182  
... ...