人体骨骼核扫描图的混合空间增强_第1页
人体骨骼核扫描图的混合空间增强_第2页
人体骨骼核扫描图的混合空间增强_第3页
人体骨骼核扫描图的混合空间增强_第4页
人体骨骼核扫描图的混合空间增强_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、数字图像处理混合空间增强法学习报告学生姓名: 邹晓敏 学 号: 6103313025 专业班级: 数媒131 一、 学习目的与内容:对混合模糊图像进行处理,为得到一个满意的结果,对其应用多种互补的图像增强技术,最终得到良好效果。本次的数字图像处理实验是对人体骨骼核扫描图片进行混合增强处理,通过混合增强突出骨骼的更多细节。原图中骨骼比较模糊,边缘不够清晰,对比度不够,对此应该采取的策略是首先用拉普拉斯变换突出图像中的小细节,然后用梯度法突出其边缘。平滑后的拉普拉斯变换将用于掩蔽拉普拉斯图像,最后用灰度变换来扩展图像的灰度动态范围。二、 算法介绍:软件开发环境:基于vc+ MFC实现软件编写。具体

2、步骤:(1)拉普拉斯算子拉普拉斯算子是最简单的各向同性微分算子,具有旋转不变性。一个二维图像函数 的拉普拉斯变换是各向同性的二阶导数,定义为:为了更适合于数字图像处理,将该方程表示为离散形式另外,拉普拉斯算子还可以表示成模板的形式,一般增强技术对于陡峭的边缘和缓慢变化的边缘很难确定其边缘线的位置。但此算子却可用二次微分正峰和负峰之间的过零点来确定,对孤立点或端点更为敏感,因此特别适用于以突出图像中的孤立点、孤立线或线端点为目的的场合。用以上算子与原图进行卷积,得到中心像素点与邻域像素点的差值。得到的拉普拉斯变换图M1,M1与原图相加得到M2,锐化原图。 (2)边缘检测 一幅图像的边缘是通过一阶

3、和二阶数字导数来检测得到的。边缘的宽度取决于从初始灰度级跃变到最终灰度级的斜坡的长度。这个长度又取决于斜度,而斜度又取决于模糊程度。所以,我们可知,模糊的边缘使其变粗,而清晰的边缘使其变得较细。一幅数字图像的一阶导数是基于各种二维梯度的近似值。图像在位置的梯度定义为下列向量:梯度向量指向在坐标的的最大变化率方向。在边缘检测中,一个重要的量是向量的大小,用表示,。一般来讲称为梯度。考虑到图片中的噪声,所以在此处用sobel算子。Sobel卷积因子为:该算子包含两组3x3的矩阵,分别为横向及纵向,将之与图像作平面卷积,即可分别得出横向及纵向的亮度差分近似值。如果以A代表原始图像,Gx及Gy分别代表

4、经横向及纵向边缘检测的图像灰度值,其公式如下:sobel算子运算结果得到M3,保留边缘去除噪声根据最后运行的结果显示,sobel图像的边缘要比拉普拉斯图像的边缘突出很多。拉普拉斯变换作为一种二阶微分算子,在图像细节的增强处理方面有明显的优点,但拉普拉斯变换与梯度变换相比较会产生更多的噪声。其中位于平滑区域的噪声非常显眼,梯度变换在灰度变换的区域的相应要比拉普拉斯更强烈,而梯度变换对噪声和小细节的响应要比拉普拉斯变换弱,而且可以通过均值滤波器对其进行平滑处理而进一步的降低,对梯度图像进行平滑处理并用拉普拉斯图像与他相乘。处理后的结果在灰度变化强的区域仍然保留细节,而在灰度变化相对平坦的区域则减少

5、噪声,这种处理可以看做是将拉普拉斯变换与梯度变换的有点结合。(3)平滑处理均值滤波是典型的线性滤波算法,它是指在图像上对目标像素给一个模板,该模板包括了其周围的临近像素(以目标象素为中心的周围8个像素,构成一个滤波模板,即去掉目标像素本身),再用模板中的全体像素的平均值来代替原来像素值。一个5*5的均值滤波器对图像进行平滑处理,5*5的均值滤波器对图像进行平滑处理得到图像M4。再由M2和M4相乘形成掩蔽图像M5。(4)锐化图像 拉普拉斯与平滑后的梯度图像乘积的结果可以看出,强边缘的优势和可见噪声的减少。将乘积图像与原始图像相加就得到了锐化图像。与原始图像相比,锐化处理后的图像细节增加很明显。单

6、独使用拉普拉斯或者梯度变换不能达到这种效果。而且以上的锐化过程没有影响图像的灰度动态变化范围。进行增强处理的最后一步就是扩大锐化图像的灰度动态范围。将M5和原图M求和锐化得到M6,再对M6做幂律变换,扩散灰度范围,提升对比度,但幂次必须小于1。得到最后的混合空间加强图像M7。三、 源程序核心代码及运行结果/拉普拉斯(Laplacian)算子void CImageProcessingDoc:LaplaceOperator(CImage * pSrcImage, CImage * pDstImage, int laplacetype,bool bCalibration) int x;int y;i

7、nt i;int j;int mWidth = pSrcImage-GetWidth();int mHeight = pSrcImage-GetHeight();int mRowBytes = pSrcImage-GetPitch();BYTE *rImageData = (BYTE *)pDstImage-GetBits();int *pBitData = NULL;pBitData = new int3 * mHeight*mWidth;BYTE * pData = NULL;pData = new BYTE9;int Laplace033 = 0,1,0,1,-4,1 , 0,1,0 ;

8、int Laplace133 = 1,1,1,1,-8, 1, 1,1,1 ;int Laplace233 = 0,-1,0,-1,4,-1, 0,-1,0 ;int Laplace333 = -1,-1,-1,-1,8,-1,-1,-1,-1 ;int *p;switch (laplacetype) case 1: p = (int *)Laplace0; break;case 2: p = (int *)Laplace1; break;case 3: p = (int *)Laplace2; break;case 4: p = (int *)Laplace3; break;default:

9、 return;int laplace; for (y = 0; y mHeight; y+)for (x = 0; x mWidth; x+) CopyAreaBlueFromImgBits(pSrcImage, pData, x, y, 1, 1); laplace = 0; for (j = 0; j 3; j+) for (i = 0; i 3; i+) laplace += pDataj * 3 + i * pj*3 + i; pBitData3 * y * mWidth + x * 3 = laplace; CopyAreaGreenFromImgBits(pSrcImage, p

10、Data, x, y, 1, 1); laplace = 0; for (j = 0; j 3; j+) for (i = 0; i 3; i+) laplace += pDataj * 3 + i * pj*3 + i; pBitData3 * y * mWidth + x * 3 + 1 = laplace; CopyAreaRedFromImgBits(pSrcImage, pData, x, y, 1, 1); laplace = 0; for (j = 0; j 3; j+) for (i = 0; i 3; i+) laplace += pDataj * 3 + i * pj*3

11、+ i; pBitData3 * y * mWidth + x * 3 + 2 = laplace;int minBlue = pBitData0;int minGreen = pBitData1;int minRed = pBitData2;for (y = 0; y mHeight; y+)for (x = 0; x mWidth; x+)if (pBitData3 * y * mWidth + x * 3 minBlue)minBlue = pBitData3 * y * mWidth + x * 3;if (pBitData3 * y * mWidth + x * 3 + 1 minG

12、reen)minGreen = pBitData3 * y * mWidth + x * 3 + 1;if (pBitData3 * y * mWidth + x * 3 + 2 minRed)minRed = pBitData3 * y * mWidth + x * 3 + 2; for (y = 0; y mHeight; y+)for (x = 0; x 255?255: laplace + minBlue): (laplace 255) ? 255 : (laplace 255 ? 255 : laplace + minBlue) : (laplace 255) ? 255 : (la

13、place 255 ? 255 : laplace + minBlue) : (laplace 255) ? 255 : (laplace GetWidth();int mHeight = pSrcImage-GetHeight();int mRowBytes = pSrcImage-GetPitch();BYTE *sImageData = (BYTE *)pSrcImage-GetBits();BYTE *rImageData = (BYTE *)pDstImage-GetBits();for (y = 1; y mHeight - 1; y+)for (x = 1; x 255) ? 2

14、55 : sobel;rImageDatay*mRowBytes + x * 3 + 0 = sobel;dx = sImageData(y - 1)*mRowBytes + (x - 1) * 3 + 1 - sImageData(y + 1)*mRowBytes + (x - 1) * 3 + 1+ 2 * (sImageData(y - 1)*mRowBytes + x * 3 + 1 - sImageData(y + 1)*mRowBytes + x * 3 + 1)+ sImageData(y - 1)*mRowBytes + (x + 1) * 3 + 1 - sImageData

15、(y + 1)*mRowBytes + (x + 1) * 3 + 1;dy = sImageData(y - 1)*mRowBytes + (x - 1) * 3 + 1 - sImageData(y - 1)*mRowBytes + (x + 1) * 3 + 1+ 2 * (sImageDatay*mRowBytes + (x - 1) * 3 + 1 - sImageDatay*mRowBytes + (x - 1) * 3 + 1)+ sImageData(y + 1)*mRowBytes + (x - 1) * 3 + 1 - sImageData(y + 1)*mRowBytes

16、 + (x + 1) * 3 + 1;sobel = (int)(sqrt(dx*dx*1.0 + dy*dy);sobel = (sobel 255) ? 255 : sobel;rImageDatay*mRowBytes + x * 3 + 1 = sobel;dx = sImageData(y - 1)*mRowBytes + (x - 1) * 3 + 2 - sImageData(y + 1)*mRowBytes + (x - 1) * 3 + 2+ 2 * (sImageData(y - 1)*mRowBytes + x * 3 + 2 - sImageData(y + 1)*mR

17、owBytes + x * 3 + 2)+ sImageData(y - 1)*mRowBytes + (x + 1) * 3 + 2 - sImageData(y + 1)*mRowBytes + (x + 1) * 3 + 2;dy = sImageData(y - 1)*mRowBytes + (x - 1) * 3 + 2 - sImageData(y - 1)*mRowBytes + (x + 1) * 3 + 2+ 2 * (sImageDatay*mRowBytes + (x - 1) * 3 + 2 - sImageDatay*mRowBytes + (x - 1) * 3 +

18、 2)+ sImageData(y + 1)*mRowBytes + (x - 1) * 3 + 2 - sImageData(y + 1)*mRowBytes + (x + 1) * 3 + 2;sobel = (int)(sqrt(dx*dx*1.0 + dy*dy);sobel = (sobel 255) ? 255 : sobel;rImageDatay*mRowBytes + x * 3 + 2 = sobel;/均值滤波void CImageProcessingDoc:MeanOperator(CImage * pSrcImage, CImage * pDstImage, int

19、m, int n)int x;int y;int mWidth = pSrcImage-GetWidth();int mHeight = pSrcImage-GetHeight();int mRowBytes = pSrcImage-GetPitch();BYTE *rImageData = (BYTE *)pDstImage-GetBits();double sumB;double sumG;double sumR;int nums = (2 * m + 1)*(2 * n + 1);BYTE * pData = NULL;pData = new BYTE3 * nums;int lineB

20、ytes = 3 * (2 * n + 1);for (y = 0; y mHeight; y+)for (x = 0; x mWidth; x+)CopyAreaRGBFromImgBits(pSrcImage, pData, x, y, m, n);sumB = sumG = sumR = 0;for (int j = -m; j = m; j+)for (int i = -n; i = n; i+)sumB += pData(j + m)*lineBytes + (i + n) * 3 + 0;sumG += pData(j + m)*lineBytes + (i + n) * 3 +

21、1;sumR += pData(j + m)*lineBytes + (i + n) * 3 + 2;rImageDatay*mRowBytes + x * 3 = (int)(sumB/nums);rImageDatay*mRowBytes + x * 3 + 1 = (int)(sumG / nums); rImageDatay*mRowBytes + x * 3 + 2 = (int)(sumR / nums);if (pData)delete pData;pData = NULL;/幂律变换void CImageProcessingDoc:OnPowerTransform()/ TOD

22、O: 在此添加命令处理程序代码if (m_sImage.IsNull()AfxMessageBox(_T(请打开要处理的图像!);return;CDialogPowerParameters mdlg;if (mdlg.DoModal() = IDCANCEL)return;int x;int y;int nRows = m_sImage.GetHeight();int nCols = m_sImage.GetWidth();int nBPP = m_sImage.GetBPP();BYTE nRed, nGreen, nBlue;double dGrey;m_rImage.Destroy();

23、if (!m_rImage.Create(nCols, nRows, nBPP)return;BYTE *sImageData = (BYTE *)m_sImage.GetBits();BYTE *rImageData = (BYTE *)m_rImage.GetBits();int nRowBytes = m_sImage.GetPitch();for (y = 0; y nRows; y+)for (x = 0; x nCols; x+)nBlue = sImageDatay * nRowBytes + x * 3 + 0;nGreen = sImageDatay * nRowBytes

24、+ x * 3 + 1;nRed = sImageDatay * nRowBytes + x * 3 + 2;dGrey = 0.299*nRed + 0.587*nGreen + 0.114*nBlue;dGrey = 255 * mdlg.m_power_c * exp(mdlg.m_power_gama * log(dGrey / 255 + 0.00001);rImageDatay * nRowBytes + x * 3 = (BYTE)dGrey;rImageDatay * nRowBytes + x * 3 + 1 = (BYTE)dGrey;rImageDatay * nRowB

25、ytes + x * 3 + 2 = (BYTE)dGrey;UpdateAllViews(NULL);/图像相加void CImageProcessingDoc:OnImageAdd()CImage lsImage;CString strFilter;CSimpleArray aguidFileTypes;HRESULT hResult;/ 获取CImage支持的图像文件的过滤字符串hResult = m_sImage.GetExporterFilterString(strFilter, aguidFileTypes, _T(All Image Files);if (FAILED(hResu

26、lt)AfxMessageBox(_T(GetExporterFilter函数失败!);return;CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, strFilter);if (IDOK != dlg.DoModal()return;lsImage.Destroy();/ 将外部图像文件装载到CImage对象中hResult = lsImage.Load(dlg.GetPathName();if( ( lsImage.GetHeight() != m_sImage.GetHeight() ) | ( lsImage.GetWidth(

27、) != m_sImage.GetWidth() ) )lsImage.Destroy();AfxMessageBox(_T(本软件只处理相同大小图像的逻辑与代数运算!);return;CDialogImageAddRatio mdlg;if (mdlg.DoModal() != IDOK)lsImage.Destroy();return;double lambuda = mdlg.addRatio / 100.0;int x; int y;int nRows = m_sImage.GetHeight();int nCols = m_sImage.GetWidth();int nBPP = m

28、_sImage.GetBPP();m_rImage.Destroy();if (!m_rImage.Create(nCols, nRows, nBPP)lsImage.Destroy();return;BYTE *sImageData = (BYTE *)m_sImage.GetBits();BYTE *lsImageData = (BYTE *)lsImage.GetBits();BYTE *rImageData = (BYTE *)m_rImage.GetBits();int nRowBytes = m_sImage.GetPitch();int sRowBytes = m_sImage.

29、GetPitch();for (y = 0; y nRows; y+)for (x = 0; x nCols ; x+)rImageDatay * nRowBytes + x * 3 + 0 = (int)(lambuda * sImageDatay * nRowBytes + x * 3 + 0 + (1- lambuda) * lsImageDatay * nRowBytes + x * 3 + 0 );rImageDatay * nRowBytes + x * 3 + 1 = (int)(lambuda * sImageDatay * nRowBytes + x * 3 + 1 + (1

30、 - lambuda) * lsImageDatay * nRowBytes + x * 3 + 1);rImageDatay * nRowBytes + x * 3 + 2 = (int)(lambuda * sImageDatay * nRowBytes + x * 3 + 2 + (1 - lambuda) * lsImageDatay * nRowBytes + x * 3 + 2);lsImage.Destroy(); UpdateAllViews(NULL);/图像相乘void CImageProcessingDoc:OnImageMul()CImage lsImage;CStri

31、ng strFilter;CSimpleArray aguidFileTypes;HRESULT hResult;/ 获取CImage支持的图像文件的过滤字符串hResult = m_sImage.GetExporterFilterString(strFilter, aguidFileTypes, _T(All Image Files);if (FAILED(hResult)AfxMessageBox(_T(GetExporterFilter函数失败!);return;CFileDialog dlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST, strFilter)

32、;if (IDOK != dlg.DoModal()return;lsImage.Destroy();/ 将外部图像文件装载到CImage对象中hResult = lsImage.Load(dlg.GetPathName();int x;int y;int nRows = m_sImage.GetHeight();int nCols = m_sImage.GetWidth();int nBPP = m_sImage.GetBPP();m_rImage.Destroy();if (!m_rImage.Create(nCols, nRows, nBPP)lsImage.Destroy();return;BYTE *sImageData = (BYTE *)m_sImage.GetBits();BYTE *lsImageData = (BYTE *)lsImage.GetBits();BYT

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论