www.pudn.com > inhanceImage.zip > main.cpp, change:2012-11-01,size:3212b


#include<cv.h> 
#include <cxcore.h> 
#include <highgui.h> 
#include <iostream> 
using namespace std; 
//#pragma comment(lib,"cv.lib") 
//#pragma comment(lib,"cxcore.lib") 
//#pragma comment(lib,"highgui.lib") 
#define B(image,x,y)((uchar*)(image->imageData+image->widthStep*(y)))[(x*3)]//B 
#define G(image,x,y)((uchar*)(image->imageData+image->widthStep*(y)))[(x*3)+1]//G 
#define R(image,x,y)((uchar*)(image->imageData+image->widthStep*(y)))[(x*3)+2]//R 
#define S(image,x,y)((uchar*)(image->imageData+image->widthStep*(y)))[(x)]                //S 
/************************************************************************/ 
/* 彩色图像进行拉普拉斯锐化                                                                     */ 
/************************************************************************/ 
void main() 
{ 
        IplImage *src; 
        IplImage *dst=NULL; 
        IplImage *dst1=NULL; 
        src=cvLoadImage("D://zhangchen_openCV//lena3.jpg",-1);//图像导入 
        dst=cvCloneImage(src); 
        int m,m1,m2; 
        int i,j; 
        dst1=cvCloneImage(dst); 
        int templt[9]={-1,-1,-1,-1,8,-1,-1,-1,-1}; 
        int x,y; 
        int scale; 
        int size=3; 
        scale = 3;//设定衰减因子 
        //依次对源图像的每个像素进行处理 
        for(j=size/2;j<dst1->height-size/2;j++) 
                for(i=size/2;i<dst1->width-size/2;i++) 
                { 
                        m=0;         
                        m1=0; 
                        m2=0; 
                        for(x=0;x<size;x++) 
                                for(y=0;y<size;y++) 
                                { 
                                        m+=B(dst1,(i-size/2+x),(j-size/2+y))*templt[x*size+y]; 
                                        m1+=G(dst1,(i-size/2+x),(j-size/2+y))*templt[x*size+y]; 
                                        m2+=R(dst1,(i-size/2+x),(j-size/2+y))*templt[x*size+y]; 
                                } 
                                m/= scale; 
                                //对中心像素进行增强 
                                m=B(dst,i,j)+m; 
                                //过限处理 
                                m = m>255?255:m;     
                                m = m<0?0:m; 
 
                                m1/= scale; 
                                //对中心像素进行增强 
                                m1=G(dst,i,j)+m1; 
                                //过限处理 
                                m1 = m1>255?255:m1;     
                                m1 = m1<0?0:m1; 
 
                                m2/= scale; 
                                //对中心像素进行增强 
                                m2=R(dst,i,j)+m2; 
                                //过限处理 
                                m2 = m2>255?255:m2;     
                                m2 = m2<0?0:m2; 
                                B(dst1,i,j)=m; 
                                G(dst1,i,j)=m1; 
                                R(dst1,i,j)=m2; 
 
                } 
                cvNamedWindow("dst",1); 
                cvNamedWindow("dst1",1); 
                cvShowImage("dst",dst); 
                cvShowImage("dst1",dst1); 
                cvWaitKey(0); 
}