VC6.0图像处理3--灰度变换

源码下载:http://download.csdn.net/detail/renshengrumenglibing/3875522

//书接前文,我们继续看一些灰度操作,由于比较简单,我们多放几个函数

//添加菜单以及处理函数 

void CBMPViewerDoc::OnMenuitem32777() //灰度拉伸
{
// TODO: Add your command handler code here

int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


int r1  = 60;
int r2 = 200;
double  k = 1.5;
// TODO: Add your command handler code here




// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
unsigned char *lpScr;
lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i -1) + j;


// *(lpScr) = BYTE((*lpScr - min)*256/(max- min));
// *(lpScr) = BYTE(0);


if(*lpScr < r1){
*lpScr = BYTE(*lpScr/ k);
}
else if(*lpScr < r2){
*lpScr = BYTE((*lpScr - r1)*k + r1/k);
}
else {
*lpScr = BYTE((*lpScr - r2)/k + 255 -(255 -r2)/k);
}
}

}
       UpdateAllViews(NULL,0,NULL);

}


void CBMPViewerDoc::OnMenuitem32780() //亮度增减  亮度增加20
{
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
unsigned char *lpScr;
lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i -1) + j;
if(*lpScr < 235){
*(lpScr) = BYTE(*lpScr +20);
}
else *lpScr = BYTE(255);
}

}

// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);

}


void CBMPViewerDoc::OnMenuitem32781() //取对数
{
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
unsigned char *lpScr;
lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i -1) + j;
double c ;
c = 255/log(255);
*lpScr  = BYTE(c*log(*lpScr +1));
}

}

// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);

}


void CBMPViewerDoc::OnMenuitem32782() //取指数
{
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
unsigned char *lpScr;
lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i -1) + j;
double c ;
c = 255/pow(255 ,2);
*lpScr  = BYTE(c*pow(*lpScr , 2));
}

}

// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);

}


void CBMPViewerDoc::OnMenuitem32785() //降低亮度
{
// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;


// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
unsigned char *lpScr;
lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i -1) + j;

if(*lpScr > 20){
*(lpScr) = BYTE(*lpScr -20);
}
else *lpScr = BYTE(0);
}

}

// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值