VC6.0图像处理3--灰度变换
2011-08-31 23:26 libing64 阅读(726) 评论(0) 编辑 收藏 举报源码下载: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);
}