Commit abaf5630a93d1e10be9b4e20c68686bd6ac95899
1 parent
e166b01b
fixed the signed/unsigned problem with stim::cuda::conv2
Showing
4 changed files
with
33 additions
and
23 deletions
Show diff stats
fun_mPb_theta.cpp
1 | 1 | #include <stim/image/image.h> |
2 | 2 | #include <cmath> |
3 | -#include <conio.h> | |
3 | +//#include <conio.h> | |
4 | 4 | #include <stim/visualization/colormap.h> |
5 | 5 | #include <stim/image/image_contour_detection.h> |
6 | 6 | |
7 | 7 | void array_multiply(float* lhs, float rhs, unsigned int N); |
8 | 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 | 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 | 18 | stim::image<float> mPb_theta(w, h, 1); |
13 | 19 | |
20 | + //allocate space for each individual channel | |
14 | 21 | stim::image<float> pic_light, pic_colora, pic_colorb; |
15 | 22 | pic_light = lab.channel(0); |
16 | 23 | pic_colora = lab.channel(1); |
17 | 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 | 30 | unsigned r2 = 5; |
24 | 31 | unsigned r3 = 10; |
25 | 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 | 36 | stim::image<float> l1,l2,l3,a1,a2,a3,b1,b2,b3; |
30 | 37 | |
31 | 38 | l1 = gaussian_derivative_filter_odd(pic_light, sigma, sigma_n, r3 * 2, theta, w, h); |
32 | 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 | 43 | stim::cpu2image(l2.data(), "data_output/l2_tex.bmp", w, h, stim::cmBrewer); |
35 | 44 | l3 = gaussian_derivative_filter_odd(pic_light, sigma, sigma_n, r3 * 2, theta, w, h); |
36 | 45 | stim::cpu2image(l3.data(), "data_output/l3_tex.bmp", w, h, stim::cmBrewer); |
... | ... | @@ -45,7 +54,7 @@ stim::image<float> func_mPb_theta(stim::image<float> lab, float theta, unsigned |
45 | 54 | b2 = gaussian_derivative_filter_odd(pic_colorb, sigma, sigma_n, r3 * 2, theta, w, h); |
46 | 55 | stim::cpu2image(b2.data(), "data_output/b2_tex.bmp", w, h, stim::cmBrewer); |
47 | 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 | 59 | /*for (unsigned i = 0; i<N; i++){ |
51 | 60 | |
... | ... | @@ -90,4 +99,4 @@ stim::image<float> func_mPb_theta(stim::image<float> lab, float theta, unsigned |
90 | 99 | //getch(); |
91 | 100 | |
92 | 101 | return mPb_theta; |
93 | -} | |
94 | 102 | \ No newline at end of file |
103 | +} | ... | ... |
func_mPb.cpp
1 | 1 | #include <stim/image/image.h> |
2 | 2 | #include <cmath> |
3 | -#include <conio.h> | |
3 | +//#include <conio.h> | |
4 | 4 | #include <stim/visualization/colormap.h> |
5 | 5 | #include <stim/image/image_contour_detection.h> |
6 | 6 | #include <sstream> |
... | ... | @@ -62,7 +62,7 @@ stim::image<float> func_mPb(stim::image<float> lab, unsigned int theta_n, unsign |
62 | 62 | double duration2 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; |
63 | 63 | std::cout<<"total time:"<< duration2 <<"s"<<'\n'; |
64 | 64 | |
65 | - getch(); | |
65 | + //getch(); | |
66 | 66 | |
67 | 67 | return mPb; |
68 | 68 | |
... | ... | @@ -132,4 +132,4 @@ stim::image<float> func_mPb(stim::image<float> lab, unsigned int theta_n, unsign |
132 | 132 | |
133 | 133 | |
134 | 134 | |
135 | -} | |
136 | 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 | 12 | // winsize = 2 * r, side of mask = winsize + 1 |
13 | 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 | 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 | 25 | // set parameters |
... | ... | @@ -53,9 +54,9 @@ stim::image<float> gaussian_derivative_filter_odd(stim::image<float> image, floa |
53 | 54 | // 2D convolution |
54 | 55 | //derivative_theta = image.convolve2(mask_theta); |
55 | 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 | 61 | //array_abs(derivative_theta.data(), N); |
61 | 62 | |
... | ... | @@ -85,4 +86,4 @@ stim::image<float> gaussian_derivative_filter_odd(stim::image<float> image, floa |
85 | 86 | |
86 | 87 | return derivative_theta; |
87 | 88 | |
88 | -} | |
89 | 89 | \ No newline at end of file |
90 | +} | ... | ... |
test_main.cpp
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | #include <iostream> |
6 | 6 | |
7 | 7 | |
8 | -void main() | |
8 | +int main() | |
9 | 9 | { |
10 | 10 | stim::image<float> rgb,gaussgradient; //generate an image object |
11 | 11 | |
... | ... | @@ -51,6 +51,6 @@ void main() |
51 | 51 | stim::image<float> mPb; |
52 | 52 | mPb = func_mPb(lab, theta_n, w, h); |
53 | 53 | |
54 | - | |
54 | + return 0; | |
55 | 55 | |
56 | -} | |
57 | 56 | \ No newline at end of file |
57 | +} | ... | ... |