Commit b71cc8bb1b8f43b4339e5865ef2792a0624de9d5

Authored by Tianshu Cheng
0 parents

mPb using 3 channels

CMakeLists.txt 0 → 100644
  1 +++ a/CMakeLists.txt
  1 +#Specify the version being used aswell as the language
  2 +cmake_minimum_required(VERSION 2.8.11)
  3 +
  4 +#Name your project here
  5 +project(bsds500)
  6 +
  7 +#set the module directory
  8 +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
  9 +
  10 +#set up CUDA
  11 +find_package(CUDA REQUIRED)
  12 +
  13 +#find the STIM library
  14 +find_package(STIM REQUIRED)
  15 +
  16 +#find the pthreads package
  17 +find_package(Threads)
  18 +
  19 +#find the X11 package
  20 +find_package(X11)
  21 +
  22 +include_directories(
  23 + ${STIM_INCLUDE_DIRS}
  24 + )
  25 +
  26 +#Assign source files to the appropriate variables
  27 +file(GLOB SRC_CPP "*.cpp")
  28 +file(GLOB SRC_H "*.h")
  29 +file(GLOB SRC_CU "*.cu")
  30 +file(GLOB SRC_CUH "*.cuh")
  31 +
  32 +#create an executable file
  33 +cuda_add_executable(bsds500
  34 + ${SRC_H}
  35 + ${SRC_CPP}
  36 + ${SRC_CU}
  37 + ${SRC_CUH}
  38 + )
  39 +
  40 +#set the link libraries
  41 +target_link_libraries(bsds500
  42 + #${CUDA_cufft_LIBRARY}
  43 + #${CUDA_cublas_LIBRARY}
  44 + ${CMAKE_THREAD_LIBS_INIT}
  45 + ${X11_LIBRARIES}
  46 + )
  47 +
  48 +#copy an image test case
  49 +configure_file(data/101085.bmp 101085.bmp COPYONLY)
  50 +configure_file(data/101087.bmp 101087.bmp COPYONLY)
... ...
FindSTIM.cmake 0 → 100644
  1 +++ a/FindSTIM.cmake
  1 +include(FindPackageHandleStandardArgs)
  2 +
  3 +set(STIM_INCLUDE_DIR $ENV{STIMLIB_PATH})
  4 +
  5 +find_package_handle_standard_args(STIM DEFAULT_MSG STIM_INCLUDE_DIR)
  6 +
  7 +if(STIM_FOUND)
  8 + set(STIM_INCLUDE_DIRS ${STIM_INCLUDE_DIR})
  9 +endif()
0 10 \ No newline at end of file
... ...
cudafunc.cu 0 → 100644
  1 +++ a/cudafunc.cu
  1 +#include <stim/cuda/gaussian_blur.cuh>
  2 +
  3 +void blur(float* image, float sigma, unsigned int x, unsigned int y){
  4 +
  5 + stim::cuda::cpu_gaussian_blur_2d<float>(image, sigma, x, y);
  6 +}
0 7 \ No newline at end of file
... ...
data/101085.bmp 0 → 100644
No preview for this file type
data/101087.bmp 0 → 100644
No preview for this file type
fun_mPb_theta.cpp 0 → 100644
  1 +++ a/fun_mPb_theta.cpp
  1 +#include <stim/image/image.h>
  2 +#include <cmath>
  3 +#include <conio.h>
  4 +#include <stim/visualization/colormap.h>
  5 +#include <stim/image/image_contour_detection.h>
  6 +
  7 +stim::image<float> func_mPb_theta(stim::image<float> lab, float theta, unsigned int w, unsigned int h){
  8 +
  9 + stim::image<float> mPb_theta(w, h, 1);
  10 +
  11 + stim::image<float> pic_light, pic_colora, pic_colorb;
  12 + pic_light = lab.channel(0);
  13 + pic_colora = lab.channel(1);
  14 + pic_colorb = lab.channel(2);
  15 +
  16 + unsigned int N = w * h;
  17 + float sigma = 2;
  18 + unsigned int sigma_n = 3;
  19 + unsigned r1 = 3;
  20 + unsigned r2 = 5;
  21 + unsigned r3 = 10;
  22 + unsigned r4 = 20;
  23 + float alpha[9] = {1,1,1,1,1,1,1,1,1};
  24 +
  25 +
  26 + stim::image<float> l1,l2,l3,a1,a2,a3,b1,b2,b3;
  27 +
  28 + l1 = gaussian_derivative_filter_odd(pic_light, sigma, sigma_n, r1 * 2, theta, w, h);
  29 + l2 = gaussian_derivative_filter_odd(pic_light, sigma, sigma_n, r2 * 2, theta, w, h);
  30 + l3 = gaussian_derivative_filter_odd(pic_light, sigma, sigma_n, r3 * 2, theta, w, h);
  31 + a1 = gaussian_derivative_filter_odd(pic_colora, sigma, sigma_n, r2 * 2, theta, w, h);
  32 + a2 = gaussian_derivative_filter_odd(pic_colora, sigma, sigma_n, r3 * 2, theta, w, h);
  33 + a3 = gaussian_derivative_filter_odd(pic_colora, sigma, sigma_n, r4 * 2, theta, w, h);
  34 + b1 = gaussian_derivative_filter_odd(pic_colorb, sigma, sigma_n, r2 * 2, theta, w, h);
  35 + b2 = gaussian_derivative_filter_odd(pic_colorb, sigma, sigma_n, r3 * 2, theta, w, h);
  36 + b3 = gaussian_derivative_filter_odd(pic_colorb, sigma, sigma_n, r4 * 2, theta, w, h);
  37 +
  38 + for (unsigned i = 0; i<N; i++){
  39 +
  40 + mPb_theta.data()[i] = l1.data()[i] * alpha[0] +
  41 + l2.data()[i] * alpha[1] +
  42 + l3.data()[i] * alpha[2] +
  43 + a1.data()[i] * alpha[3] +
  44 + a2.data()[i] * alpha[4] +
  45 + a3.data()[i] * alpha[5] +
  46 + b1.data()[i] * alpha[6] +
  47 + b2.data()[i] * alpha[7] +
  48 + b3.data()[i] * alpha[8] ;
  49 +
  50 + }
  51 +
  52 + //stim::cpu2image(mPb_theta.data(), "data_output/cmap_mPb_theta0.bmp", w, h, stim::cmBrewer);
  53 +
  54 +
  55 + //getch();
  56 +
  57 + return mPb_theta;
  58 +}
0 59 \ No newline at end of file
... ...
func_mPb.cpp 0 → 100644
  1 +++ a/func_mPb.cpp
  1 +#include <stim/image/image.h>
  2 +#include <cmath>
  3 +#include <conio.h>
  4 +#include <stim/visualization/colormap.h>
  5 +#include <stim/image/image_contour_detection.h>
  6 +#include <sstream>
  7 +
  8 +stim::image<float> func_mPb(stim::image<float> lab, unsigned int theta_n, unsigned int w, unsigned int h){
  9 +
  10 + std::clock_t start;
  11 + start = std::clock();
  12 +
  13 + //---------------pavel's suggesiton------------------------------------
  14 + std::ostringstream ss;
  15 + unsigned int N = w * h;
  16 + stim::image<float> mPb_theta(w,h), mPb(w,h);
  17 + unsigned size = mPb_theta.size();
  18 + memset ( mPb.data(), 0, size * sizeof(float));
  19 +
  20 + float* ptr;
  21 + ptr = (float*) malloc(size * sizeof(float) * theta_n);
  22 +
  23 + for (unsigned int n = 0; n < theta_n; n++){
  24 +
  25 + ss << "data_output/mPb_theta"<< n << ".bmp";
  26 + float theta = 180 * ((float)n/theta_n);
  27 +
  28 + mPb_theta = func_mPb_theta(lab, theta, w, h);
  29 + //mPb_theta.load("101087.bmp");
  30 + float* ptr_n = &ptr[ n * w * h * 1 ];
  31 + mPb_theta.channel(0).data_noninterleaved(ptr_n);
  32 +
  33 + double duration1 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  34 + std::cout<<"mPb_theta_"<< theta <<" complished time:"<< duration1 <<"s"<<'\n';
  35 +
  36 +
  37 + unsigned long idx = n * w * h * 1; //index for the nth slice
  38 +
  39 + std::string sss = ss.str();
  40 + stim::cpu2image(&ptr[idx], sss, w, h, stim::cmBrewer);
  41 +
  42 +
  43 + for(unsigned long i = 0; i < N; i++){
  44 +
  45 + float pixel = ptr[i+idx]; //get the ith pixel in nth slice
  46 +
  47 + if(pixel > mPb.data()[i]){
  48 + mPb.data()[i] = pixel;
  49 + }
  50 +
  51 + else{
  52 + }
  53 + }
  54 +
  55 +
  56 +
  57 + ss.str("");
  58 + }
  59 +
  60 + stim::cpu2image(mPb.data(), "data_output/mPb.bmp", w, h, stim::cmBrewer);
  61 +
  62 + double duration2 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  63 + std::cout<<"total time:"<< duration2 <<"s"<<'\n';
  64 +
  65 + getch();
  66 +
  67 + return mPb;
  68 +
  69 + //---------------my first method------------------------------------
  70 + /*
  71 + std::clock_t start;
  72 + start = std::clock();
  73 +
  74 + stim::image<float> mPb_stack(w,h,theta_n), mPb(w,h), mPb_theta(w,h), A, B, temp;
  75 + float* ptr[8];
  76 +
  77 + for (unsigned int n = 0; n < theta_n; n++){
  78 +
  79 + //int* x = new int(5);
  80 + //int* y = x;
  81 + //*y = 1;
  82 +
  83 + float theta = 180 * ((float)n/theta_n);
  84 + mPb_theta = func_mPb_theta(lab, theta, w, h);
  85 + mPb_stack.getslice(n) = mPb_theta;
  86 + float* ptr[n] = mPb_stack.getslice(n).data();
  87 +
  88 + double duration1 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  89 + std::cout<<"mPb_theta, theta = "<< theta <<" time:"<< duration1 <<"s"<<'\n';
  90 +
  91 +
  92 + for(unsigned long i = 0; i < N; i++){
  93 +
  94 + *(ptr[n]+i) = mPb_theta.data()[i];
  95 +
  96 +
  97 + //float a = mPb_theta.data()[i];
  98 + //float* B = ptr[n]+i;
  99 + //A.data()[i] = mPb_theta.data()[i];
  100 + //float* C = ptr[0]+1;
  101 + //*C = 1;
  102 +
  103 + //
  104 + }
  105 + stim::cpu2image(ptr[0], "data_output/mPb_theta.bmp", w, h, stim::cmBrewer);
  106 + }
  107 +
  108 + for (unsigned long i = 0; i < N; i++){
  109 +
  110 + mPb.data()[i] = 0;
  111 + for (unsigned int n = 0; n < theta_n; n++){
  112 +
  113 + float* ptr2 = ptr[i]+n;
  114 + float temp = *ptr2;
  115 +
  116 + if(temp > mPb.data()[i]){
  117 + mPb.data()[i] = temp;
  118 + }
  119 + else{
  120 + }
  121 + }
  122 + }
  123 +
  124 + stim::cpu2image(mPb.data(), "data_output/cmap_mPb.bmp", w, h, stim::cmBrewer);
  125 +
  126 + double duration2 = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
  127 + std::cout<<"total time:"<< duration2 <<"s"<<'\n';
  128 +
  129 + getch();
  130 +
  131 + return mPb; */
  132 +
  133 +
  134 +
  135 +}
0 136 \ No newline at end of file
... ...
gauss_derivative_odd.cpp 0 → 100644
  1 +++ a/gauss_derivative_odd.cpp
  1 +#include <stim/image/image.h>
  2 +#include <cmath>
  3 +#include <stim/visualization/colormap.h>
  4 +#include <iostream>
  5 +
  6 +#define PI 3.1415926
  7 +
  8 +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){
  9 +
  10 + stim::image<float> mask_x(winsize+1, winsize+1), mask_y(winsize+1, winsize+1), mask_theta(winsize+1, winsize+1), derivative_x, derivative_y, derivative_theta(w, h);
  11 + //float* ptr = mask_x.data();
  12 +
  13 + //mask_x.load("101087.bmp");
  14 + //float s[169];
  15 + //float *ptr = s;
  16 +
  17 + // set parameters
  18 + unsigned N = w * h;
  19 + float theta_r = (theta * PI)/180;
  20 +
  21 + float step = (2*sigma*sigma_n)/winsize;
  22 +
  23 + for (unsigned j = 0; j <= winsize; j++){
  24 + for (unsigned i = 0; i<= winsize; i++){
  25 +
  26 + float x = (-1)*sigma*sigma_n + i * step; //range of x
  27 + float y = (-1)*sigma*sigma_n + j * step; //range of y
  28 +
  29 + // create the x-oriented gaussian derivative filter mask_x
  30 + mask_x.data()[j*(winsize+1) + i] = (-1) * x * exp((-1)*(pow(x, 2))/(2*pow(sigma, 2))) * exp((-1)*(pow(y, 2))/(2*pow(sigma, 2)));
  31 + // create the y-oriented gaussian derivative filter mask_y
  32 + mask_y.data()[j*(winsize+1) + i] = (-1) * y * exp((-1)*(pow(y, 2))/(2*pow(sigma, 2))) * exp((-1)*(pow(x, 2))/(2*pow(sigma, 2)));
  33 + // create the mask_theta
  34 + mask_theta.data()[j*(winsize+1) + i] = cos(theta_r) * mask_x.data()[j*(winsize+1) + i] + sin(theta_r) * mask_y.data()[j*(winsize+1) + i] ;
  35 +
  36 + }
  37 + }
  38 +
  39 + //stim::cpu2image(mask_x.data(), "data_output/cmapgray_mask_x.bmp", winsize+1, winsize+1, stim::cmBrewer);
  40 +
  41 + //stim::cpu2image(mask_y.data(), "data_output/cmapgray_mask_y.bmp", winsize+1, winsize+1, stim::cmBrewer);
  42 +
  43 +
  44 + //stim::cpu2image(mask_theta.data(), "data_output/cmapgray_mask_theta.bmp", winsize+1, winsize+1, stim::cmBrewer);
  45 +
  46 + // 2D convolution
  47 + derivative_theta = image.convolve2(mask_theta);
  48 +
  49 + for (unsigned k = 0; k < w * h; k++){
  50 +
  51 + derivative_theta.data()[k] = abs(derivative_theta.data()[k]);
  52 +
  53 + }
  54 +
  55 + float max = derivative_theta.max();
  56 +
  57 + for (unsigned k = 0; k < w * h; k++){
  58 +
  59 + derivative_theta.data()[k] = derivative_theta.data()[k]/max;
  60 +
  61 + }
  62 +
  63 + //float max2 = derivative_theta.max();
  64 +
  65 + //stim::cpu2image(derivative_theta.data(), "data_output/cmap_colorb_gradient_theta90_r5.bmp", w, h, stim::cmBrewer);
  66 + //derivative_x.save("data_output/gradient_x.bmp");
  67 +
  68 + return derivative_theta;
  69 +
  70 +}
0 71 \ No newline at end of file
... ...
image_contour_detection.h 0 → 100644
  1 +++ a/image_contour_detection.h
  1 +#include <stim/image/image.h>
  2 +//#include <cmath>
  3 +//#include <stim/visualization/colormap.h>
  4 +
  5 +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);
0 6 \ No newline at end of file
... ...
test result/0829_01_vs_gradient_theta=0.PNG 0 → 100644

193 KB

test result/0829_02_vs_gradient_theta=0.PNG 0 → 100644

381 KB

test result/0829_03_vs_gradient_theta=0_r=3,5,10.PNG 0 → 100644

583 KB

test result/0829_03_vs_gradient_theta=90_r=3,5,10.PNG 0 → 100644

542 KB

test result/0829_04_compare_colora_theta=90_r=3,5,10.PNG 0 → 100644

559 KB

test result/0829_04_compare_colorb_theta=90_r=3,5,10.PNG 0 → 100644

719 KB

test result/0829_04_compare_vs_gradient_theta=90_r=3,5,10.PNG 0 → 100644

702 KB

test result/0831_01_compare_vs_mPb.PNG 0 → 100644

416 KB

test result/0831_01_compare_vs_mPb_time.PNG 0 → 100644

6.56 KB

test_main.cpp 0 → 100644
  1 +++ a/test_main.cpp
  1 +#include <stim/image/image.h>
  2 +#include <cmath>
  3 +#include <stim/visualization/colormap.h>
  4 +#include <stim/image/image_contour_detection.h>
  5 +#include <iostream>
  6 +
  7 +
  8 +void main()
  9 +{
  10 + stim::image<float> rgb,gaussgradient; //generate an image object
  11 +
  12 + rgb.load("101087.bmp"); //load the input image
  13 + unsigned int w = rgb.width(); //get the image size
  14 + unsigned int h = rgb.height();
  15 + unsigned int s = rgb.size();
  16 + unsigned a = sizeof(float);
  17 +
  18 + stim::image<float> lab; //create an image object for a single-channel (grayscale) image
  19 + lab = rgb.srgb2lab(); //create the single-channel image
  20 +
  21 + /*
  22 + stim::image<float> pic_light, pic_colora, pic_colorb;
  23 + pic_light = lab.channel(0);
  24 + pic_light.save("pic_light.bmp");
  25 +
  26 + pic_colora = lab.channel(1);
  27 + pic_colorb = lab.channel(2);
  28 +
  29 + float sigma = 2;
  30 + unsigned int sigma_n = 3;
  31 + unsigned int r = 5;
  32 + unsigned int winsize = r * 2; //window size = winsize + 1
  33 + float theta = 90;
  34 +
  35 + gaussgradient = gaussian_derivative_filter_odd(pic_colorb, sigma, sigma_n, winsize, theta, w, h);
  36 + gaussgradient.save("data_output/pic_gray_gradient.bmp");
  37 + */
  38 +
  39 + //float theta = 0;
  40 + unsigned int theta_n = 8;
  41 +
  42 + //stim::image<float> mPb_stack(w,h,theta_n);
  43 +
  44 + //stim::image<float> mPb_theta;
  45 + //mPb_theta = func_mPb_theta(lab, theta, w, h);
  46 + //mPb_theta.save("data_output/pic_gray_gradient.bmp");
  47 +
  48 + stim::image<float> mPb;
  49 + mPb = func_mPb(lab, theta_n, w, h);
  50 +
  51 +
  52 +
  53 +}
0 54 \ No newline at end of file
... ...