ht玩玩数字图像处理[2]---图像增强

  玩玩数字图像处理[2]---图像增强

            EmilMatthew (EmilMatthew@126.com)      

[  类别  ]算法实现   

[推荐指数]★★

[  摘要  ]本文主要介绍了基于灰度图像的图像增强方面的技术。

[ 关键词 ]图像增强

 

Playing With Digit Image Process [2] ------ Image Enhancement

[Classify] Algorithm Implementation  

[  Level ] ★★

[Abstract] This article mainly introduces the technology of Image enhancement based on the grey digit image.

[Key Words] Image Enhancement

 

[0引言]

    数字图像的增强工作,主要是对于原有图像中需要重点观测内容进行突出,而对非重点观测内容则进行抑制。本文主要介绍两种效用较为明显的方法:1. 直方图的均衡化。2.伪彩色方法。其余的方法,如对比度线性展宽,灰级窗等相对容易,具体请参考[1]

 

[1直方图的均衡化方法]

    直方图均衡化的方法的主要目的,简单说来,就是将原来出现频率较高的像素范围进行展宽,而对出现频率较低的像素,则尽可能的将其像素范围进行压缩,以期达到突出画面主要内容的目的。

   具体来说,图像均衡化的方法如下:

   ht玩玩数字图像处理[2]---图像增强_第1张图片  

直方图的均衡化算法实现

void BMParse::equalizeOp(HDC inHdc,int offsetX,int offsetY)

{

                            //0.Inner value

                            int arrHists[256];

                            float pArr[256];

                           

                            int i,j;

                            long totalHistVal;

                           

                            //0.Valuable declaration

                           unsigned long outputPixel;

                            int tmpTableVal;

                           

                            //1.cal each grey value's fequence

                            for(i=0;i<256;i++)

                                   arrHists[i]=0;

 

                            for(j=0;j<mBMFileInfo.bmHeight;j++) 

                                   for(i=0;i<mBMFileInfo.bmWidth;i++)

                                   {

                                                        arrHists[bmpBWMatrix[j][i]]++;

                                   }

                           

                                                

                 //2.cal total hist value

                 totalHistVal=mBMFileInfo.bmHeight*mBMFileInfo.bmWidth;

                 

                //3.cal pi

pArr[0]=0;

pArr[1]=(float)arrHists[0]/(float)totalHistVal+(float)arrHists[1]/(float)totalHistVal;

 

                            //4.show out adjusted picture:

                            for(i=0;i<mBMFileInfo.bmHeight;i++)

                                          for(j=0;j<mBMFileInfo.bmWidth;j++)

                                          {

                                                        tmpTableVal=255*pArr[bmpBWMatrix[i][j]];

                                                       

       //make to windows color format

       outputPixel=((unsigned long)paletteArr[tmpTableVal].b)*65536+((unsigned long)paletteArr[tmpTableVal].g)*256+(unsigned long)paletteArr[tmpTableVal].r;      

                                                

                                          //output pixel

                                          SetPixel(inHdc,j+offsetX,i+offsetY,outputPixel);         

                            }

}

 

 ht玩玩数字图像处理[2]---图像增强_第2张图片  ht玩玩数字图像处理[2]---图像增强_第3张图片 

      1:庙宇原像                                2:庙宇均衡化后的图像

 

[2灰度图像的伪彩色处理]

    由于现实仪器设备彩采集数据能力的限制,如CT扫描仪,温度感知器等,这些仪器得到的图像通常仅为灰度图像。而灰度图像对于视觉的观测上对区域的区分不是十分明显,如医学上病灶的位置,或某个环境场中温度较高的区域,因此,将它们从灰度图像中突显出来就显得十分必要了。而伪彩色处理技术则不失为一种有效的处理方式,虽然“彩”色的效果距离真实还有相当的差距,但从伪彩色处理的效果上看,已经能够满足现实应用的要求了。

   灰度图像的伪彩色处理的原理如下:

根据色彩学方面的研究结果,将灰度图像对应到red , green , blue三个通道上,最后将三个通道的颜色值合成为需要显示的RGB颜色值即可。

       灰度值与三个通道的映射关系如图3、图4、图5所示:

                        ht玩玩数字图像处理[2]---图像增强_第4张图片

3:灰度与红色通道映射关系

      ht玩玩数字图像处理[2]---图像增强_第5张图片

 

4:灰度与绿色通道映射关系

      ht玩玩数字图像处理[2]---图像增强_第6张图片

 

5:灰度与蓝色通道映射关系

 

    伪彩色处理的算法实现:

void BMParse::changeGreyToColorMix(HDC inHdc,int offsetX,int offsetY)

 {   

                       //0.Inner Value declaration

                           unsigned long outputPixel;

                            int tmpTableVal;

                            int i,j;

                           

                            //1.Core part of false color change

                            for(i=0;i<mBMFileInfo.bmHeight;i++)

                                          for(j=0;j<mBMFileInfo.bmWidth;j++)

                                          {

                                                 //1.1color change ,show out

                                                 //red channel

                                                 if(bmpBWMatrix[i][j]<128)

                                                               tmpTableVal=0;

                                                 else if(bmpBWMatrix[i][j]<192)

                                                                                                                        tmpTableVal=255/64*(bmpBWMatrix[i][j]-128);

                                                 else

                                                 tmpTableVal=255;

                                                                                   

                                                 outputPixel=(unsigned long)tmpTableVal;    

                                                                                                                                                                                     

                                     //green channel

                                     if(bmpBWMatrix[i][j]<64)

                                                                                                         tmpTableVal=255/64*bmpBWMatrix[i][j];

                                     else if(bmpBWMatrix[i][j]<192)

                                                 tmpTableVal=255;

                                                   else                                                                               tmpTableVal=-255/63*(bmpBWMatrix[i][j]-192)+255;

                                                                                   

                                           outputPixel+=(unsigned long)tmpTableVal*256;      

                                                                                                                      

                                      //blue channel

                                          if(bmpBWMatrix[i][j]<64)

                                                 tmpTableVal=255;

                                          else if(bmpBWMatrix[i][j]<128)

                                                                                                                        tmpTableVal=-255/64*(bmpBWMatrix[i][j]-64)+255;

                                          else

                                             tmpTableVal=0;

                                          outputPixel+=(unsigned long)tmpTableVal*65536;   

                                                                                   

                                          //1.2show out

                                          SetPixel(inHdc,j+offsetX,i+offsetY,outputPixel);

                                   }

                                         

}            

 

    ht玩玩数字图像处理[2]---图像增强_第7张图片    ht玩玩数字图像处理[2]---图像增强_第8张图片

 图6:庙宇像的红色通道                       图7: 庙宇像伪彩色化后的结果

    从实验结果可以看出,在现实条件下温度较高或较亮的区域中,呈现红色调;而对于较冷或暗的区域则以蓝色调显示,中间的颜色则以绿色调呈现。

 

[参考文献与网站]

[0] 朱虹等著,数字图像处理基础,科学出版社,2005.

程序完成日: 06/09/24

文章完成日: 06/09/27

[源码下载]

注:源码中包括了1)对比度增强、2)对比度线性展宽、3)灰级窗、4)二值化5)直方图的均衡化、6)伪彩色,六种图像增强方法的源码。

http://emilmatthew.51.net/EmilPapers/0629ImageProcess2/code1.rar

http://emilmatthew.51.net/EmilPapers/0629ImageProcess2/code2.rar

http://emilmatthew.51.net/EmilPapers/0629ImageProcess2/code3.rar

http://emilmatthew.51.net/EmilPapers/0629ImageProcess2/code4.rar

 

若直接点击无法下载(或浏览),请将下载(或浏览)的超链接粘接至浏览器地( 推荐MYIEGREENBORWSER)址栏后按回车.若不出意外,此时应能下载.

若下载中出现了问题,请参考:

http://blog.csdn.net/emilmatthew/archive/2006/04/08/655612.aspx

 

 

 

你可能感兴趣的:(Algorithm,算法,windows,image,float,图像处理)