GPU自适应图像去噪完整程序


本程序是用Cuda C 编写实现的图像去噪算法,去噪思想是在空域中对图像中的噪声进行自适应去噪处理,针对的是椒盐噪声,先对椒盐噪声进行确定,之后再处理。本程序的执行效率非常高。最高加速比达三个数量级。
资源截图
代码片段和文件信息
// CUDA utilities and system includes
#include 
// Includes
#include 
#include 
#include 
#include 
#include “SobelFilter_kernels.h“
// includes project
#include     // includes cuda.h and cuda_runtime_api.h
#include     // standard utility and system includes

//函数声明
bool readBmp(char *bmpName);
bool saveBmp(char *bmpName unsigned char *imgBuf int width int height int biBitCount RGBQUAD *pColorTable);
unsigned char computAve(unsigned char *arrint n);
unsigned char computMed(unsigned char *arrint n);
unsigned char computSignalMed(unsigned char *arrint n);
void medFilter(unsigned char *imgBufint width int heightint biBitCount );
void initializeData(char *file) ;

const char *sSDKsample = “CUDA Adapt Denoise Filter!“; 

// 定义用于保存的文件名
char *denoiseGPU=“DenoiseGPU.bmp“;
char denoiseCPU[]=“DenoiseCPU.bmp“;

static int imWidth  = 0;   // Image width
static int imHeight = 0;   // Image height

unsigned char * pixels = NULL; // 主机端的源图像数据 
unsigned char * imgDes = NULL; // CPU上处理理的结果指针
int bmpWidth;
int bmpHeight;
RGBQUAD *pColorTable;
int biBitCount;
float imageScale = 1.f;        // Image exposure
enum SobelDisplayMode g_SobelDisplayMode;

int *pArgc   = NULL;
char **pArgv = NULL;

//extern “C“ void runAutoTest();
void runAutoTest();
////////////////////////////////////////////////////////////////////////////////
// These are CUDA Helper functions
// This will output the proper CUDA error strings in the event that a CUDA host call returns an error
#define checkCudaErrors(err)           __checkCudaErrors (err __FILE__ __LINE__)

inline void __checkCudaErrors( cudaError err const char *file const int line )
{
    if( cudaSuccess != err)
{
fprintf(stderr “%s(%i) : CUDA Runtime API error %d: %s.

                   file line (int)err cudaGetErrorString( err ) );
exit(-1);
     }
}

    // This will output the proper error string when calling cudaGetLastError
    #define getLastCudaError(msg)      __getLastCudaError (msg __FILE__ __LINE__)

    inline void __getLastCudaError( const char *errorMessage const char *file const int line )
    {
        cudaError_t err = cudaGetLastError();
        if( cudaSuccess != err) {
            fprintf(stderr “%s(%i) : getLastCudaError() CUDA error : %s : (%d) %s.

                    file line errorMessage (int)err cudaGetErrorString( err ) );
            exit(-1);
        }
    }   
// end of CUDA Helper Functions

void initializeData(char *file)
{
    size_t file_length= strlen(file);

if(!strcmp(&file[file_length-3] “bmp“))
{
if(!readBmp(file))
{
printf(“Failed to load BMP image file: %s
“ file);
            exit(-1);
}
}
else 
{
        cudaDeviceReset();
        exit(-1);
    }    
imWidth=(int)bmpWidth;
imHeight=(int)bmpHeight;
    setupTexture(imWidth imHeight pixels);//使用CUDA数组 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-12-06 13:06  MySobelFilter
     目录           0  2013-01-07 14:54  MySobelFilterDebug
     文件       22442  2012-11-15 13:14  MySobelFilterDebugBuildLog.htm
     文件          37  2012-11-15 13:14  MySobelFilterDebugSobelFilter.device-link.options
     文件         145  2012-11-15 13:14  MySobelFilterDebugSobelFilter.exe.intermediate.manifest
     文件      253569  2012-11-15 13:14  MySobelFilterDebugSobelFilter.obj
     文件     3083264  2012-11-15 13:14  MySobelFilterDebugSobelFilter.pdb
     文件      241618  2012-11-15 13:14  MySobelFilterDebugSobelFilter_kernels.cu.obj
     文件          65  2012-11-15 13:14  MySobelFilterDebugmt.dep
     文件      722783  2012-11-15 13:14  MySobelFilterDebug
endercheck_gl.obj
     文件      683008  2012-11-15 13:14  MySobelFilterDebugvc80.idb
     文件      233472  2012-11-15 13:14  MySobelFilterDebugvc80.pdb
     文件       12171  2013-01-07 14:52  MySobelFilterSobelFilter.cpp
     文件        9495  2013-01-07 14:53  MySobelFilterSobelFilter_kernels.cu
     文件         637  2013-01-02 12:50  MySobelFilterSobelFilter_kernels.h
     文件     9849856  2012-11-15 13:43  MySobelFilterSobelFilter_vs2005.ncb
     文件       19456  2012-11-15 13:43  MySobelFilterSobelFilter_vs2005.suo
     文件        2657  2012-12-06 08:57  MySobelFilterSobelFilter_vs2005.vcproj.HI7QXQWSECZ1E3V.Administrator.user
     文件    31281152  2013-01-07 14:53  MySobelFilterSobelFilter_vs2010.sdf
     文件        1249  2012-01-26 04:38  MySobelFilterSobelFilter_vs2010.sln
     文件       33792  2013-01-07 14:53  MySobelFilterSobelFilter_vs2010.suo
     文件       12644  2013-01-02 13:34  MySobelFilterSobelFilter_vs2010.vcxproj
     文件         143  2012-12-11 13:13  MySobelFilterSobelFilter_vs2010.vcxproj.user
     目录           0  2013-01-07 14:54  MySobelFilterWin32
     目录           0  2013-01-07 14:54  MySobelFilterWin32Debug
     文件       25660  2013-01-07 14:50  MySobelFilterWin32DebugCL.read.1.tlog
     文件         682  2013-01-07 14:50  MySobelFilterWin32DebugCL.write.1.tlog
     文件        2647  2013-01-07 09:29  MySobelFilterWin32DebugSobelFilter.Build.CppClean.log
     文件         381  2013-01-07 14:50  MySobelFilterWin32DebugSobelFilter.exe.intermediate.manifest
     文件         117  2013-01-07 14:50  MySobelFilterWin32DebugSobelFilter.lastbuildstate
     文件      213695  2013-01-07 14:50  MySobelFilterWin32DebugSobelFilter.obj
............此处省略61个文件信息

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

发表评论

评论列表(条)