b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
1
2
|
#include <stim/image/image.h>
#include <cmath>
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
3
4
5
6
|
#include <stim/visualization/colormap.h>
#include <stim/image/image_contour_detection.h>
#include <sstream>
|
7fab7a98
Tianshu Cheng
a neat version of...
|
7
|
/// This function evaluates the multicale Pb given an multi-channel image
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
8
|
|
7fab7a98
Tianshu Cheng
a neat version of...
|
9
10
11
12
13
|
/// @param img is the multi-channel image
/// @param theta_n is the number of angles used for computing the gradient
/// @param r is an array of radii for different scaled discs(filters)
/// @param alpha is an array of weights for different scaled discs(filters)
/// @param s is the number of scales
|
6dcc460e
Tianshu Cheng
cPb+tPb
|
14
|
|
7fab7a98
Tianshu Cheng
a neat version of...
|
15
|
stim::image<float> func_mPb(stim::image<float> img, unsigned int theta_n, int* r, float* alpha, int s){
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
16
|
|
7fab7a98
Tianshu Cheng
a neat version of...
|
17
18
|
std::clock_t start; // (optional) set the timer to calculate the total time
start = std::clock(); // (optional) set timer start point
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
19
|
|
7fab7a98
Tianshu Cheng
a neat version of...
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
std::ostringstream ss; // (optional) set the stream to designate the test result file
unsigned int w = img.width(); // get the width of picture
unsigned int h = img.height(); // get the height of picture
unsigned int N = w * h; // get the number of pixels
stim::image<float> mPb_theta(w,h); // allocate space for theta-dependent multicale Pb (mPb_theta)
stim::image<float> mPb(w,h); // allocate space for multicale Pb (mPb)
unsigned size = mPb.size(); // get the size of mPb
memset ( mPb.data(), 0, size * sizeof(float)); // initialize all the pixels of mPb to 0
float* ptr; // set a pointer
ptr = (float*) malloc(size * sizeof(float) * theta_n); // this pointer points to a continuous space allocated to store all the mPb_theta
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
35
|
|
40d11588
Tianshu Cheng
2D inseparable co...
|
36
|
for (unsigned int n = 0; n < theta_n; n++){
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
37
|
|
6dcc460e
Tianshu Cheng
cPb+tPb
|
38
39
|
//ss << "data_output/mPb_theta"<< n << "_0911.bmp"; // (optional) set the name for test result file
//std::string sss = ss.str(); // (optional)
|
7fab7a98
Tianshu Cheng
a neat version of...
|
40
|
float theta = 180 * ((float)n/theta_n); // calculate the even-splited angle for each mPb_theta
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
41
|
|
7fab7a98
Tianshu Cheng
a neat version of...
|
42
|
mPb_theta = func_mPb_theta(img, theta, r, alpha, s); // calculate the mPb_theta
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
43
|
|
7fab7a98
Tianshu Cheng
a neat version of...
|
44
45
|
float* ptr_n = &ptr[ n * w * h * 1 ]; // set a pointer which points to the space for each mPb_theta
mPb_theta.data_noninterleaved(ptr_n); // set this pointer to point to the each mPb_theta
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
46
|
|
7fab7a98
Tianshu Cheng
a neat version of...
|
47
48
|
double duration1 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; // (optional) calculate the time for generating each mPb_theta
std::cout<<"mPb_theta_"<< theta <<" complished time:"<< duration1 <<"s"<<'\n'; // (optional) show this time
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
49
|
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
50
|
|
7fab7a98
Tianshu Cheng
a neat version of...
|
51
52
53
|
unsigned long idx = n * w * h * 1; //index for the nth mPb_theta
|
6dcc460e
Tianshu Cheng
cPb+tPb
|
54
|
//stim::cpu2image(mPb_theta.data(), sss, w, h, stim::cmBrewer); // (optional) output the nth mPb_theta
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
55
56
57
|
for(unsigned long i = 0; i < N; i++){
|
7fab7a98
Tianshu Cheng
a neat version of...
|
58
|
float pixel = ptr[i+idx]; //get the ith pixel in nth mPb_theta
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
59
|
|
7fab7a98
Tianshu Cheng
a neat version of...
|
60
|
if(pixel > mPb.data()[i]){ //get the maximum value among all mPb_theta for ith pixel
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
61
62
63
64
65
66
67
68
|
mPb.data()[i] = pixel;
}
else{
}
}
|
6dcc460e
Tianshu Cheng
cPb+tPb
|
69
|
//ss.str(""); //(optional) clear the space for stream
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
70
|
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
71
72
|
}
|
6dcc460e
Tianshu Cheng
cPb+tPb
|
73
|
stim::cpu2image(mPb.data(), "data_output/mPb_500_0914_neat.bmp", w, h, stim::cmBrewer); // output the mPb
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
74
|
|
7fab7a98
Tianshu Cheng
a neat version of...
|
75
76
|
double duration2 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; // (optional) calculate the total time
std::cout<<"total time:"<< duration2 <<"s"<<'\n'; // (optional) show the total time
|
b71cc8bb
Tianshu Cheng
mPb using 3 channels
|
77
78
79
|
return mPb;
|
abaf5630
David Mayerich
fixed the signed/...
|
80
|
}
|