From afb1883de8958319b58e681623a35d7e1191191a Mon Sep 17 00:00:00 2001 From: Tianshu Cheng Date: Thu, 8 Oct 2015 18:05:10 -0500 Subject: [PATCH] fixed problem about sigma --- stim/cuda/bsds500/Pb.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ stim/cuda/bsds500/cPb.cpp | 13 ++++++------- stim/cuda/bsds500/dG1_conv2.cpp | 11 ++++++----- stim/cuda/bsds500/dG1_theta_conv2.cpp | 30 +++++++++++++++++------------- stim/cuda/bsds500/dG2_conv2.cpp | 11 ++++++----- stim/cuda/bsds500/dG2_d2x_theta_conv2.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ stim/cuda/bsds500/kmeans.cpp | 2 +- stim/cuda/bsds500/laplacian_conv2.cpp | 20 +++++++++++--------- stim/cuda/bsds500/main.cpp | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ stim/cuda/bsds500/tPb.cpp | 2 +- stim/cuda/bsds500/textons.cpp | 13 ++++--------- stim/image/image_contour_detection.h | 14 +++++++------- 12 files changed, 297 insertions(+), 57 deletions(-) create mode 100644 stim/cuda/bsds500/Pb.cpp create mode 100644 stim/cuda/bsds500/dG2_d2x_theta_conv2.cpp create mode 100644 stim/cuda/bsds500/main.cpp diff --git a/stim/cuda/bsds500/Pb.cpp b/stim/cuda/bsds500/Pb.cpp new file mode 100644 index 0000000..c4ec506 --- /dev/null +++ b/stim/cuda/bsds500/Pb.cpp @@ -0,0 +1,65 @@ +#include +//#include +#include +#include + +#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 Pb(stim::image 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 + + int r = SIGMA_N * sigma; // set the radius of filter + int winsize = 2 * r + 1; // set the winsdow size of filter + + stim::image I(w, h, 1, 2); // allocate space for return image of dG1_conv2 + stim::image theta(w, h); // allocate space for theta matrix + stim::image cos(w, h); // allocate space for cos(theta) + stim::image sin(w, h); // allocate space for sin(theta) + stim::image temp(w, h); // allocate space for temp + stim::image Ix(w, h); // allocate space for Ix + stim::image Iy(w, h); // allocate space for Iy + stim::image Pb(w, h); // allocate space for Pb + + I = dG1_conv2(image, sigma); // calculate the Ix, Iy + Ix = I.channel(0); + array_abs(Ix.data(), N); //get |Ix|; + //stim::cpu2image(Ix.data(), "data_output/Pb_Ix_0924.bmp", w, h, stim::cmBrewer); + Iy = I.channel(1); + array_abs(Iy.data(), N); //get |Iy|; + //stim::cpu2image(Iy.data(), "data_output/Pb_Iy_0924.bmp", w, h, stim::cmBrewer); + + array_divide(Iy.data(), Ix.data(), temp.data(), N); //temp = Iy./Ix + array_atan(temp.data(), theta.data(), N); //theta = atan(temp) + array_cos(theta.data(), cos.data(), N); //cos = cos(theta) + array_sin(theta.data(), sin.data(), N); //sin = sin(theta) + array_multiply(Ix.data(), cos.data(), Ix.data(), N); //Ix = Ix.*cos + array_multiply(Iy.data(), sin.data(), Iy.data(), N); //Iy = Iy.*sin + array_add(Ix.data(), Iy.data(), Pb.data(), N); //Pb = Ix + Iy; + + float max = Pb.maxv(); // get the maximum of Pb used for normalization + array_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; + +} \ No newline at end of file diff --git a/stim/cuda/bsds500/cPb.cpp b/stim/cuda/bsds500/cPb.cpp index 3d9f23c..f8f1388 100644 --- a/stim/cuda/bsds500/cPb.cpp +++ b/stim/cuda/bsds500/cPb.cpp @@ -15,7 +15,7 @@ void array_add(float* ptr1, float* ptr2, float* sum, unsigned int N); /// @param alpha is is an array of weights for different scaled discs(filters) /// @param s is the number of scales -stim::image cPb(stim::image img, int* r, float* alpha, int s){ +stim::image cPb(stim::image img, int* sigma, float* alpha, int s){ unsigned int w = img.width(); // get the width of picture unsigned int h = img.height(); // get the height of picture @@ -28,20 +28,19 @@ stim::image cPb(stim::image img, int* r, float* alpha, int s){ unsigned int N = w * h; // get the number of pixels - int sigma_n = 3; // set the number of standard deviations used to define the sigma - std::ostringstream ss; // (optional) set the stream to designate the test result file + //std::ostringstream ss; // (optional) set the stream to designate the test result file stim::image temp; // set the temporary image to store the addtion result for (int i = 0; i < c; i++){ for (int j = 0; j < s; j++){ - ss << "data_output/cPb_slice"<< i*s + j << ".bmp"; // set the name for test result file (optional) - std::string sss = ss.str(); + //ss << "data_output/cPb_slice"<< i*s + j << ".bmp"; // set the name for test result file (optional) + //std::string sss = ss.str(); // get the gaussian gradient by convolving each image slice with the mask - temp = Pb(img.channel(i), r[i*s + j], sigma_n); + temp = Pb(img.channel(i), sigma[i*s + j]); // output the test result of each slice (optional) //stim::cpu2image(temp.data(), sss, w, h, stim::cmBrewer); @@ -52,7 +51,7 @@ stim::image cPb(stim::image img, int* r, float* alpha, int s){ // add up all the weighted gaussian gradients array_add(cPb.data(), temp.data(), cPb.data(), N); - ss.str(""); //(optional) clear the space for stream + //ss.str(""); //(optional) clear the space for stream } } diff --git a/stim/cuda/bsds500/dG1_conv2.cpp b/stim/cuda/bsds500/dG1_conv2.cpp index ed50990..4e98709 100644 --- a/stim/cuda/bsds500/dG1_conv2.cpp +++ b/stim/cuda/bsds500/dG1_conv2.cpp @@ -2,25 +2,26 @@ //#include #include #include +#define SIGMA_N 3 /// This function generates the first-order gaussian derivative filter gx gy, /// convolves the image with gx gy, /// and returns an image class which channel(0) is Ix and channel(1) is Iy /// @param img is the 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 +/// @param sigma is the parameter for gaussian function void conv2_sep(float* img, unsigned int x, unsigned int y, float* kernel0, unsigned int k0, float* kernel1, unsigned int k1); //void array_abs(float* img, unsigned int N); -stim::image Gd1(stim::image image, int r, unsigned int sigma_n){ +stim::image dG1_conv2(stim::image 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 - int winsize = 2 * r + 1; // set the winsdow size of disc(filter) - float sigma = float(r)/float(sigma_n); // calculate the sigma used in gaussian function + + int r = SIGMA_N * sigma; + int winsize = 2 * SIGMA_N * sigma + 1; // set the winsdow size of filter stim::image I(w, h, 1, 2); // allocate space for return image class stim::image Ix(w, h); // allocate space for Ix diff --git a/stim/cuda/bsds500/dG1_theta_conv2.cpp b/stim/cuda/bsds500/dG1_theta_conv2.cpp index b1ea9aa..99c29fb 100644 --- a/stim/cuda/bsds500/dG1_theta_conv2.cpp +++ b/stim/cuda/bsds500/dG1_theta_conv2.cpp @@ -4,6 +4,7 @@ #include #define PI 3.1415926 +#define SIGMA_N 3 void array_multiply(float* lhs, float rhs, unsigned int N); void array_add(float* ptr1, float* ptr2, float* sum, unsigned int N); @@ -16,33 +17,36 @@ void array_abs(float* img, unsigned int N); /// @param sigma_n is the number of standard deviations used to define the sigma /// @param theta is angle used for computing the gradient -stim::image Gd_odd(stim::image image, int r, unsigned int sigma_n, float theta){ +stim::image dG1_theta_conv2(stim::image image, int sigma, float theta){ float theta_r = (theta * PI)/180; //change angle unit from degree to rad unsigned int w = image.width(); // get the width of picture unsigned int h = image.height(); // get the height of picture + + int r = SIGMA_N * sigma; unsigned N = w * h; // get the number of pixels of picture - int winsize = 2 * r + 1; // set the winsdow size of disc(filter) - stim::image I(w, h, 1, 2); // allocate space for return image of Gd1 - stim::image Ix(w, h); // allocate space for Ix - stim::image Iy(w, h); // allocate space for Iy - stim::image Gd_odd_theta(w, h); // allocate space for Pb + int winsize = 2 * SIGMA_N * sigma + 1; // set the winsdow size of filter + + stim::image I(w, h, 1, 2); // allocate space for return image of dG1_conv2 + stim::image Ix(w, h); // allocate space for Ix + stim::image Iy(w, h); // allocate space for Iy + stim::image dG1_theta(w, h); // allocate space for Pb - I = Gd1(image, r, sigma_n); // calculate the Ix, Iy + I = dG1_conv2(image, sigma); // calculate the Ix, Iy Ix = I.channel(0); Iy = I.channel(1); array_multiply(Ix.data(), cos(theta_r), N); //Ix = Ix*cos(theta_r) array_multiply(Iy.data(), sin(theta_r), N); //Iy = Iy*sin(theta_r) - array_add(Ix.data(), Iy.data(), Gd_odd_theta.data(), N); //Gd_odd_theta = Ix + Iy; - array_abs(Gd_odd_theta.data(), N); + array_add(Ix.data(), Iy.data(), dG1_theta.data(), N); //dG1_theta = Ix + Iy; + array_abs(dG1_theta.data(), N); - //stim::cpu2image(I.channel(0).data(), "data_output/Gd_odd_x_0919.bmp", w, h, stim::cmBrewer); - //stim::cpu2image(I.channel(1).data(), "data_output/Gd_odd_y_0919.bmp", w, h, stim::cmBrewer); - //stim::cpu2image(Gd_odd_theta.data(), "data_output/Gd_odd_theta_0919.bmp", w, h, stim::cmBrewer); + //stim::cpu2image(I.channel(0).data(), "data_output/dG1_theta_x_0919.bmp", w, h, stim::cmBrewer); + //stim::cpu2image(I.channel(1).data(), "data_output/dG1_theta_y_0919.bmp", w, h, stim::cmBrewer); + //stim::cpu2image(dG1_theta.data(), "data_output/dG1_theta_0919.bmp", w, h, stim::cmBrewer); - return Gd_odd_theta; + return dG1_theta; } diff --git a/stim/cuda/bsds500/dG2_conv2.cpp b/stim/cuda/bsds500/dG2_conv2.cpp index 85414b1..cb92322 100644 --- a/stim/cuda/bsds500/dG2_conv2.cpp +++ b/stim/cuda/bsds500/dG2_conv2.cpp @@ -2,25 +2,26 @@ //#include #include #include +#define SIGMA_N 3 /// This function generates the second-order gaussian derivative filter gxx gyy, /// convolves the image with gxx gyy, /// and returns an image class which channel(0) is Ixx and channel(1) is Iyy /// @param img is the 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 +/// @param sigma is the parameter for gaussian function void conv2_sep(float* img, unsigned int x, unsigned int y, float* kernel0, unsigned int k0, float* kernel1, unsigned int k1); //void array_abs(float* img, unsigned int N); -stim::image Gd2(stim::image image, int r, unsigned int sigma_n){ +stim::image dG2_conv2(stim::image 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 - int winsize = 2 * r + 1; // set the winsdow size of disc(filter) - float sigma = float(r)/float(sigma_n); // calculate the sigma used in gaussian function + + int winsize = 2 * SIGMA_N * sigma + 1; // set the winsdow size of filter + int r = SIGMA_N * sigma; stim::image I(w, h, 1, 2); // allocate space for return image class stim::image Ixx(w, h); // allocate space for Ixx diff --git a/stim/cuda/bsds500/dG2_d2x_theta_conv2.cpp b/stim/cuda/bsds500/dG2_d2x_theta_conv2.cpp new file mode 100644 index 0000000..13ce010 --- /dev/null +++ b/stim/cuda/bsds500/dG2_d2x_theta_conv2.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +#define SIGMA_N 3 + +/// This function evaluates the theta-dependent even-symmetric gaussian derivative gradient of an one-channel image + +/// @param img is the 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 +/// @param theta is angle used for computing the gradient + +void conv2(float* img, float* mask, float* cpu_copy, unsigned int w, unsigned int h, unsigned int M); +void array_abs(float* img, unsigned int N); + +stim::image dG2_d2x_theta_conv2(stim::image image, int sigma, float theta){ + + 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 + + int r = SIGMA_N * sigma; // set the radius of filter + int winsize = 2 * SIGMA_N * sigma + 1; // set the winsdow size of filter + + stim::image I(w, h, 1, 2); // allocate space for return image class + stim::image dG2_d2x_theta(w, h); // allocate space for dG2_d2x_theta + stim::image mask_x(winsize, winsize); // allocate space for x-axis-oriented filter + stim::image mask_r(winsize, winsize); // allocate space for theta-oriented filter + + for (int j = 0; j < winsize; j++){ + for (int i = 0; i< winsize; i++){ + + int x = i - r; //range of x + int y = j - r; //range of y + + // create the x-oriented gaussian derivative filter mask_x + mask_x.data()[j*winsize + i] = (-1) * (1 - pow(x, 2)) * exp((-1)*(pow(x, 2))/(2*pow(sigma, 2))) * exp((-1)*(pow(y, 2))/(2*pow(sigma, 2))); + + } + } + + mask_r = mask_x.rotate(theta, r, r); + //mask_r = mask_x.rotate(45, r, r); + //stim::cpu2image(mask_r.data(), "data_output/mask_r_0919.bmp", winsize, winsize, stim::cmBrewer); + + // do the 2D convolution with image and mask + conv2(image.data(), mask_r.data(), dG2_d2x_theta.data(), w, h, winsize); + array_abs(dG2_d2x_theta.data(), N); + + //stim::cpu2image(dG2_d2x_theta.data(), "data_output/dG2_d2x_theta_0919.bmp", w, h, stim::cmGrayscale); + + return dG2_d2x_theta; +} \ No newline at end of file diff --git a/stim/cuda/bsds500/kmeans.cpp b/stim/cuda/bsds500/kmeans.cpp index fee17b7..083cae8 100644 --- a/stim/cuda/bsds500/kmeans.cpp +++ b/stim/cuda/bsds500/kmeans.cpp @@ -8,7 +8,7 @@ /// This function use cvkmeans to cluster given textons /// @param testons is a multi-channel image -/// @param k is the number of clusters +/// @param K is the number of clusters stim::image kmeans(stim::image textons, unsigned int K){ diff --git a/stim/cuda/bsds500/laplacian_conv2.cpp b/stim/cuda/bsds500/laplacian_conv2.cpp index 4b41d0d..e773e94 100644 --- a/stim/cuda/bsds500/laplacian_conv2.cpp +++ b/stim/cuda/bsds500/laplacian_conv2.cpp @@ -4,6 +4,7 @@ #include #define PI 3.1415926 +#define SIGMA_N 3 void array_multiply(float* lhs, float rhs, unsigned int N); void array_add(float* ptr1, float* ptr2, float* sum, unsigned int N); @@ -15,27 +16,28 @@ void array_abs(float* img, unsigned int N); /// @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 Gd_center(stim::image image, int r, unsigned int sigma_n){ +stim::image laplacian_conv2(stim::image 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 - int winsize = 2 * r + 1; // set the winsdow size of disc(filter) + + int winsize = 2 * SIGMA_N * sigma + 1; // set the winsdow size of filter - stim::image I(w, h, 1, 2); // allocate space for return image of Gd2 + stim::image I(w, h, 1, 2); // allocate space for return image of dG2_conv2 stim::image Ixx(w, h); // allocate space for Ixx stim::image Iyy(w, h); // allocate space for Iyy - stim::image Gd_center(w, h); // allocate space for Pb + stim::image laplacian(w, h); // allocate space for Pb - I = Gd2(image, r, sigma_n); // calculate the Ixx, Iyy + I = dG2_conv2(image, sigma); // calculate the Ixx, Iyy Ixx = I.channel(0); Iyy = I.channel(1); - array_add(Ixx.data(), Iyy.data(), Gd_center.data(), N); //Gd_center = Ixx + Iyy; - array_abs(Gd_center.data(), N); + array_add(Ixx.data(), Iyy.data(), laplacian.data(), N); //laplacian = Ixx + Iyy; + array_abs(laplacian.data(), N); - //stim::cpu2image(Gd_center.data(), "data_output/Gd_center_0919.bmp", w, h, stim::cmBrewer); + //stim::cpu2image(laplacian.data(), "data_output/laplacian_0919.bmp", w, h, stim::cmBrewer); - return Gd_center; + return laplacian; } diff --git a/stim/cuda/bsds500/main.cpp b/stim/cuda/bsds500/main.cpp new file mode 100644 index 0000000..ddea1b6 --- /dev/null +++ b/stim/cuda/bsds500/main.cpp @@ -0,0 +1,118 @@ +#include +#include +#include +#include +#include +#include +#include +/// calculate the cPb, tPb and mPb given a multi-channel image + +void array_multiply(float* lhs, float rhs, unsigned int N); +void array_add(float* ptr1, float* ptr2, float* sum, unsigned int N); + +int main() +{ + stim::image image; // generate an image object + + //std::ostringstream ss1,ss2; // (optional) set the stream to designate the test result file + + //for(unsigned int i = 27; i < 31; i++){ + + //ss1 << "3d_sample/b0"<< i << ".bmp"; // (optional) set the name for test result file + //std::string sss1 = ss1.str(); // (optional) + + //image.load("bone1001_3.bmp"); + //image.load(sss1); + //image.load("101085.bmp"); // load the input image + image.load("slice00_500_500.bmp"); // load the input image + image = image.channel(0); // get the first channel of black-and-white image + + + unsigned int w = image.width(); // get the width of picture + unsigned int h = image.height(); // get the height of picture + unsigned int N = w * h; // get the number of pixels + int c = image.channels(); // get the number if channels of picture + int s = 3; // set the number of scales + int sigma[3] = {1,2,3}; // set an array of sigmas for different scaled gaussian filters for cPb, the length of array is c*s + int r[3] = {5,10,20}; // set an array of radii for different scaled discs(filters) for tPb, the length of array is c*s + float alpha[3] = {1,1,1}; // set an array of weights for different scaled discs(filters) + unsigned int theta_n = 8; // set the number of angles used in filter orientation + unsigned int bin_n = 16; // set the number of bins used in chi-distance + unsigned int K = 16; // set the number of cludters, K should be multiple of bin_n + + stim::image img_cPb(w, h); // allocate the space for cPb + stim::image img_tPb(w, h); // allocate the space for tPb + stim::image img_mPb(w, h); // allocate the space for tPb + + std::cout<<"imagesize: "<< w <<"*"<< h <<'\n'; + + //*******************cPb******************** + std::clock_t start1; // (optional) set the timer to calculate the total time + start1 = std::clock(); // (optional) set timer start point + + std::cout<<"begin cPb"<<'\n'; + + img_cPb = cPb(image, sigma, alpha, s); + + // show the cPb (optional) + stim::cpu2image(img_cPb.data(), "data_output/img_cPb_1008.bmp", w, h, stim::cmBrewer); + //ss2 << "3d_sample/cPb0"<< i << ".bmp"; // (optional) set the name for test result file + //std::string sss2 = ss2.str(); + + //stim::cpu2image(img_cPb.data(), "data_output/bone_cPb3.1.bmp", w, h, stim::cmBrewer); + + double duration1 = ( std::clock() - start1 ) / (double) CLOCKS_PER_SEC; // (optional) calculate the total time + std::cout<<"cPb time: "<< duration1 <<"s"<<'\n'; // (optional) show the total time + + //ss1.str(""); //(optional) clear the space for stream + //ss2.str(""); //(optional) clear the space for stream + + + //*******************tPb******************** + + std::cout<<"begin tPb"<<'\n'; + + + std::clock_t start2; // (optional) set the timer to calculate the total time + start2 = std::clock(); // (optional) set timer start point + + img_tPb = tPb(image, r, alpha, theta_n, bin_n, s, K); + + // show the tPb (optional) + // stim::cpu2image(img_tPb.data(), "data_output/bone_tPb_3.1.bmp", w, h, stim::cmBrewer); + stim::cpu2image(img_tPb.data(), "data_output/img_tPb_1008.bmp", w, h, stim::cmBrewer); + + double duration2 = ( std::clock() - start2 ) / (double) CLOCKS_PER_SEC; // (optional) calculate the total time + std::cout<<"tPb time: "<< duration2 <<"s"<<'\n'; // (optional) show the total time + + + //******************************************* + + double duration3 = ( std::clock() - start1 ) / (double) CLOCKS_PER_SEC; // (optional) calculate the total time + std::cout<<"total running time: "<< duration3 <<"s"<<'\n'; // (optional) show the total time + //} + //******************mPb********************** + // set parameters for linear combination + + float a = 1; + float b = 0.5; + + // create mPb by linearly combined cPb and tPb + array_multiply(img_cPb.data(), a, N); + array_multiply(img_tPb.data(), b, N); + array_add(img_cPb.data(), img_tPb.data(), img_mPb.data(), N); + + //ss2 << "3d_sample/mPb0"<< i << ".bmp"; // (optional) set the name for test result file + //std::string sss2 = ss2.str(); + // show the mPb (optional) + stim::cpu2image(img_mPb.data(), "data_output/img_mPb_1008.bmp", w, h, stim::cmBrewer); + + //stim::cpu2image(img_mPb.data(), sss2, w, h, stim::cmBrewer); + + //ss1.str(""); //(optional) clear the space for stream + //ss2.str(""); //(optional) clear the space for stream + + //} + return 0; + +} diff --git a/stim/cuda/bsds500/tPb.cpp b/stim/cuda/bsds500/tPb.cpp index e066dae..bc1a44a 100644 --- a/stim/cuda/bsds500/tPb.cpp +++ b/stim/cuda/bsds500/tPb.cpp @@ -39,7 +39,7 @@ stim::image tPb(stim::image img, int* r, float* alpha, unsigned in img_texture = kmeans(img_textons, K); // changing kmeans result into float type is required - stim::cpu2image(img_texture.data(), "data_output/texture_0925.bmp", w, h, stim::cmBrewer); + stim::cpu2image(img_texture.data(), "data_output/texture.bmp", w, h, stim::cmBrewer); unsigned int max1 = img_texture.maxv(); // get the maximum of Pb used for normalization diff --git a/stim/cuda/bsds500/textons.cpp b/stim/cuda/bsds500/textons.cpp index dbe66f1..484b27d 100644 --- a/stim/cuda/bsds500/textons.cpp +++ b/stim/cuda/bsds500/textons.cpp @@ -19,12 +19,7 @@ stim::image textons(stim::image image, unsigned int theta_n){ stim::image textons(w, h, 1, theta_n*2+1); // allocate space for textons stim::image temp(w, h); // allocate space for temp - unsigned int r_odd = 3; // set disc radii for odd-symmetric filter - unsigned int sigma_n_odd = 3; // set sigma_n for odd-symmetric filter - unsigned int r_even = 3; // set disc radii for even-symmetric filter - unsigned int sigma_n_even = 3; // set sigma_n for even-symmetric filter - unsigned int r_center = 3; // set disc radii for center-surround filter - unsigned int sigma_n_center = 3; // set sigma_n for center-surround filter + int sigma = 1; // set sigma for odd-symmetric, even-symmetric and center-surround filter filter //std::ostringstream ss1, ss2; // (optional) set the stream to designate the test result file @@ -37,11 +32,11 @@ stim::image textons(stim::image image, unsigned int theta_n){ float theta = 180 * ((float)i/theta_n); // calculate the even-splited angle for each oriented filter - temp = Gd_odd(image, r_odd, sigma_n_odd, theta); // return Gd_odd to temp + temp = dG1_theta_conv2(image, sigma, theta); // return dG1_theta_conv2 to temp //stim::cpu2image(temp.data(), sss1, w, h, stim::cmBrewer); textons.set_channel(i, temp.data()); // copy temp to ith channel of textons - temp = Gd_even(image, r_even, sigma_n_even, theta); // return Gd_even to temp + temp = dG2_d2x_theta_conv2(image, sigma, theta); // return dG2_d2x_theta_conv2 to temp //stim::cpu2image(temp.data(), sss2, w, h, stim::cmBrewer); textons.set_channel(i + theta_n, temp.data()); // copy temp to (i+theta_n)th channel of textons @@ -50,7 +45,7 @@ stim::image textons(stim::image image, unsigned int theta_n){ } - temp = Gd_center(image, r_center, sigma_n_center); // return Gd_center to temp + temp = laplacian_conv2(image, sigma); // return laplacian_conv2 to temp //stim::cpu2image(temp.data(), "data_output/textons_channel_16.bmp", w, h, stim::cmBrewer); textons.set_channel(theta_n*2, temp.data()); // copy temp to (theta_n*2)th channel of textons diff --git a/stim/image/image_contour_detection.h b/stim/image/image_contour_detection.h index 055d06a..60e6d03 100644 --- a/stim/image/image_contour_detection.h +++ b/stim/image/image_contour_detection.h @@ -3,14 +3,14 @@ //stim::image func_mPb_theta(stim::image img, float theta, int* r, float* alpha, int s); //stim::image func_mPb(stim::image img, unsigned int theta_n, int* r, float* alpha, int s); -stim::image Gd1(stim::image image, int r, unsigned int sigma_n); -stim::image Gd2(stim::image image, int r, unsigned int sigma_n); -stim::image Gd_odd(stim::image image, int r, unsigned int sigma_n, float theta); -stim::image Gd_even(stim::image image, int r, unsigned int sigma_n, float theta); -stim::image Gd_center(stim::image image, int r, unsigned int sigma_n); +stim::image dG1_conv2(stim::image image, int sigma); +stim::image dG2_conv2(stim::image image, int sigma); +stim::image dG1_theta_conv2(stim::image image, int sigma, float theta); +stim::image dG2_d2x_theta_conv2(stim::image image, int sigma, float theta); +stim::image laplacian_conv2(stim::image image, int sigma); stim::image textons(stim::image image, unsigned int theta_n); stim::image kmeans(stim::image textons, unsigned int K); -stim::image Pb(stim::image image, int r, unsigned int sigma_n); -stim::image cPb(stim::image img, int* r, float* alpha, int s); +stim::image Pb(stim::image image, int sigma); +stim::image cPb(stim::image img, int* sigma, float* alpha, int s); stim::image tPb(stim::image img, int* r, float* alpha, unsigned int theta_n, unsigned int bin_n, int s, unsigned int K); \ No newline at end of file -- libgit2 0.21.4