void CSDIELSView::OnSharpeningEnhance()
{
//程序编制:李立宗 lilizong@gmail.com
//2012-8-12
if(myImage1.IsNull())
OnOpenResourceFile();
if(!myImage2.IsNull())
myImage2.Destroy();
if(myImage2.IsNull()){
myImage2.Create(myImage1.GetWidth(),myImage1.GetHeight(),24,0);
}
//COLORREF pixel;
int maxY = myImage1.GetHeight();
int maxX=myImage1.GetWidth();
byte* pRealData;
byte* pRealData2;
pRealData=(byte*)myImage1.GetBits();
pRealData2=(byte*)myImage2.GetBits();
int pit=myImage1.GetPitch();
int pit2=myImage2.GetPitch();
//需要注意,pit和pit2的值并不一样,所以如果使用一个值,会导致不同的结果出现
//CString str;
//str.Format(TEXT("%d"),pit);
//MessageBox(str);
//str.Format(TEXT("%d"),pit2);
//MessageBox(str);
int bitCount=myImage1.GetBPP()/8;
int bitCount2=myImage2.GetBPP()/8;
int tempR,tempG,tempB;
int tempX,tempY;
int temp;
float tempA;
//int M[3][3]={{1,2,1},{2,4,2},{1,2,1}};
int t=100; //门限
int f=1; //参数,原图像的比例值
float maxR,minR,maxG,minG,maxB,minB;
float spanR,spanG,spanB;
static int tempArray[1000][1000][3]={0}; //必须定义为static,否则无法支持大数组
// tempR=tempG=tempG=0;
//说明:将生产的图像作为24位图处理。
for (int y=1; y<maxY-1; y++) {
for (int x=1; x<maxX-1; x++) {
temp=
*(pRealData+pit*(y-1)+(x-1)*bitCount)+*(pRealData+pit*(y-1)+(x)*bitCount)+*(pRealData+pit*(y-1)+(x+1)*bitCount)
+*(pRealData+pit*(y)+(x-1)*bitCount)-8*(*(pRealData+pit*(y)+(x)*bitCount))+*(pRealData+pit*(y)+(x+1)*bitCount)
+*(pRealData+pit*(y+1)+(x-1)*bitCount)+*(pRealData+pit*(y+1)+(x)*bitCount)+*(pRealData+pit*(y+1)+(x+1)*bitCount);
if(temp>255)
temp=255;
if(temp<-255)
temp=-255;
tempArray[y][x][0]=f*(*(pRealData+pit*(y)+(x)*bitCount))+temp+0.5;
if(bitCount==1)
{
/*tempG=tempR;
tempB=tempR;*/
tempArray[y][x][1]=tempArray[y][x][0];
tempArray[y][x][2]=tempArray[y][x][0];
}
else
{
temp=
*(pRealData+pit*(y-1)+(x-1)*bitCount+1)+*(pRealData+pit*(y-1)+(x)*bitCount+1)+*(pRealData+pit*(y-1)+(x+1)*bitCount+1)
+*(pRealData+pit*(y)+(x-1)*bitCount+1)-8*(*(pRealData+pit*(y)+(x)*bitCount+1))+*(pRealData+pit*(y)+(x+1)*bitCount+1)
+*(pRealData+pit*(y+1)+(x-1)*bitCount+1)+*(pRealData+pit*(y+1)+(x)*bitCount+1)+*(pRealData+pit*(y+1)+(x+1)*bitCount+1);
if(temp>255)
temp=255;
if(temp<-255)
temp=-255;
tempArray[y][x][1]=f*(*(pRealData+pit*(y)+(x)*bitCount+1))+temp+0.5;
temp=
*(pRealData+pit*(y-1)+(x-1)*bitCount+2)+*(pRealData+pit*(y-1)+(x)*bitCount+2)+*(pRealData+pit*(y-1)+(x+1)*bitCount+2)
+*(pRealData+pit*(y)+(x-1)*bitCount+2)-8*(*(pRealData+pit*(y)+(x)*bitCount+2))+*(pRealData+pit*(y)+(x+1)*bitCount+2)
+*(pRealData+pit*(y+1)+(x-1)*bitCount+2)+*(pRealData+pit*(y+1)+(x)*bitCount+2)+*(pRealData+pit*(y+1)+(x+1)*bitCount+2);
if(temp>255)
temp=255;
if(temp<-255)
temp=-255;
tempArray[y][x][2]=f*(*(pRealData+pit*(y)+(x)*bitCount+2))+temp+0.5;
}
}
}
maxR=maxG=maxB=0;
minR=minG=minB=65535;
for (int y=1; y<maxY-1; y++) {
for (int x=1; x<maxX-1; x++) {
if(maxR<(tempArray[y][x][0]))
maxR=tempArray[y][x][0];
if(maxG<(tempArray[y][x][1]))
maxG=tempArray[y][x][1];
if(maxB<(tempArray[y][x][2]))
maxB=tempArray[y][x][2];
if(minR>(tempArray[y][x][0]))
minR=tempArray[y][x][0];
if(minG>(tempArray[y][x][1]))
minG=tempArray[y][x][1];
if(minB>(tempArray[y][x][2]))
minB=tempArray[y][x][2];
}
}
spanR=maxR-minR;
spanG=maxG-minG;
spanB=maxB-minB;
for (int y=1; y<maxY-1; y++) {
for (int x=1; x<maxX-1; x++) {
if(spanR>0)
tempR=(int)(tempArray[y][x][0]-minR)*255/spanR;
else if(tempArray[y][x][0]<=255)
tempR=tempArray[y][x][0];
else
tempR=255;
if(spanG>0)
tempG=(int)(tempArray[y][x][1]-minR)*255/spanR;
else if(tempArray[y][x][1]<=255)
tempG=tempArray[y][x][1];
else
tempG=255;
if(spanB>0)
tempB=(int)(tempArray[y][x][2]-minR)*255/spanR;
else if(tempArray[y][x][2]<=255)
tempB=tempArray[y][x][2];
else
tempB=255;
*(pRealData2+pit2*y+x*bitCount2)=tempR;
*(pRealData2+pit2*y+x*bitCount2+1)=tempG;
*(pRealData2+pit2*y+x*bitCount2+2)=tempB;
}
}
Invalidate();
}
分享到:
相关推荐
matlab 非锐化掩蔽、高提升滤波
数字图像处理实验报告:图像的空域滤波 实验内容: 1、读出“girl.bmp”等一幅灰度图像。给读出的图像加入高斯噪声。 2、分别采用3*3、5*5、7*7的模板对加有高斯噪声的图像进行均值滤波,在一个图形显示窗口中显示原...
图像处理 中值滤波与均值滤波 matlab算法实现
中值滤波VC实现主代码
2.内容:基于matlab实现图像的双边滤波去噪和三边滤波去噪仿真+matlab操作视频 3.用处:用于图像的双边滤波去噪和三边滤波去噪算法编程学习 4.指向人群:本硕博等教研学习使用 5.运行注意事项: 使用matlab2021...
图像处理 逆滤波处理 C/C++语言实现..........................
灰度图像的中值滤波算法verilog实现,并且实现了前端摄像头的采集程序。
冈萨雷斯 数字图像处理(第三版)matlab代码 图3.40 非锐化掩蔽和高提升滤波
利用MATLAB实现了图像的正则化滤波,给出了lena的原始图、灰度图、加噪、模糊的图像、恢复图像对比等,对图像处理的学习有一定的帮助
数字图像处理 逆滤波 维纳滤波 数字图像处理 逆滤波 维纳滤波 源代码 还有报告
matlab 图像处理 高通滤波程序,数字图像处理课程要求
数字图像处理中值滤波和均值滤波的C++代码实现,包含代码和待处理图片
软件具有图像滤波,图像匹配,图像编码等多种功能,采用VC开发平台。
这个程序是卡尔曼滤波程序,是用vc实现的,希望对大家有用。
通过matlab程序对图像进行高斯滤波,实现去噪效果。
通过MATLAB对图像进行高通滤波,注意将图像和文件存放在同一目录下
图像处理的matlab代码:Matlab实现图像低通滤波
matlab图像处理基础,滤波,必会的。摘要大于50字太坑。
数字图像处理 中值滤波 C语言 数字图像处理 中值滤波 C语言
用java实现中值滤波与均值滤波,具体包括通过按钮实现对彩色图像的滤波处理。