Commit abaf5630a93d1e10be9b4e20c68686bd6ac95899

Authored by David Mayerich
1 parent e166b01b

fixed the signed/unsigned problem with stim::cuda::conv2

1 #include <stim/image/image.h> 1 #include <stim/image/image.h>
2 #include <cmath> 2 #include <cmath>
3 -#include <conio.h> 3 +//#include <conio.h>
4 #include <stim/visualization/colormap.h> 4 #include <stim/visualization/colormap.h>
5 #include <stim/image/image_contour_detection.h> 5 #include <stim/image/image_contour_detection.h>
6 6
7 void array_multiply(float* lhs, float rhs, unsigned int N); 7 void array_multiply(float* lhs, float rhs, unsigned int N);
8 void array_add(float* ptr1, float* ptr2, float* sum, unsigned int N); 8 void array_add(float* ptr1, float* ptr2, float* sum, unsigned int N);
9 9
  10 +/// This function evaluates the theta-dependent gradient image given an input image
  11 +
  12 +/// @param lab is the 3-channel image in the LAB color space
  13 +/// @param theta is the angle used for computing the gradient
  14 +
10 stim::image<float> func_mPb_theta(stim::image<float> lab, float theta, unsigned int w, unsigned int h){ 15 stim::image<float> func_mPb_theta(stim::image<float> lab, float theta, unsigned int w, unsigned int h){
11 16
  17 + //allocate space for the gradient image
12 stim::image<float> mPb_theta(w, h, 1); 18 stim::image<float> mPb_theta(w, h, 1);
13 19
  20 + //allocate space for each individual channel
14 stim::image<float> pic_light, pic_colora, pic_colorb; 21 stim::image<float> pic_light, pic_colora, pic_colorb;
15 pic_light = lab.channel(0); 22 pic_light = lab.channel(0);
16 pic_colora = lab.channel(1); 23 pic_colora = lab.channel(1);
17 pic_colorb = lab.channel(2); 24 pic_colorb = lab.channel(2);
18 25
19 - unsigned int N = w * h;  
20 - float sigma = 2;  
21 - unsigned int sigma_n = 3;  
22 - unsigned r1 = 3; 26 + unsigned int N = w * h; //calculate the number of pixels in the image
  27 + float sigma = 2; //set the sigma value to \sigma = 2
  28 + unsigned int sigma_n = 3; //set the number of standard deviations used to define the kernel size
  29 + unsigned r1 = 3; //disk radii
23 unsigned r2 = 5; 30 unsigned r2 = 5;
24 unsigned r3 = 10; 31 unsigned r3 = 10;
25 unsigned r4 = 20; 32 unsigned r4 = 20;
26 - float alpha[9] = {1,1,1,1,1,1,1,1,1}; 33 + float alpha[9] = {1,1,1,1,1,1,1,1,1}; //weighting for each channel
27 34
28 35
29 stim::image<float> l1,l2,l3,a1,a2,a3,b1,b2,b3; 36 stim::image<float> l1,l2,l3,a1,a2,a3,b1,b2,b3;
30 37
31 l1 = gaussian_derivative_filter_odd(pic_light, sigma, sigma_n, r3 * 2, theta, w, h); 38 l1 = gaussian_derivative_filter_odd(pic_light, sigma, sigma_n, r3 * 2, theta, w, h);
32 stim::cpu2image(l1.data(), "data_output/testl_tex5.bmp", w, h, stim::cmBrewer); 39 stim::cpu2image(l1.data(), "data_output/testl_tex5.bmp", w, h, stim::cmBrewer);
33 - l2 = gaussian_derivative_filter_odd(pic_light, sigma, sigma_n, r2 * 2, theta, w, h); 40 +
  41 + exit(0);
  42 + /*l2 = gaussian_derivative_filter_odd(pic_light, sigma, sigma_n, r2 * 2, theta, w, h);
34 stim::cpu2image(l2.data(), "data_output/l2_tex.bmp", w, h, stim::cmBrewer); 43 stim::cpu2image(l2.data(), "data_output/l2_tex.bmp", w, h, stim::cmBrewer);
35 l3 = gaussian_derivative_filter_odd(pic_light, sigma, sigma_n, r3 * 2, theta, w, h); 44 l3 = gaussian_derivative_filter_odd(pic_light, sigma, sigma_n, r3 * 2, theta, w, h);
36 stim::cpu2image(l3.data(), "data_output/l3_tex.bmp", w, h, stim::cmBrewer); 45 stim::cpu2image(l3.data(), "data_output/l3_tex.bmp", w, h, stim::cmBrewer);
@@ -45,7 +54,7 @@ stim::image&lt;float&gt; func_mPb_theta(stim::image&lt;float&gt; lab, float theta, unsigned @@ -45,7 +54,7 @@ stim::image&lt;float&gt; func_mPb_theta(stim::image&lt;float&gt; lab, float theta, unsigned
45 b2 = gaussian_derivative_filter_odd(pic_colorb, sigma, sigma_n, r3 * 2, theta, w, h); 54 b2 = gaussian_derivative_filter_odd(pic_colorb, sigma, sigma_n, r3 * 2, theta, w, h);
46 stim::cpu2image(b2.data(), "data_output/b2_tex.bmp", w, h, stim::cmBrewer); 55 stim::cpu2image(b2.data(), "data_output/b2_tex.bmp", w, h, stim::cmBrewer);
47 b3 = gaussian_derivative_filter_odd(pic_colorb, sigma, sigma_n, r4 * 2, theta, w, h); 56 b3 = gaussian_derivative_filter_odd(pic_colorb, sigma, sigma_n, r4 * 2, theta, w, h);
48 - stim::cpu2image(b3.data(), "data_output/b3_tex.bmp", w, h, stim::cmBrewer); 57 + stim::cpu2image(b3.data(), "data_output/b3_tex.bmp", w, h, stim::cmBrewer);*/
49 58
50 /*for (unsigned i = 0; i<N; i++){ 59 /*for (unsigned i = 0; i<N; i++){
51 60
@@ -90,4 +99,4 @@ stim::image&lt;float&gt; func_mPb_theta(stim::image&lt;float&gt; lab, float theta, unsigned @@ -90,4 +99,4 @@ stim::image&lt;float&gt; func_mPb_theta(stim::image&lt;float&gt; lab, float theta, unsigned
90 //getch(); 99 //getch();
91 100
92 return mPb_theta; 101 return mPb_theta;
93 -}  
94 \ No newline at end of file 102 \ No newline at end of file
  103 +}
1 #include <stim/image/image.h> 1 #include <stim/image/image.h>
2 #include <cmath> 2 #include <cmath>
3 -#include <conio.h> 3 +//#include <conio.h>
4 #include <stim/visualization/colormap.h> 4 #include <stim/visualization/colormap.h>
5 #include <stim/image/image_contour_detection.h> 5 #include <stim/image/image_contour_detection.h>
6 #include <sstream> 6 #include <sstream>
@@ -62,7 +62,7 @@ stim::image&lt;float&gt; func_mPb(stim::image&lt;float&gt; lab, unsigned int theta_n, unsign @@ -62,7 +62,7 @@ stim::image&lt;float&gt; func_mPb(stim::image&lt;float&gt; lab, unsigned int theta_n, unsign
62 double duration2 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; 62 double duration2 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
63 std::cout<<"total time:"<< duration2 <<"s"<<'\n'; 63 std::cout<<"total time:"<< duration2 <<"s"<<'\n';
64 64
65 - getch(); 65 + //getch();
66 66
67 return mPb; 67 return mPb;
68 68
@@ -132,4 +132,4 @@ stim::image&lt;float&gt; func_mPb(stim::image&lt;float&gt; lab, unsigned int theta_n, unsign @@ -132,4 +132,4 @@ stim::image&lt;float&gt; func_mPb(stim::image&lt;float&gt; lab, unsigned int theta_n, unsign
132 132
133 133
134 134
135 -}  
136 \ No newline at end of file 135 \ No newline at end of file
  136 +}
gauss_derivative_odd.cpp
@@ -12,13 +12,14 @@ void array_multiply(float* lhs, float rhs, unsigned int N); @@ -12,13 +12,14 @@ void array_multiply(float* lhs, float rhs, unsigned int N);
12 // winsize = 2 * r, side of mask = winsize + 1 12 // winsize = 2 * r, side of mask = winsize + 1
13 stim::image<float> gaussian_derivative_filter_odd(stim::image<float> image, float sigma, unsigned int sigma_n, unsigned int winsize, float theta, unsigned int w, unsigned int h){ 13 stim::image<float> gaussian_derivative_filter_odd(stim::image<float> image, float sigma, unsigned int sigma_n, unsigned int winsize, float theta, unsigned int w, unsigned int h){
14 14
15 - stim::image<float> mask_x(winsize+1, winsize+1), mask_y(winsize+1, winsize+1), mask_theta(winsize+1, winsize+1), mask_test(winsize+1, winsize+1, 1), derivative_x, derivative_y, derivative_theta(w, h); 15 + stim::image<float> mask_x(winsize+1, winsize+1), mask_y(winsize+1, winsize+1), mask_theta(winsize+1, winsize+1), mask_delta(winsize+1, winsize+1, 1), derivative_x, derivative_y, derivative_theta(w, h);
16 //float* ptr = mask_x.data(); 16 //float* ptr = mask_x.data();
17 17
18 18
19 - memset ( mask_test.data(), 0, mask_test.size() * sizeof(float));  
20 - mask_test.data()[winsize*(winsize+2)/2] = 1;  
21 - stim::cpu2image(mask_test.data(), "data_output/mask_test.bmp", winsize+1, winsize+1, stim::cmBrewer); 19 + //DEBUG calculate a Dirac delta function kernel
  20 + memset ( mask_delta.data(), 0, mask_delta.size() * sizeof(float));
  21 + mask_delta.data()[winsize*(winsize+2)/2] = 1;
  22 + stim::cpu2image(mask_delta.data(), "data_output/mask_test.bmp", winsize+1, winsize+1, stim::cmBrewer);
22 23
23 24
24 // set parameters 25 // set parameters
@@ -53,9 +54,9 @@ stim::image&lt;float&gt; gaussian_derivative_filter_odd(stim::image&lt;float&gt; image, floa @@ -53,9 +54,9 @@ stim::image&lt;float&gt; gaussian_derivative_filter_odd(stim::image&lt;float&gt; image, floa
53 // 2D convolution 54 // 2D convolution
54 //derivative_theta = image.convolve2(mask_theta); 55 //derivative_theta = image.convolve2(mask_theta);
55 //stim::cpu2image(derivative_theta.data(), "data_output/derivative_theta1.bmp", w, h, stim::cmBrewer); 56 //stim::cpu2image(derivative_theta.data(), "data_output/derivative_theta1.bmp", w, h, stim::cmBrewer);
56 - //conv2(image.data(), mask_test.data(), derivative_theta.data(), w, h, winsize+1);  
57 - conv2(image.data(), mask_theta.data(), derivative_theta.data(), w, h, winsize+1);  
58 - //stim::cpu2image(derivative_theta.data(), "data_output/derivative_theta_tex1.bmp", w, h, stim::cmBrewer); 57 + conv2(image.data(), mask_delta.data(), derivative_theta.data(), w, h, winsize+1);
  58 + //conv2(image.data(), mask_theta.data(), derivative_theta.data(), w, h, winsize+1);
  59 + stim::cpu2image(derivative_theta.data(), "data_output/derivative_theta_tex1.bmp", w, h, stim::cmBrewer);
59 60
60 //array_abs(derivative_theta.data(), N); 61 //array_abs(derivative_theta.data(), N);
61 62
@@ -85,4 +86,4 @@ stim::image&lt;float&gt; gaussian_derivative_filter_odd(stim::image&lt;float&gt; image, floa @@ -85,4 +86,4 @@ stim::image&lt;float&gt; gaussian_derivative_filter_odd(stim::image&lt;float&gt; image, floa
85 86
86 return derivative_theta; 87 return derivative_theta;
87 88
88 -}  
89 \ No newline at end of file 89 \ No newline at end of file
  90 +}
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 #include <iostream> 5 #include <iostream>
6 6
7 7
8 -void main() 8 +int main()
9 { 9 {
10 stim::image<float> rgb,gaussgradient; //generate an image object 10 stim::image<float> rgb,gaussgradient; //generate an image object
11 11
@@ -51,6 +51,6 @@ void main() @@ -51,6 +51,6 @@ void main()
51 stim::image<float> mPb; 51 stim::image<float> mPb;
52 mPb = func_mPb(lab, theta_n, w, h); 52 mPb = func_mPb(lab, theta_n, w, h);
53 53
54 - 54 + return 0;
55 55
56 -}  
57 \ No newline at end of file 56 \ No newline at end of file
  57 +}