018b00d6
David Mayerich
adapted bsds500 f...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#ifndef STIM_CUDA_PB_CUH
#define STIM_CUDA_PB_CUH
#include <stim/image/image.h>
//#include <cmath>
#include <stim/visualization/colormap.h>
//#include <stim/image/image_contour_detection.h>
#include "dG1_conv2.cuh"
#include <stim/cuda/arraymath/array_abs.cuh>
#include <stim/cuda/arraymath/array_divide.cuh>
#include <stim/cuda/arraymath/array_atan.cuh>
#include <stim/cuda/arraymath/array_atan2.cuh>
#include <stim/cuda/arraymath/array_cos.cuh>
#include <stim/cuda/arraymath/array_sin.cuh>
#include <stim/cuda/arraymath/array_multiply.cuh>
#include <stim/cuda/arraymath/array_add.cuh>
#define SIGMA_N 3
//void array_abs(float* img, unsigned int N);
//void array_multiply(float* lhs, float rhs, unsigned int N);
//void array_cos(float* ptr1, float* cpu_out, unsigned int N);
//void array_sin(float* ptr1, float* cpu_out, unsigned int N);
//void array_atan(float* ptr1, float* cpu_out, unsigned int N);
//void array_divide(float* ptr1, float* ptr2,float* cpu_quotient, unsigned int N);
//void array_multiply(float* ptr1, float* ptr2, float* product, unsigned int N);
//void array_add(float* ptr1, float* ptr2, float* sum, unsigned int N);
/// This function uses odd-symmetric gaussian derivative filter to evaluate
/// the max probability of a contour on one scale, given an one-channel image
/// @param img is an one-channel image
/// @param r is an array of radii for different scaled discs(filters)
/// @param sigma_n is the number of standard deviations used to define the sigma
stim::image<float> Pb(stim::image<float> image, int sigma){
unsigned int w = image.width(); // get the width of picture
unsigned int h = image.height(); // get the height of picture
unsigned N = w * h; // get the number of pixels of picture
stim::image<float> I(w, h, 1, 2); // allocate space for return image of dG1_conv2
stim::image<float> theta(w, h); // allocate space for theta matrix
stim::image<float> cos(w, h); // allocate space for cos(theta)
stim::image<float> sin(w, h); // allocate space for sin(theta)
stim::image<float> temp(w, h); // allocate space for temp
stim::image<float> Ix(w, h); // allocate space for Ix
stim::image<float> Iy(w, h); // allocate space for Iy
stim::image<float> Pb(w, h); // allocate space for Pb
I = dG1_conv2(image, sigma); // calculate the Ix, Iy
Ix = I.channel(0);
stim::cuda::cpu_abs(Ix.data(), N); //get |Ix|;
//stim::cpu2image(Ix.data(), "data_output/Pb_Ix_0924.bmp", w, h, stim::cmBrewer);
Iy = I.channel(1);
stim::cuda::cpu_abs(Iy.data(), N); //get |Iy|;
//stim::cpu2image(Iy.data(), "data_output/Pb_Iy_0924.bmp", w, h, stim::cmBrewer);
//stim::cuda::cpu_divide(Iy.data(), Ix.data(), theta.data(), N); //temp = Iy./Ix
stim::cuda::cpu_atan2(Iy.data(), Ix.data(), theta.data(), N); //temp = Iy./Ix
//stim::cuda::cpu_atan(temp.data(), theta.data(), N); //theta = atan(temp)
stim::cuda::cpu_cos(theta.data(), cos.data(), N); //cos = cos(theta)
stim::cuda::cpu_sin(theta.data(), sin.data(), N); //sin = sin(theta)
stim::cuda::cpu_multiply(Ix.data(), cos.data(), Ix.data(), N); //Ix = Ix.*cos
stim::cuda::cpu_multiply(Iy.data(), sin.data(), Iy.data(), N); //Iy = Iy.*sin
stim::cuda::cpu_add(Ix.data(), Iy.data(), Pb.data(), N); //Pb = Ix + Iy;
float max = Pb.maxv(); // get the maximum of Pb used for normalization
stim::cuda::cpu_multiply(Pb.data(), 1/max, N); // normalize the Pb
//stim::cpu2image(Pb.data(), "data_output/Pb_0924.bmp", w, h, stim::cmBrewer); show the Pb(optional)
return Pb;
}
#endif
|