数字图像处理算法Word格式.docx

上传人:b****5 文档编号:19258801 上传时间:2023-01-04 格式:DOCX 页数:40 大小:36.54KB
下载 相关 举报
数字图像处理算法Word格式.docx_第1页
第1页 / 共40页
数字图像处理算法Word格式.docx_第2页
第2页 / 共40页
数字图像处理算法Word格式.docx_第3页
第3页 / 共40页
数字图像处理算法Word格式.docx_第4页
第4页 / 共40页
数字图像处理算法Word格式.docx_第5页
第5页 / 共40页
点击查看更多>>
下载资源
资源描述

数字图像处理算法Word格式.docx

《数字图像处理算法Word格式.docx》由会员分享,可在线阅读,更多相关《数字图像处理算法Word格式.docx(40页珍藏版)》请在冰豆网上搜索。

数字图像处理算法Word格式.docx

(1)在空间域图像处理中,对于一个图像我们往往需要对其逐个像素的进行处理,对每个像素的处理使用相同的算法(或者是图像中的某个矩形部分)。

即,对于图像f(x,y),其中0≤x≤M,0≤y≤N,图像为M*N大小,使用算法algo,则f(x,y)=algo(f(x,y))。

事先实现一个算法框架,然后再以函数指针或函数对象(functor,即实现operator()的对象)传入算法,可以减轻编程的工作量。

如下代码便是一例:

#ifndefPROCESSALGO_H

#definePROCESSALGO_H

#include<

windows.h>

Gdiplus.h>

namespacensimgtk

{

template<

typenamepixelType,Gdiplus:

PixelFormatpixelFormat,classProcessor>

boolProcessPixelsOneByOne(Gdiplus:

Bitmap*constp_bitmap,Processorprocessor,unsignedintx,unsignedinty,

 

unsignedintwidth,unsignedintheight)

{

if(p_bitmap==NULL)

returnfalse;

}

if((width+x>

p_bitmap->

GetWidth())||(height+y>

p_bitmap->

GetHeight()))

BitmapDatabitmapData;

Rectrect(x,y,width,height);

if(p_bitmap->

LockBits(&

rect,Gdiplus:

ImageLockModeWrite,pixelFormat,&

bitmapData)!

=Gdiplus:

Ok)

pixelType*pixels=(pixelType*)bitmapData.Scan0;

for(unsignedintrow=0;

row<

height;

++row)

for(unsignedintcol=0;

col<

width;

++col)

processor(&

pixels[col+row*bitmapData.Stride/sizeof(pixelType)]);

UnlockBits(&

returntrue;

}

#endif

ProcessPixelsOneByOne函数可以对图像中从(x,y)位置起始,width*height大小的区域进行处理。

模板参数pixelType用于指定像素大小,例如在Win32平台上传入unsignedchar即为8位,用于8阶灰度图。

模板参数Processor为图像处理算法实现,可以定义类实现voidoperator(pixelType*)函数,或者传入同样接口的函数指针。

如下便是一些算法示例(说明见具体注释):

#ifndefSPATIALDOMAIN_H

#defineSPATIALDOMAIN_H

cmath>

string>

//8阶灰度图的灰度反转算法 

classNegativeGray8

public:

voidoperator()(unsignedchar*constp_value)

*p_value^=0xff;

};

//8阶灰度图的Gamma校正算法

classGammaCorrectGray8

private:

unsignedchard_s[256];

GammaCorrectGray8:

GammaCorrectGray8(doublec,doublegamma);

voidoperator()(unsignedchar*constp_value)

*p_value=d_s[*p_value];

//8阶灰度图的饱和度拉伸算法

classContrastStretchingGray8

ContrastStretchingGray8:

ContrastStretchingGray8(doublea1,doubleb1,unsignedintx1,

doublea2,doubleb2,unsignedintx2,doublea3,doubleb3);

//8阶灰度图的位平面分割,构造函数指定位平面号

classBitPlaneSliceGray8

BitPlaneSliceGray8(unsignedcharbitPlaneNum);

voidoperator()(unsignedchar*constp_value)

//上述类中各构造函数的实现代码,应该分在另一个文件中,此处为说明方便,一并列出

#include"

SpatialDomain/spatialDomain.h"

GammaCorrectGray8(doublec,doublegamma)

doubletemp;

for(unsignedinti=0;

i<

256;

++i)

temp=ceil(c*255.0*pow(double(i)/255.0,gamma));

d_s[i]=unsignedchar(temp);

doublea2,doubleb2,unsignedintx2,doublea3,doubleb3)

if(x1>

255||x2>

255||x1>

x1)

d_s[i]=i;

else

doubletmp;

x1;

tmp=ceil(a1*double(i)+b1);

d_s[i]=(unsignedchar)tmp;

for(unsignedinti=x1;

x2;

tmp=ceil(a2*double(i)+b2);

for(unsignedinti=x2;

tmp=ceil(a3*double(i)+b3);

BitPlaneSliceGray8:

BitPlaneSliceGray8(unsignedcharbitPlaneNum)

unsignedcharbitMaskArray[8]=

0x01,0x02,0x04,0x08,

0x10,0x20,0x40,0x80

unsignedchartmp=i;

tmp&

=bitMaskArray[bitPlaneNum];

tmp=(tmp>

>

bitPlaneNum)*255;

d_s[i]=tmp;

(2)直方图在GDI+1.0中没有获得支持,我们必须自行实现。

直方图相关的处理在数字图像处理中占有重要地位,可以通过它获取图像灰度级的统计信息,且可以通过直方图进行一些重要的图像增强技术,如直方图均衡化,直方图规定化,基本全局门限等。

下面是获取8阶图像直方图的算法实现:

boolGetHistogramNormalizeGray8(Gdiplus:

Bitmap*constp_bitmap,float*histogramArray)

if(p_bitmap==NULL||histogramArray==NULL)

Rectrect(0,0,p_bitmap->

GetWidth(),p_bitmap->

GetHeight());

ImageLockModeRead,PixelFormat8bppIndexed,&

unsignedchar*pixels=(unsignedchar*)bitmapData.Scan0;

unsignedinthistogram[256];

for(inti=0;

histogram[i]=0;

GetWidth();

GetHeight();

++histogram[pixels[col+row*bitmapData.Stride]];

constunsignedinttotalPixels=p_bitmap->

GetWidth()*p_bitmap->

histogramArray[i]=float(histogram[i])/float(totalPixels);

在获取直方图后(即上面算法的第二个参数),再将其作为参数传入下面的对象的构造函数,然后以该对象为仿函数传入ProcessPixelsOneByOne即可实现8阶图像直方图均衡化:

//8阶灰度图的直方图均衡化

classHistogramEqualizationGray8

HistogramEqualizationGray8(constfloat*consthistogramArray);

#endif 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

HistogramEqualizationGray8:

HistogramEqualizationGray8(constfloat*consthistogramArray)

if(histogramArray!

=NULL)

floatsum=0.0;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 财务管理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1