void referenceCalculation(const uchar4* const rgbaImage, uchar4 *const outputImage, size_t numRows, size_t numCols, const float* const filter, const int filterWidth) { unsigned char *red = new unsigned char[numRows * numCols]; unsigned char *blue = new unsigned char[numRows * numCols]; unsigned char *green = new unsigned char[numRows * numCols]; unsigned char *redBlurred = new unsigned char[numRows * numCols]; unsigned char *blueBlurred = new unsigned char[numRows * numCols]; unsigned char *greenBlurred = new unsigned char[numRows * numCols]; //First we separate the incoming RGBA image into three separate channels //for Red, Green and Blue for (size_t i = 0; i < numRows * numCols; ++i) { uchar4 rgba = rgbaImage[i]; red[i] = rgba.x; green[i] = rgba.y; blue[i] = rgba.z; } //Now we can do the convolution for each of the color channels channelConvolution(red, redBlurred, numRows, numCols, filter, filterWidth); channelConvolution(green, greenBlurred, numRows, numCols, filter, filterWidth); channelConvolution(blue, blueBlurred, numRows, numCols, filter, filterWidth); //now recombine into the output image - Alpha is 255 for no transparency for (size_t i = 0; i < numRows * numCols; ++i) { uchar4 rgba = make_uchar4(redBlurred[i], greenBlurred[i], blueBlurred[i], 255); outputImage[i] = rgba; } delete[] red; delete[] green; delete[] blue; delete[] redBlurred; delete[] greenBlurred; delete[] blueBlurred; }
static inline __host__ __device__ uchar4 _pixMake(Ncv8u x, Ncv8u y, Ncv8u z, Ncv8u w) {return make_uchar4(x,y,z,w);}
template<> inline __host__ __device__ uchar4 _pixMakeZero<uchar4>() {return make_uchar4(0,0,0,0);}
int main(int argc, char** argv) { std::cout << "Starting iu_image_cpu_unittest ..." << std::endl; // test image size IuSize sz(79,63); iu::ImageCpu_8u_C1 im_cpu_8u_C1(sz); iu::ImageCpu_8u_C2 im_cpu_8u_C2(sz); iu::ImageCpu_8u_C3 im_cpu_8u_C3(sz); iu::ImageCpu_8u_C4 im_cpu_8u_C4(sz); iu::ImageCpu_32f_C1 im_cpu_32f_C1(sz); iu::ImageCpu_32f_C2 im_cpu_32f_C2(sz); iu::ImageCpu_32f_C3 im_cpu_32f_C3(sz); iu::ImageCpu_32f_C4 im_cpu_32f_C4(sz); unsigned char set_value_8u_C1 = 1; uchar2 set_value_8u_C2 = make_uchar2(2,2); uchar3 set_value_8u_C3 = make_uchar3(3,3,3); uchar4 set_value_8u_C4 = make_uchar4(4,4,4,4); float set_value_32f_C1 = 1.1f; float2 set_value_32f_C2 = make_float2(2.2f); float3 set_value_32f_C3 = make_float3(3.3f); float4 set_value_32f_C4 = make_float4(4.4f); // set values test { std::cout << "testing setValue on cpu ..." << std::endl; iu::setValue(set_value_8u_C1, &im_cpu_8u_C1, im_cpu_8u_C1.roi()); iu::setValue(set_value_8u_C2, &im_cpu_8u_C2, im_cpu_8u_C2.roi()); iu::setValue(set_value_8u_C3, &im_cpu_8u_C3, im_cpu_8u_C3.roi()); iu::setValue(set_value_8u_C4, &im_cpu_8u_C4, im_cpu_8u_C4.roi()); iu::setValue(set_value_32f_C1, &im_cpu_32f_C1, im_cpu_32f_C1.roi()); iu::setValue(set_value_32f_C2, &im_cpu_32f_C2, im_cpu_32f_C2.roi()); iu::setValue(set_value_32f_C3, &im_cpu_32f_C3, im_cpu_32f_C3.roi()); iu::setValue(set_value_32f_C4, &im_cpu_32f_C4, im_cpu_32f_C4.roi()); // check if set values are correct for (unsigned int y = 0; y<sz.height; ++y) { for (unsigned int x = 0; x<sz.width; ++x) { // 8-bit if( *im_cpu_8u_C1.data(x,y) != set_value_8u_C1) return EXIT_FAILURE; if( *im_cpu_8u_C2.data(x,y) != set_value_8u_C2) return EXIT_FAILURE; if( *im_cpu_8u_C3.data(x,y) != set_value_8u_C3) return EXIT_FAILURE; if( *im_cpu_8u_C4.data(x,y) != set_value_8u_C4) return EXIT_FAILURE; // 32-bit if( *im_cpu_32f_C1.data(x,y) != set_value_32f_C1) return EXIT_FAILURE; if( *im_cpu_32f_C2.data(x,y) != set_value_32f_C2) return EXIT_FAILURE; if( *im_cpu_32f_C3.data(x,y) != set_value_32f_C3) return EXIT_FAILURE; if( *im_cpu_32f_C4.data(x,y) != set_value_32f_C4) return EXIT_FAILURE; } } } // copy test { std::cout << "testing copy cpu -> cpu ..." << std::endl; iu::ImageCpu_8u_C1 cp_cpu_8u_C1(sz); iu::ImageCpu_8u_C2 cp_cpu_8u_C2(sz); iu::ImageCpu_8u_C3 cp_cpu_8u_C3(sz); iu::ImageCpu_8u_C4 cp_cpu_8u_C4(sz); iu::ImageCpu_32f_C1 cp_cpu_32f_C1(sz); iu::ImageCpu_32f_C2 cp_cpu_32f_C2(sz); iu::ImageCpu_32f_C3 cp_cpu_32f_C3(sz); iu::ImageCpu_32f_C4 cp_cpu_32f_C4(sz); iu::copy(&im_cpu_8u_C1, &cp_cpu_8u_C1); iu::copy(&im_cpu_8u_C2, &cp_cpu_8u_C2); iu::copy(&im_cpu_8u_C3, &cp_cpu_8u_C3); iu::copy(&im_cpu_8u_C4, &cp_cpu_8u_C4); iu::copy(&im_cpu_32f_C1, &cp_cpu_32f_C1); iu::copy(&im_cpu_32f_C2, &cp_cpu_32f_C2); iu::copy(&im_cpu_32f_C3, &cp_cpu_32f_C3); iu::copy(&im_cpu_32f_C4, &cp_cpu_32f_C4); // check if set values are correct for (unsigned int y = 0; y<sz.height; ++y) { for (unsigned int x = 0; x<sz.width; ++x) { if( *cp_cpu_8u_C1.data(x,y) != set_value_8u_C1) return EXIT_FAILURE; if( *cp_cpu_8u_C2.data(x,y) != set_value_8u_C2) return EXIT_FAILURE; if( *cp_cpu_8u_C3.data(x,y) != set_value_8u_C3) return EXIT_FAILURE; if( *cp_cpu_8u_C4.data(x,y) != set_value_8u_C4) return EXIT_FAILURE; if( *cp_cpu_32f_C1.data(x,y) != set_value_32f_C1) return EXIT_FAILURE; if( *cp_cpu_32f_C2.data(x,y) != set_value_32f_C2) return EXIT_FAILURE; if( *cp_cpu_32f_C3.data(x,y) != set_value_32f_C3) return EXIT_FAILURE; if( *cp_cpu_32f_C4.data(x,y) != set_value_32f_C4) return EXIT_FAILURE; } } } std::cout << std::endl; std::cout << "**************************************************************************" << std::endl; std::cout << "* Everything seem to be ok. -- All assertions passed. *" << std::endl; std::cout << "* Look at the images and close the windows to derminate the unittests. *" << std::endl; std::cout << "**************************************************************************" << std::endl; std::cout << std::endl; return EXIT_SUCCESS; }
int main(int argc, char **argv) { if(argc < 2) { std::cout << "usage: iugui_imagewindow_test image_filename" << std::endl; exit(EXIT_FAILURE); } printf("start ImageWindow test\n"); // we want to remove this!!! initGL(argc,argv); QApplication app(argc, argv); // First load the image, so we know what the size of the image (imageW and imageH) std::string in_file = argv[1]; std::cout << "reading " << in_file << " into gpu memory." << std::endl; iu::ImageGpu_8u_C1* image_8u_C1 = iu::imread_cu8u_C1(in_file); iu::ImageGpu_32f_C1* image_32f_C1 = iu::imread_cu32f_C1(in_file); iu::ImageGpu_8u_C4* image_8u_C4 = iu::imread_cu8u_C4(in_file); iu::ImageGpu_32f_C4* image_32f_C4 = iu::imread_cu32f_C4(in_file); // iu::imshow(image_8u_C4, "reference input image"); double time = iu::getTime(); iu::ImageWindow win_8u_C1; win_8u_C1.setWindowTitle("gpu 8u C1"); win_8u_C1.setImage(image_8u_C1); // create overlays iu::ImageGpu_8u_C1 overlay_8u(image_8u_C1->size()); { iu::setValue(0, &overlay_8u, overlay_8u.roi()); IuRect roi(10,10,100,100); iu::setValue(64u, &overlay_8u, roi); roi = IuRect(110,110,200,200); iu::setValue(128u, &overlay_8u, roi); } iu::ImageGpu_32f_C1 overlay_32f(image_8u_C1->size()); { iu::setValue(0, &overlay_32f, overlay_32f.roi()); IuRect roi(10,10,100,100); iu::setValue(0.2f, &overlay_32f, roi); roi = IuRect(110,110,200,200); iu::setValue(0.5f, &overlay_32f, roi); } iu::LinearHostMemory_8u_C1 lut_values1_8u(2); *lut_values1_8u.data(0) = 64u; *lut_values1_8u.data(1) = 128u; iu::LinearHostMemory_8u_C4 lut_colors1_8u(2); *lut_colors1_8u.data(0) = make_uchar4(255,0,0,128); *lut_colors1_8u.data(1) = make_uchar4(0,0,255,128); iu::LinearHostMemory_32f_C1 lut_values2_32f(2); *lut_values2_32f.data(0) = 0.2f; *lut_values2_32f.data(1) = 0.5f; iu::LinearHostMemory_8u_C4 lut_colors2_8u(2); *lut_colors2_8u.data(0) = make_uchar4(0,0,255,128); *lut_colors2_8u.data(1) = make_uchar4(255,0,0,128); iu::LinearDeviceMemory_8u_C1 cu_lut_values1_8u(2); iu::LinearDeviceMemory_8u_C4 cu_lut_colors1_8u(2); iu::LinearDeviceMemory_32f_C1 cu_lut_values2_32f(2); iu::LinearDeviceMemory_8u_C4 cu_lut_colors2_8u(2); iu::copy(&lut_values1_8u, &cu_lut_values1_8u); iu::copy(&lut_values2_32f, &cu_lut_values2_32f); iu::copy(&lut_colors1_8u, &cu_lut_colors1_8u); iu::copy(&lut_colors2_8u, &cu_lut_colors2_8u); QString name1("overlay 1"); win_8u_C1.addOverlay(name1, reinterpret_cast<iu::Image*>(&overlay_8u), reinterpret_cast<iu::LinearMemory*>(&cu_lut_values1_8u), &cu_lut_colors1_8u, true); win_8u_C1.addOverlay(QString("overlay 2"), &overlay_32f, &cu_lut_values2_32f, &cu_lut_colors2_8u, false); win_8u_C1.show(); std::cout << "display create/show takes " << (iu::getTime()-time) << "ms" << std::endl; // time = iu::getTime(); // iu::QGLImageGpuWidget widget_8u_C1(0); // widget_8u_C1.setWindowTitle("qgl widget: 8u_C1"); // widget_8u_C1.setImage(image_8u_C1); // widget_8u_C1.show(); // std::cout << "display create/show takes " << (iu::getTime()-time) << "ms" << std::endl; // // update test // std::cout << "reading " << in_file2 << std::endl; // iu::ImageCpu_8u_C1* image2_8u_C1 = iu::imread_8u_C1(in_file2); // im_display_8u_C1.updateImage(image2_8u_C1); // // check gpu widget // iu::ImageGpu_8u_C1* image_cu8u_C1 = iu::imread_cu8u_C1(in_file); // iu::ImageGpu_32f_C1* image_cu32f_C1 = iu::imread_cu32f_C1(in_file); // iu::ImageGpu_8u_C4* image_cu8u_C4 = iu::imread_cu8u_C4(in_file); // iu::ImageGpu_8u_C4* image2_cu8u_C4 = iu::imread_cu8u_C4(in_file2); // iu::ImageGpu_32f_C4* image_cu32f_C4 = iu::imread_cu32f_C4(in_file); app.exec(); delete(image_8u_C1); delete(image_8u_C4); delete(image_32f_C1); delete(image_32f_C4); cudaThreadExit(); return(EXIT_SUCCESS); }
int main(int argc, char** argv) { std::cout << "Starting iu_image_gpu_unittest ..." << std::endl; // test image size IuSize sz(79,63); iu::ImageGpu_8u_C1 im_gpu_8u_C1(sz); iu::ImageGpu_8u_C2 im_gpu_8u_C2(sz); iu::ImageGpu_8u_C3 im_gpu_8u_C3(sz); iu::ImageGpu_8u_C4 im_gpu_8u_C4(sz); iu::ImageGpu_32f_C1 im_gpu_32f_C1(sz); iu::ImageGpu_32f_C2 im_gpu_32f_C2(sz); iu::ImageGpu_32f_C3 im_gpu_32f_C3(sz); iu::ImageGpu_32f_C4 im_gpu_32f_C4(sz); unsigned char set_value_8u_C1 = 1; uchar2 set_value_8u_C2 = make_uchar2(2,2); uchar3 set_value_8u_C3 = make_uchar3(3,3,3); uchar4 set_value_8u_C4 = make_uchar4(4,4,4,4); float set_value_32f_C1 = 1.1f; float2 set_value_32f_C2 = make_float2(2.2f); float3 set_value_32f_C3 = make_float3(3.3f); float4 set_value_32f_C4 = make_float4(4.4f); // copy values back to cpu to compare the set values iu::ImageCpu_8u_C1 im_cpu_8u_C1(sz); iu::ImageCpu_8u_C2 im_cpu_8u_C2(sz); iu::ImageCpu_8u_C3 im_cpu_8u_C3(sz); iu::ImageCpu_8u_C4 im_cpu_8u_C4(sz); iu::ImageCpu_32f_C1 im_cpu_32f_C1(sz); iu::ImageCpu_32f_C2 im_cpu_32f_C2(sz); iu::ImageCpu_32f_C3 im_cpu_32f_C3(sz); iu::ImageCpu_32f_C4 im_cpu_32f_C4(sz); // set values on cpu and copy to gpu and back again { std::cout << "Testing copy. setValue on cpu (should work because of previous test) and copy forth and back" << std::endl; iu::setValue(set_value_8u_C1, &im_cpu_8u_C1, im_cpu_8u_C1.roi()); iu::setValue(set_value_8u_C2, &im_cpu_8u_C2, im_cpu_8u_C2.roi()); iu::setValue(set_value_8u_C3, &im_cpu_8u_C3, im_cpu_8u_C3.roi()); iu::setValue(set_value_8u_C4, &im_cpu_8u_C4, im_cpu_8u_C4.roi()); iu::setValue(set_value_32f_C1, &im_cpu_32f_C1, im_cpu_32f_C1.roi()); iu::setValue(set_value_32f_C2, &im_cpu_32f_C2, im_cpu_32f_C2.roi()); iu::setValue(set_value_32f_C3, &im_cpu_32f_C3, im_cpu_32f_C3.roi()); iu::setValue(set_value_32f_C4, &im_cpu_32f_C4, im_cpu_32f_C4.roi()); std::cout << " copy cpu -> gpu ..." << std::endl; iu::copy(&im_cpu_8u_C1, &im_gpu_8u_C1); iu::copy(&im_cpu_8u_C2, &im_gpu_8u_C2); iu::copy(&im_cpu_8u_C3, &im_gpu_8u_C3); iu::copy(&im_cpu_8u_C4, &im_gpu_8u_C4); iu::copy(&im_cpu_32f_C1, &im_gpu_32f_C1); iu::copy(&im_cpu_32f_C2, &im_gpu_32f_C2); iu::copy(&im_cpu_32f_C3, &im_gpu_32f_C3); iu::copy(&im_cpu_32f_C4, &im_gpu_32f_C4); std::cout << " copy gpu -> cpu ..." << std::endl; iu::copy(&im_gpu_8u_C1, &im_cpu_8u_C1); iu::copy(&im_gpu_8u_C2, &im_cpu_8u_C2); iu::copy(&im_gpu_8u_C3, &im_cpu_8u_C3); iu::copy(&im_gpu_8u_C4, &im_cpu_8u_C4); iu::copy(&im_gpu_32f_C1, &im_cpu_32f_C1); iu::copy(&im_gpu_32f_C2, &im_cpu_32f_C2); iu::copy(&im_gpu_32f_C3, &im_cpu_32f_C3); iu::copy(&im_gpu_32f_C4, &im_cpu_32f_C4); std::cout << " check copied values on cpu ..." << std::endl; // check if set values are correct for (unsigned int y = 0; y<sz.height; ++y) { for (unsigned int x = 0; x<sz.width; ++x) { // 8-bit if( *im_cpu_8u_C1.data(x,y) != set_value_8u_C1) return EXIT_FAILURE; if( *im_cpu_8u_C2.data(x,y) != set_value_8u_C2) return EXIT_FAILURE; if( *im_cpu_8u_C3.data(x,y) != set_value_8u_C3) return EXIT_FAILURE; if( *im_cpu_8u_C4.data(x,y) != set_value_8u_C4) return EXIT_FAILURE; // 32-bit if( *im_cpu_32f_C1.data(x,y) != set_value_32f_C1) return EXIT_FAILURE; if( *im_cpu_32f_C2.data(x,y) != set_value_32f_C2) return EXIT_FAILURE; if( *im_cpu_32f_C3.data(x,y) != set_value_32f_C3) return EXIT_FAILURE; if( *im_cpu_32f_C4.data(x,y) != set_value_32f_C4) return EXIT_FAILURE; } } } // set values on gpu { std::cout << "Testing setValue on gpu (implecitely testing copy gpu->cpu) ..." << std::endl; iu::setValue(set_value_8u_C1, &im_gpu_8u_C1, im_gpu_8u_C1.roi()); iu::setValue(set_value_8u_C2, &im_gpu_8u_C2, im_gpu_8u_C2.roi()); iu::setValue(set_value_8u_C3, &im_gpu_8u_C3, im_gpu_8u_C3.roi()); iu::setValue(set_value_8u_C4, &im_gpu_8u_C4, im_gpu_8u_C4.roi()); iu::setValue(set_value_32f_C1, &im_gpu_32f_C1, im_gpu_32f_C1.roi()); iu::setValue(set_value_32f_C2, &im_gpu_32f_C2, im_gpu_32f_C2.roi()); iu::setValue(set_value_32f_C3, &im_gpu_32f_C3, im_gpu_32f_C3.roi()); iu::setValue(set_value_32f_C4, &im_gpu_32f_C4, im_gpu_32f_C4.roi()); std::cout << "Copy gpu images to cpu for checking the set values." << std::endl; iu::copy(&im_gpu_8u_C1, &im_cpu_8u_C1); iu::copy(&im_gpu_8u_C2, &im_cpu_8u_C2); iu::copy(&im_gpu_8u_C3, &im_cpu_8u_C3); iu::copy(&im_gpu_8u_C4, &im_cpu_8u_C4); iu::copy(&im_gpu_32f_C1, &im_cpu_32f_C1); iu::copy(&im_gpu_32f_C2, &im_cpu_32f_C2); iu::copy(&im_gpu_32f_C3, &im_cpu_32f_C3); iu::copy(&im_gpu_32f_C4, &im_cpu_32f_C4); // check if set values are correct for (unsigned int y = 0; y<sz.height; ++y) { for (unsigned int x = 0; x<sz.width; ++x) { // 8-bit if( *im_cpu_8u_C1.data(x,y) != set_value_8u_C1) return EXIT_FAILURE; if( *im_cpu_8u_C2.data(x,y) != set_value_8u_C2) return EXIT_FAILURE; if( *im_cpu_8u_C3.data(x,y) != set_value_8u_C3) return EXIT_FAILURE; if( *im_cpu_8u_C4.data(x,y) != set_value_8u_C4) return EXIT_FAILURE; // 32-bit if( *im_cpu_32f_C1.data(x,y) != set_value_32f_C1) return EXIT_FAILURE; if( *im_cpu_32f_C2.data(x,y) != set_value_32f_C2) return EXIT_FAILURE; if( *im_cpu_32f_C3.data(x,y) != set_value_32f_C3) return EXIT_FAILURE; if( *im_cpu_32f_C4.data(x,y) != set_value_32f_C4) return EXIT_FAILURE; } } } // copy gpu -> gpu test { std::cout << "testing copy gpu -> gpu ..." << std::endl; iu::ImageGpu_8u_C1 cp_gpu_8u_C1(sz); iu::ImageGpu_8u_C2 cp_gpu_8u_C2(sz); iu::ImageGpu_8u_C3 cp_gpu_8u_C3(sz); iu::ImageGpu_8u_C4 cp_gpu_8u_C4(sz); iu::ImageGpu_32f_C1 cp_gpu_32f_C1(sz); iu::ImageGpu_32f_C2 cp_gpu_32f_C2(sz); iu::ImageGpu_32f_C3 cp_gpu_32f_C3(sz); iu::ImageGpu_32f_C4 cp_gpu_32f_C4(sz); iu::copy(&im_gpu_8u_C1, &cp_gpu_8u_C1); iu::copy(&im_gpu_8u_C2, &cp_gpu_8u_C2); iu::copy(&im_gpu_8u_C3, &cp_gpu_8u_C3); iu::copy(&im_gpu_8u_C4, &cp_gpu_8u_C4); iu::copy(&im_gpu_32f_C1, &cp_gpu_32f_C1); iu::copy(&im_gpu_32f_C2, &cp_gpu_32f_C2); iu::copy(&im_gpu_32f_C3, &cp_gpu_32f_C3); iu::copy(&im_gpu_32f_C4, &cp_gpu_32f_C4); iu::copy(&cp_gpu_8u_C1, &im_cpu_8u_C1); iu::copy(&cp_gpu_8u_C2, &im_cpu_8u_C2); iu::copy(&cp_gpu_8u_C3, &im_cpu_8u_C3); iu::copy(&cp_gpu_8u_C4, &im_cpu_8u_C4); iu::copy(&cp_gpu_32f_C1, &im_cpu_32f_C1); iu::copy(&cp_gpu_32f_C2, &im_cpu_32f_C2); iu::copy(&cp_gpu_32f_C3, &im_cpu_32f_C3); iu::copy(&cp_gpu_32f_C4, &im_cpu_32f_C4); // check if set values are correct for (unsigned int y = 0; y<sz.height; ++y) { for (unsigned int x = 0; x<sz.width; ++x) { // 8-bit if( *im_cpu_8u_C1.data(x,y) != set_value_8u_C1) return EXIT_FAILURE; if( *im_cpu_8u_C2.data(x,y) != set_value_8u_C2) return EXIT_FAILURE; if( *im_cpu_8u_C3.data(x,y) != set_value_8u_C3) return EXIT_FAILURE; if( *im_cpu_8u_C4.data(x,y) != set_value_8u_C4) return EXIT_FAILURE; // 32-bit if( *im_cpu_32f_C1.data(x,y) != set_value_32f_C1) return EXIT_FAILURE; if( *im_cpu_32f_C2.data(x,y) != set_value_32f_C2) return EXIT_FAILURE; if( *im_cpu_32f_C3.data(x,y) != set_value_32f_C3) return EXIT_FAILURE; if( *im_cpu_32f_C4.data(x,y) != set_value_32f_C4) return EXIT_FAILURE; } } } std::cout << std::endl; std::cout << "**************************************************************************" << std::endl; std::cout << "* Everything seem to be ok. -- All assertions passed. *" << std::endl; std::cout << "* Look at the images and close the windows to derminate the unittests. *" << std::endl; std::cout << "**************************************************************************" << std::endl; std::cout << std::endl; return EXIT_SUCCESS; }
__device__ __forceinline__ void clear_voxel(uchar4 & value) { value = make_uchar4(0, 0, 0, 0); }