VC6.0图形处理6--图像增强
2011-09-01 12:49
295 查看
源码下载:http://download.csdn.net/detail/renshengrumenglibing/3875522
//本节包含高斯平滑,中值滤波和锐化三个部分,三者均为模板操作,只是模板不同,算法均相同,希望读者仔细研读其中之一,其他两个自然就明白了
void CBMPViewerDoc::OnMenuitem32790() //高斯平滑
{
// TODO: Add your command handler code here
//模板1/16*[1 2 1 ; 2 ,4 ,2 ; 1, 2,1]
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );
LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
int sum ;
int Gauss[9] = {1, 2, 1 , 2 ,4 ,2 , 1, 2,1 };
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = *lpScr;
}
else{
sum = 0 ;
for(int m = i -1 ; m <= i+1 ;m++){
for(int n = j-1; n<=j+1; n++){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
sum += (*lpScr) * Gauss[3*(m - i +1) + n - j +1];
}
}
sum/= 16;
if((sum >= 0 )&&(sum <= 255))
{
*lpDest = sum;
}
else if(sum > 255) *lpDest = 255;
else *lpDest= 0;
}
}
}
memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}
void CBMPViewerDoc::OnMenuitem32791() //锐化处理
{
//模板1/16*[1 1 1 ; 1 ,1 ,1 ; 1, 1,1]
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );
LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
int sum ;
int m_template[9] = {0, -1, 0 , -1 ,5 ,-1 , 0, -1,0 };
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = *lpScr;
}
else{
sum = 0 ;
for(int m = i -1 ; m <= i+1 ;m++){
for(int n = j-1; n<=j+1; n++){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
sum += (*lpScr) * m_template[3*(m - i +1) + n - j +1];
}
}
if((sum >= 0 )&&(sum <= 255))
{
*lpDest = sum;
}
else if(sum > 255) *lpDest = 255;
else *lpDest= 0;
}
}
}
memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}
void CBMPViewerDoc::OnMenuitem32792() //中值滤波
{
//模板1/16*[1 1 1 ; 1 ,1 ,1 ; 1, 1,1]
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );
LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
int sum ;
int m_template[9] = {1, 1, 1 , 1 ,1 ,1 , 1, 1,1 };
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = *lpScr;
}
else{
sum = 0 ;
for(int m = i -1 ; m <= i+1 ;m++){
for(int n = j-1; n<=j+1; n++){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
sum += (*lpScr) * m_template[3*(m - i +1) + n - j +1];
}
}
sum/= 9;
if((sum >= 0 )&&(sum <= 255))
{
*lpDest = sum;
}
else if(sum > 255) *lpDest = 255;
else *lpDest= 0;
}
}
}
memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}
//本节包含高斯平滑,中值滤波和锐化三个部分,三者均为模板操作,只是模板不同,算法均相同,希望读者仔细研读其中之一,其他两个自然就明白了
void CBMPViewerDoc::OnMenuitem32790() //高斯平滑
{
// TODO: Add your command handler code here
//模板1/16*[1 2 1 ; 2 ,4 ,2 ; 1, 2,1]
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );
LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
int sum ;
int Gauss[9] = {1, 2, 1 , 2 ,4 ,2 , 1, 2,1 };
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = *lpScr;
}
else{
sum = 0 ;
for(int m = i -1 ; m <= i+1 ;m++){
for(int n = j-1; n<=j+1; n++){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
sum += (*lpScr) * Gauss[3*(m - i +1) + n - j +1];
}
}
sum/= 16;
if((sum >= 0 )&&(sum <= 255))
{
*lpDest = sum;
}
else if(sum > 255) *lpDest = 255;
else *lpDest= 0;
}
}
}
memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}
void CBMPViewerDoc::OnMenuitem32791() //锐化处理
{
//模板1/16*[1 1 1 ; 1 ,1 ,1 ; 1, 1,1]
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );
LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
int sum ;
int m_template[9] = {0, -1, 0 , -1 ,5 ,-1 , 0, -1,0 };
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = *lpScr;
}
else{
sum = 0 ;
for(int m = i -1 ; m <= i+1 ;m++){
for(int n = j-1; n<=j+1; n++){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
sum += (*lpScr) * m_template[3*(m - i +1) + n - j +1];
}
}
if((sum >= 0 )&&(sum <= 255))
{
*lpDest = sum;
}
else if(sum > 255) *lpDest = 255;
else *lpDest= 0;
}
}
}
memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}
void CBMPViewerDoc::OnMenuitem32792() //中值滤波
{
//模板1/16*[1 1 1 ; 1 ,1 ,1 ; 1, 1,1]
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;
HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );
LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;
int sum ;
int m_template[9] = {1, 1, 1 , 1 ,1 ,1 , 1, 1,1 };
// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = *lpScr;
}
else{
sum = 0 ;
for(int m = i -1 ; m <= i+1 ;m++){
for(int n = j-1; n<=j+1; n++){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
sum += (*lpScr) * m_template[3*(m - i +1) + n - j +1];
}
}
sum/= 9;
if((sum >= 0 )&&(sum <= 255))
{
*lpDest = sum;
}
else if(sum > 255) *lpDest = 255;
else *lpDest= 0;
}
}
}
memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}
相关文章推荐
- VC6.0图形处理6--图像增强
- 图像处理实例--Retinex增强处理
- VC6.0图形处理9--轮廓提取
- 图形图像处理之——实现图形图像之子区域提取2
- 【Android开发】图形图像处理技术-使用BitmapShader渲染图像
- php图形图像处理
- 【Android开发】图形图像处理技术-实现Android动画的两种方式
- VC6.0图形处理技术和文字处理技术
- IOS中图形图像处理第一部分:位图图像原图修改
- 图像增强处理之:同态滤波与Retinex算法(三)Retinex邻域算法:SSR,MSR,MSRCR
- 图像处理1--VC6.0下directshow配置
- 图像预处理--灰度直方图--图像增强
- 冈萨雷斯数字图像处理学习4:频率域图像增强1
- iOS 图形图像处理 一 :位图图像原图修改
- 图像处理中傅里叶变换以及频率域图像增强详解
- java 图像处理截圆形的图形(修改版)
- 小波的秘密9_图像处理应用:图像增强
- Android绘图机制与处理技巧(三)——Android图像处理之图形特效处理
- OPENCV下针对IplImage实现图像增强处理
- iOS 图形图像处理 二 :Core Graphics 、Core Image and GPUImage