Commit 569e0942f3874deff6728f4eeafee23034a8246a
Merge branch 'master' of git.stim.ee.uh.edu:codebase/stimlib into ivote2
Showing
1 changed file
with
20 additions
and
28 deletions
Show diff stats
stim/iVote/ivote2.cuh
... | ... | @@ -94,8 +94,7 @@ namespace stim { |
94 | 94 | |
95 | 95 | //this function performs the 2D iterative voting algorithm on the image stored in the gpu |
96 | 96 | template<typename T> |
97 | - void gpu_ivote2(T* gpuI, unsigned int rmax, size_t x, size_t y, bool invert = false, T t = 0, std::string outname_img = "out.bmp", std::string outname_txt = "out.txt", | |
98 | - int iter = 8, T phi = 15.0f * (float)stim::PI / 180, int conn = 8, bool debug = false) { | |
97 | + void gpu_ivote2(T* gpuI, unsigned int rmax, size_t x, size_t y, bool invert = false, T t = 0, int iter = 8, T phi = 15.0f * (float)stim::PI / 180, int conn = 8, bool debug = false) { | |
99 | 98 | |
100 | 99 | size_t pixels = x * y; //compute the size of input image |
101 | 100 | // |
... | ... | @@ -129,43 +128,36 @@ namespace stim { |
129 | 128 | } |
130 | 129 | stim::cuda::gpu_local_max<float>(gpuI, gpuVote, conn, x, y); //calculate the local maxima |
131 | 130 | |
132 | - T* pts = (T*)malloc(bytes); //allocate memory on the cpu to store the output of iterative voting | |
133 | - HANDLE_ERROR(cudaMemcpy(pts, gpuI, bytes, cudaMemcpyDeviceToHost)); //copy the output from gpu to the cpu memory | |
134 | - | |
135 | - T threshold; | |
136 | - if (t == 0) threshold = stim::th_otsu<T>(pts, pixels); //if threshold value is not set call the function to compute the threshold | |
137 | - else threshold = t; | |
138 | - | |
139 | - std::ofstream output; //save the thresholded detected seeds in a text file | |
140 | - output.open(outname_txt); | |
141 | - output << "X" << " " << "Y" << " " << "threshold" << "\n"; | |
142 | - size_t ind; | |
143 | - for (size_t ix = 0; ix < x; ix++) { | |
144 | - for (size_t iy = 0; iy < y; iy++) { | |
145 | - ind = iy * x + ix; | |
146 | - if (pts[ind] > threshold) { | |
147 | - output << ix << " " << iy << " " << pts[ind] << "\n"; | |
148 | - pts[ind] = 1; | |
131 | + if (t > 0) { | |
132 | + T* pts = (T*)malloc(bytes); //allocate memory on the cpu to store the output of iterative voting | |
133 | + HANDLE_ERROR(cudaMemcpy(pts, gpuI, bytes, cudaMemcpyDeviceToHost)); //copy the output from gpu to the cpu memory | |
134 | + | |
135 | + T threshold; | |
136 | + threshold = t; | |
137 | + | |
138 | + size_t ind; | |
139 | + for (size_t ix = 0; ix < x; ix++) { | |
140 | + for (size_t iy = 0; iy < y; iy++) { | |
141 | + ind = iy * x + ix; | |
142 | + if (pts[ind] > threshold) { | |
143 | + pts[ind] = 1; | |
144 | + } | |
145 | + else pts[ind] = 0; | |
149 | 146 | } |
150 | - else pts[ind] = 0; | |
151 | 147 | } |
148 | + HANDLE_ERROR(cudaMemcpy(gpuI, pts, bytes, cudaMemcpyHostToDevice)); //copy the points to the gpu | |
152 | 149 | } |
153 | - output.close(); | |
154 | - | |
155 | - HANDLE_ERROR(cudaMemcpy(gpuI, pts, bytes, cudaMemcpyHostToDevice)); //copy the points to the gpu | |
156 | - stim::cpu2image(pts, outname_img, x, y); //output the image | |
157 | - | |
150 | + | |
158 | 151 | } |
159 | 152 | |
160 | 153 | |
161 | 154 | template<typename T> |
162 | - void cpu_ivote2(T* cpuI, unsigned int rmax, size_t x, size_t y, bool invert = false, T t = 0, std::string outname_img = "out.bmp", std::string outname_txt = "out.txt", | |
163 | - int iter = 8, T phi = 15.0f * (float)stim::PI / 180, int conn = 8, bool debug = false) { | |
155 | + void cpu_ivote2(T* cpuI, unsigned int rmax, size_t x, size_t y, bool invert = false, T t = 0, int iter = 8, T phi = 15.0f * (float)stim::PI / 180, int conn = 8, bool debug = false) { | |
164 | 156 | size_t bytes = x*y * sizeof(T); |
165 | 157 | T* gpuI; //allocate space on the gpu to save the input image |
166 | 158 | HANDLE_ERROR(cudaMalloc(&gpuI, bytes)); |
167 | 159 | HANDLE_ERROR(cudaMemcpy(gpuI, cpuI, bytes, cudaMemcpyHostToDevice)); //copy the image to the gpu |
168 | - stim::gpu_ivote2<T>(gpuI, rmax, x, y, invert, t, outname_img, outname_txt, iter, phi, conn, debug); //call the gpu version of the ivote | |
160 | + stim::gpu_ivote2<T>(gpuI, rmax, x, y, invert, t, iter, phi, conn, debug); //call the gpu version of the ivote | |
169 | 161 | HANDLE_ERROR(cudaMemcpy(cpuI, gpuI, bytes, cudaMemcpyDeviceToHost)); //copy the output to the cpu |
170 | 162 | } |
171 | 163 | } | ... | ... |