该代码可以完美的对基于某一阈值的二维切片进行三维重建,代码已经对Marching cubes算法的歧义性进行了处理,代码经过测试,并且已经用于公司产品。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4177 2014-01-24 09:58 RebuildFormSectionImageProcessing.cpp
文件 605 2014-01-21 14:13 RebuildFormSectionImageProcessing.h
文件 260928 2014-01-24 14:30 RebuildFormSectionMarchingCubes.cpp
文件 1897 2014-01-24 14:10 RebuildFormSectionMarchingCubes.h
文件 1229 2014-01-24 14:16 RebuildFormSectionMathAlgorithm.h
文件 1280 2014-01-02 10:10 RebuildFormSectionReadMe.txt
文件 4433 2014-01-24 14:41 RebuildFormSectionRebuildFormSection.cpp
文件 5026 2014-01-13 17:36 RebuildFormSectionRebuildFormSection.dsp
文件 544 2014-01-02 10:10 RebuildFormSectionRebuildFormSection.dsw
文件 181248 2014-01-25 09:38 RebuildFormSectionRebuildFormSection.ncb
文件 56832 2014-01-25 09:38 RebuildFormSectionRebuildFormSection.opt
文件 3564 2014-01-24 14:41 RebuildFormSectionRebuildFormSection.plg
文件 305 2014-01-02 10:10 RebuildFormSectionStdAfx.cpp
文件 791 2014-01-06 15:21 RebuildFormSectionStdAfx.h
文件 5863 2014-01-24 14:41 RebuildFormSectionDebugImageProcessing.obj
文件 0 2014-01-24 14:41 RebuildFormSectionDebugImageProcessing.sbr
文件 161381 2014-01-24 14:41 RebuildFormSectionDebugMarchingCubes.obj
文件 0 2014-01-24 14:41 RebuildFormSectionDebugMarchingCubes.sbr
文件 1238016 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.bsc
文件 405587 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.exe
文件 233180 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.ilk
文件 11565 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.obj
文件 2381656 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.pch
文件 443392 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.pdb
文件 0 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.sbr
文件 55071 2014-01-24 14:41 RebuildFormSectionDebugStdAfx.obj
文件 437613 2014-01-24 14:41 RebuildFormSectionDebugStdAfx.sbr
文件 82944 2014-01-24 14:41 RebuildFormSectionDebugvc60.idb
文件 176128 2014-01-24 14:41 RebuildFormSectionDebugvc60.pdb
目录 0 2014-02-11 13:10 RebuildFormSectionRelease
............此处省略5个文件信息
#include “stdafx.h“
#include “ImageProcessing.h“
//读图像的位图数据、宽、高、颜色表及每像素位数等数据进内存,存放在相应的全局变量中
unsigned char * readBmp(char *bmpNameint &bmpWidthint &bmpHeightint &lineByte)
{
unsigned char *pBmpBuf;
RGBQUAD *pColorTable;
int biBitCount;//图像类型,每像素位数
FILE *fp=fopen(bmpName“rb“);//二进制读方式打开指定的图像文件
if(fp==0)
return 0;
//跳过位图文件头结构BITMAPFILEHEADER
fseek(fp sizeof(BITMAPFILEHEADER)0);
//定义位图信息头结构变量,读取位图信息头进内存,存放在变量head中
BITMAPINFOHEADER head;
fread(&head sizeof(BITMAPINFOHEADER) 1fp); //获取图像宽、高、每像素所占位数等信息
bmpWidth = head.biWidth;
bmpHeight = head.biHeight;
biBitCount = head.biBitCount;//定义变量,计算图像每行像素所占的字节数(必须是4的倍数)
lineByte=(bmpWidth * biBitCount/8+3)/4*4;//灰度图像有颜色表,且颜色表表项为256
if(biBitCount==8)
{
//申请颜色表所需要的空间,读颜色表进内存
pColorTable=new RGBQUAD[256];
fread(pColorTablesizeof(RGBQUAD)256fp);
}
//申请位图数据所需要的空间,读位图数据进内存
pBmpBuf=new unsigned char[lineByte * bmpHeight];
fread(pBmpBuf1lineByte * bmpHeightfp);
fclose(fp);//关闭文件
return pBmpBuf;//读取文件成功
}
//-----------------------------------------------------------------------------------------
//给定一个图像位图数据、宽、高、颜色表指针及每像素所占的位数等信息将其写到指定文件中
bool saveBmp(char *bmpName unsigned char *imgBuf int width int height int biBitCount RGBQUAD *pColorTable)
{
//如果位图数据指针为0,则没有数据传入,函数返回
if(!imgBuf)
return 0;
//颜色表大小,以字节为单位,灰度图像颜色表为1024字节,彩色图像颜色表大小为0
int colorTablesize=0;
if(biBitCount==8)
colorTablesize=1024;
//待存储图像数据每行字节数为4的倍数
int lineByte=(width * biBitCount/8+3)/4*4;
//以二进制写的方式打开文件
FILE *fp=fopen(bmpName“wb“);
if(fp==0)
return 0;
//申请位图文件头结构变量,填写文件头信息
BITMAPFILEHEADER fileHead;
fileHead.bfType = 0x4D42;//bmp类型
//bfSize是图像文件4个组成部分之和
fileHead.bfSize= sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + colorTablesize + lineByte*height;
fileHead.bfReserved1 = 0;
fileHead.bfReserved2 = 0;
//bfOffBits是图像文件前3个部分所需空间之和
fileHead.bfOffBits=54+colorTablesize;
//写文件头进文件
fwrite(&fileHead sizeof(BITMAPFILEHEADER)1 fp);
//申请位图信息头结构变量,填写信息头信息
BITMAPINFOHEADER head;
head.biBitCount=biBitCount;
head.biClrImportant=0;
head.biClrUsed=0;
head.biCompression=0;
head.biHeight=height;
head.biPlanes=1;
head.biSize=40;
head.biSizeImage=lineByte*height;
head.biWidth=width;
head.biXPelsPerMeter=0;
head.biYPelsPerMeter=0;
//写位图信息头进内存
fwrite(&head sizeof(BITMAPINFOHEADER)1 fp);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4177 2014-01-24 09:58 RebuildFormSectionImageProcessing.cpp
文件 605 2014-01-21 14:13 RebuildFormSectionImageProcessing.h
文件 260928 2014-01-24 14:30 RebuildFormSectionMarchingCubes.cpp
文件 1897 2014-01-24 14:10 RebuildFormSectionMarchingCubes.h
文件 1229 2014-01-24 14:16 RebuildFormSectionMathAlgorithm.h
文件 1280 2014-01-02 10:10 RebuildFormSectionReadMe.txt
文件 4433 2014-01-24 14:41 RebuildFormSectionRebuildFormSection.cpp
文件 5026 2014-01-13 17:36 RebuildFormSectionRebuildFormSection.dsp
文件 544 2014-01-02 10:10 RebuildFormSectionRebuildFormSection.dsw
文件 181248 2014-01-25 09:38 RebuildFormSectionRebuildFormSection.ncb
文件 56832 2014-01-25 09:38 RebuildFormSectionRebuildFormSection.opt
文件 3564 2014-01-24 14:41 RebuildFormSectionRebuildFormSection.plg
文件 305 2014-01-02 10:10 RebuildFormSectionStdAfx.cpp
文件 791 2014-01-06 15:21 RebuildFormSectionStdAfx.h
文件 5863 2014-01-24 14:41 RebuildFormSectionDebugImageProcessing.obj
文件 0 2014-01-24 14:41 RebuildFormSectionDebugImageProcessing.sbr
文件 161381 2014-01-24 14:41 RebuildFormSectionDebugMarchingCubes.obj
文件 0 2014-01-24 14:41 RebuildFormSectionDebugMarchingCubes.sbr
文件 1238016 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.bsc
文件 405587 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.exe
文件 233180 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.ilk
文件 11565 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.obj
文件 2381656 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.pch
文件 443392 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.pdb
文件 0 2014-01-24 14:41 RebuildFormSectionDebugRebuildFormSection.sbr
文件 55071 2014-01-24 14:41 RebuildFormSectionDebugStdAfx.obj
文件 437613 2014-01-24 14:41 RebuildFormSectionDebugStdAfx.sbr
文件 82944 2014-01-24 14:41 RebuildFormSectionDebugvc60.idb
文件 176128 2014-01-24 14:41 RebuildFormSectionDebugvc60.pdb
目录 0 2014-02-11 13:10 RebuildFormSectionRelease
............此处省略5个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)