您的位置:首页 > 其它

图像处理算法基础(二)---线性变换和伽马变换

2015-12-11 08:14 531 查看
1.灰度线性变换:F(x)=a*f(x)+b

int IMGChange(IplImage *src,IplImage *dest, float slope,float intercept)

{

if(NULL == src)

return -1;

if(src->nChannels!=1 || dest->nChannels!=1)

{

cout<<"It's not gray image!"<<endl;

return -1;

}

float gray = 0;

for(int i = 0;i < src->height;i++){

for(int j = 0; j < src->width; j++){

gray = (float)src->imageData[src->widthStep * i + j ];

gray = slope*gray + intercept;

dest->imageData[dest->widthStep * i + j ]=gray;

}

}

return 0;

}

当slope=-1 intercept=255即为图像反转



2.伽马变换,s=c*(r)γ,可用于图像增强等预处理。



int IMGgammaChange(IplImage *src,IplImage *dest, double gamma,double comp)

{

if(NULL == src)

return -1;

if(src->nChannels!=1 || dest->nChannels!=1)

{

cout<<"It's not gray image!"<<endl;

return -1;

}

double gray = 0;

for(int i = 0;i < src->height;i++){

for(int j = 0; j < src->width; j++){

gray = (double)src->imageData[src->widthStep * i + j ];

gray =pow((gray+comp)/255.0,gamma)*255;

dest->imageData[dest->widthStep * i + j ]=gray;

}

}

return 0;

}





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: