CUDA-Sobel-Filter-master


This program is meant to run a sobel filter using three different methods. Each sobel filter function runs in a different way than the others, one is a basic sobel filter running through just the cpu on a single thread, another runs through openmp to parallelize the single threaded cpu function, and the last one runs through a NVIDIA gpu to parallelize the function onto the many cores available on the gpu. The resulting output from the functions should be the same no matter which way it is ran, the only difference will be the time taken to process each method. In most cases, the CPU will run the slowest, then openmp, and finally the GPU method will run the fastest (due to having more cores to handle many small computations). The result will be an image showing an edge map produced by each method, the edge maps should all be the same.
资源截图
代码片段和文件信息
/*************************************************************************************************
 * File: imageLoader.cpp
 * Date: 10/16/2017
 *
 * Description: This file is meant to be a file of load/write functions for the original program.
 *      The file includes both a useful typedef to shorten unsigned chars into bytes and a struct
 *      meant to make accessing image data easier.
 *************************************************************************************************/
#include “lodepng.h“
#include 

typedef unsigned char byte; // most useful typedef ever

/************************************************************************************************
 * struct imgData(byte* uint uint)
 * - a struct to contain all information about our image
 ***********************************************************************************************/
struct imgData {
    imgData(byte* pix = nullptr unsigned int w = 0 unsigned int h = 0) : pixels(pix) width(w) height(h) {
    };
    byte* pixels;
    unsigned int width;
    unsigned int height;
};

/************************************************************************************************
 * imgData loadImage(char*)
 * - takes in a filename with a png extension and uses LodePNG to decode it the resulting data
 * - is converted to grayscale and then a structure containing the pixel data image width and
 * - height are returned out. Decoding currently uses a C style decoding that uses free and an
 * - array might consider re-writing to use the newer decode using a C++ vector if I have time.
 *  
 * Inputs: char* filename : the filename of the image to load
 * Outputs:       imgData : a structure returned containing the image data (pixels width height)
 * 
 ***********************************************************************************************/
imgData loadImage(char* filename) {
    unsigned int width height;
    byte* rgb;
    unsigned error = lodepng_decode_file(&rgb &width &height filename LCT_RGBA 8);
    if(error) {
        printf(“LodePNG had an error during file processing. Exiting program.
“);
        printf(“Error code: %u: %s
“ error lodepng_error_text(error));
        exit(2);
    }
    byte* grayscale = new byte[width*height];
    byte* img = rgb;
    for(int i = 0; i < width*height; ++i) {
        int r = *img++;
        int g = *img++;
        int b = *img++;
        int a = *img++;
        grayscale[i] = 0.3*r + 0.6*g + 0.1*b+0.5;
    }
    free(rgb);
    return imgData(grayscale width height);
}

/************************************************************************************************
 * void writeImage(char* std::string imgData)
 * - This function takes a filename as a char array a string of text and a structure containing
 * - the image‘s pixel info width and height. The function will take the original filename
 * - remove the .png ending and append text before re-adding the .png extension then lodepng is
 * - ca

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-10-18 15:44  CUDA-Sobel-Filter-master
     文件          50  2017-10-18 15:44  CUDA-Sobel-Filter-master.gitignore
     文件         469  2017-10-18 15:44  CUDA-Sobel-Filter-masterMakefile
     文件        1206  2017-10-18 15:44  CUDA-Sobel-Filter-masterREADME.md
     文件    13861916  2017-10-18 15:44  CUDA-Sobel-Filter-masterflags.png
     文件        4037  2017-10-18 15:44  CUDA-Sobel-Filter-masterimageLoader.cpp
     文件      220491  2017-10-18 15:44  CUDA-Sobel-Filter-masterlodepng.cpp
     文件       82320  2017-10-18 15:44  CUDA-Sobel-Filter-masterlodepng.h
     文件       12768  2017-10-18 15:44  CUDA-Sobel-Filter-mastersobelFilter.cu

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)