From f861ad6c5893d3f9b954437f1019920933dfb8c6 Mon Sep 17 00:00:00 2001 From: Laila Saadatifard Date: Mon, 3 Apr 2017 15:37:22 -0500 Subject: [PATCH] do not threshold if the 't' parameter set to zero --- stim/iVote/ivote2.cuh | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/stim/iVote/ivote2.cuh b/stim/iVote/ivote2.cuh index 0c97ccb..e1cacb7 100644 --- a/stim/iVote/ivote2.cuh +++ b/stim/iVote/ivote2.cuh @@ -94,8 +94,7 @@ namespace stim { //this function performs the 2D iterative voting algorithm on the image stored in the gpu template - 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", - int iter = 8, T phi = 15.0f * (float)stim::PI / 180, int conn = 8, bool debug = false) { + 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) { size_t pixels = x * y; //compute the size of input image // @@ -129,43 +128,36 @@ namespace stim { } stim::cuda::gpu_local_max(gpuI, gpuVote, conn, x, y); //calculate the local maxima - T* pts = (T*)malloc(bytes); //allocate memory on the cpu to store the output of iterative voting - HANDLE_ERROR(cudaMemcpy(pts, gpuI, bytes, cudaMemcpyDeviceToHost)); //copy the output from gpu to the cpu memory - - T threshold; - if (t == 0) threshold = stim::th_otsu(pts, pixels); //if threshold value is not set call the function to compute the threshold - else threshold = t; - - std::ofstream output; //save the thresholded detected seeds in a text file - output.open(outname_txt); - output << "X" << " " << "Y" << " " << "threshold" << "\n"; - size_t ind; - for (size_t ix = 0; ix < x; ix++) { - for (size_t iy = 0; iy < y; iy++) { - ind = iy * x + ix; - if (pts[ind] > threshold) { - output << ix << " " << iy << " " << pts[ind] << "\n"; - pts[ind] = 1; + if (t > 0) { + T* pts = (T*)malloc(bytes); //allocate memory on the cpu to store the output of iterative voting + HANDLE_ERROR(cudaMemcpy(pts, gpuI, bytes, cudaMemcpyDeviceToHost)); //copy the output from gpu to the cpu memory + + T threshold; + threshold = t; + + size_t ind; + for (size_t ix = 0; ix < x; ix++) { + for (size_t iy = 0; iy < y; iy++) { + ind = iy * x + ix; + if (pts[ind] > threshold) { + pts[ind] = 1; + } + else pts[ind] = 0; } - else pts[ind] = 0; } + HANDLE_ERROR(cudaMemcpy(gpuI, pts, bytes, cudaMemcpyHostToDevice)); //copy the points to the gpu } - output.close(); - - HANDLE_ERROR(cudaMemcpy(gpuI, pts, bytes, cudaMemcpyHostToDevice)); //copy the points to the gpu - stim::cpu2image(pts, outname_img, x, y); //output the image - + } template - 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", - int iter = 8, T phi = 15.0f * (float)stim::PI / 180, int conn = 8, bool debug = false) { + 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) { size_t bytes = x*y * sizeof(T); T* gpuI; //allocate space on the gpu to save the input image HANDLE_ERROR(cudaMalloc(&gpuI, bytes)); HANDLE_ERROR(cudaMemcpy(gpuI, cpuI, bytes, cudaMemcpyHostToDevice)); //copy the image to the gpu - stim::gpu_ivote2(gpuI, rmax, x, y, invert, t, outname_img, outname_txt, iter, phi, conn, debug); //call the gpu version of the ivote + stim::gpu_ivote2(gpuI, rmax, x, y, invert, t, iter, phi, conn, debug); //call the gpu version of the ivote HANDLE_ERROR(cudaMemcpy(cpuI, gpuI, bytes, cudaMemcpyDeviceToHost)); //copy the output to the cpu } } -- libgit2 0.21.4