資源簡介
CUDA實現的圖像融合算法,圖像格式為BMP。實例處理圖像為:將一張清晰地黑白圖像和一張模糊彩色圖像融合為一張較為清晰地彩色圖像,利用CUDA實現并行計算。

代碼片段和文件信息
#include?“BMPImage2.h“
#include
BMPIMAGE*?BmpRead(char?*filename)
{
FILE?*infile;
unsigned?char?*buffer?BmpHeader[54];?
long?i?j?width?height?BitCount?compression?LineBytes;
unsigned?short?type;
BMPIMAGE?*image=NULL;
if?(filename?==?NULL)
{
printf(“ERROR?in?read:?Filename?is?NULL?assign?it\n“);
return?NULL;
}
infile?=?fopen?(filename?“rb“);
if?(infile?==?NULL)
{
printf(“Unable?to?open?file?%s\n“?filename);
return?NULL;
}
fread(BmpHeader?CharLen?54?infile);?
type?=?(BmpHeader[1]?<8)?+?BmpHeader[0];
width?=(BmpHeader[21]?<24)+(BmpHeader[20]?<16)+(BmpHeader[19]?<8)?+?BmpHeader[18];?
height?=(BmpHeader[25]?<24)+(BmpHeader[24]?<16)+(BmpHeader[23]?<8)?+?BmpHeader[22];
BitCount?=?(BmpHeader[29]?<8)?+?BmpHeader[28];
compression?=(BmpHeader[33]?<24)+(BmpHeader[32]?<16)+(BmpHeader[31]?<8)?+?BmpHeader[32];
LineBytes?=?(width?*?BitCount?+?31)?/?32?*?4;??
if?(type?!=?((unsigned?short)(‘M‘?<8)?|?‘B‘))
{
printf(“the?file?maybe?is?not?a?bmp?image.\n“);
return?NULL;
}
if?(compression?!=?0)?
{
printf(“Can?not?read?a?compressed?file.\n“?filename);
return?NULL;
}
if?((BitCount!=8)&&(BitCount!=24)?)
{
printf(“This?program?can?only?deal?with?the?file?with?256?colors?or?true?color.?\n“?filename);
return?NULL;
}
if(BitCount?==?8)
{
if?((image?=?ImageAlloc(height?width?BitCount))?==?NULL)
{
printf(“ERROR?when?read?call?ImageAlloc.\n“);
return?NULL;
}
buffer?=?new?unsigned?char?[LineBytes];
fseek(infile?1078?SEEK_SET);
for(i=0;?i<=height-1;?i++)
{
fread?(buffer?CharLen?LineBytes?infile);
for(j=0;?j image->gray[i*width+j]?=?buffer[j];
}
}
if(BitCount?==?24)
{
if?((image?=?ImageAlloc(height?width?BitCount))?==?NULL)
{
printf(“ERROR?when?read?call?ImageAlloc.\n“);
return?NULL;
}
buffer?=?new?unsigned?char?[LineBytes];?
fseek(infile?54?SEEK_SET);
for(i=0;?i<=height-1;?i++)//?i:?0?-->?(biHeight-1)
{
fread?(buffer?CharLen?LineBytes?infile);
for(j?=?0;?j? {
image->blue[i*width+j]?=?buffer[3*j];
image->green[i*width+j]?=?buffer[3*j+1];
image->red[i*width+j]?=?buffer[3*j+2];
}
}
?????? }
delete?[]?buffer;
fclose?(infile);
return?image;
}
BMPIMAGE*?BmpRead2(char?*filenamelong?xslong?yslong?xt?long?yt)
{
FILE?*infile;
unsigned?char?*buffer?BmpHeader[54];?
long?i?j?width?height?BitCount?compression?LineBytes;
unsigned?short?type;
BMPIMAGE?*image=NULL;
long?wh;?
if?(filename?==?NULL)
{
printf(“ERROR?in?read:?Filename?is?NULL?assign?it\n“);
return?NULL;
}
infile?=?fopen?(filename?“rb“);
if?(infile?==?NULL)
{
printf(“Unable?to?open?file?%s\n“?filename);
return?NULL;
}
fread(BmpHeader?CharLen?54?infile);?
type?=?(BmpHeader[1]?<8)?+?BmpHeader[0];
width?=(BmpHeader[21]?<24)+(BmpHeader[20]
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????417792??2010-10-16?08:56??Fusion\debug\Fusion.exe
?????文件????1879040??2010-10-16?08:56??Fusion\debug\Fusion.pdb
?????文件??????32592??2010-10-15?11:26??Fusion\Fusion\BMPImage2.cpp
?????文件???????1460??2010-10-14?10:15??Fusion\Fusion\BMPImage2.h
?????文件??????32382??2010-10-15?21:10??Fusion\Fusion\Debug\BMPImage2.obj
?????文件??????11358??2010-10-16?08:56??Fusion\Fusion\Debug\BuildLog.htm
?????文件??????34395??2010-10-16?08:56??Fusion\Fusion\Debug\Fusion.cu.obj
?????文件????????145??2010-10-16?08:56??Fusion\Fusion\Debug\Fusion.exe.intermediate.manifest
?????文件?????????67??2010-10-16?08:56??Fusion\Fusion\Debug\mt.dep
?????文件??????44032??2010-10-15?21:10??Fusion\Fusion\Debug\vc80.idb
?????文件??????53248??2010-10-15?21:10??Fusion\Fusion\Debug\vc80.pdb
?????文件???????3674??2010-10-15?21:23??Fusion\Fusion\Fusion.cu
?????文件???????8103??2010-10-14?09:44??Fusion\Fusion\Fusion.vcproj
?????文件???????2661??2010-10-16?08:56??Fusion\Fusion\Fusion.vcproj.AD24BBE2B6134E1.Administrator.user
?????文件?????641080??2010-06-29?16:56??Fusion\Fusion\gray.bmp
?????文件????1920054??2010-10-16?08:56??Fusion\Fusion\result.bmp
?????文件????1920056??2010-06-29?16:55??Fusion\Fusion\rgb.bmp
?????文件?????159744??2010-10-16?08:56??Fusion\Fusion\vc80.pdb
?????文件?????470016??2010-10-16?08:56??Fusion\Fusion.ncb
?????文件???????1297??2010-10-14?09:28??Fusion\Fusion.sln
????..A..H.?????11264??2010-10-16?08:56??Fusion\Fusion.suo
?????目錄??????????0??2010-10-17?00:18??Fusion\Fusion\Debug
?????目錄??????????0??2010-10-17?00:18??Fusion\debug
?????目錄??????????0??2010-10-17?00:18??Fusion\Fusion
?????目錄??????????0??2010-10-17?00:18??Fusion
-----------?---------??----------?-----??----
??????????????7644460????????????????????25
- 上一篇:新版答題卡制作系統
- 下一篇:TMS320F2812手冊
評論
共有 條評論