图像处理算法基础(二)---线性变换和伽马变换
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;
}
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;
}
相关文章推荐
- 集差集 哈希表 比较数据库的照片和server画面上,将server垃圾上的图片删除
- 第十二周项目4-利用遍历思想求解图问题(2)
- 第十二周项目一:图基本算法库
- 第十五周项目2- 用哈希法组织关键字
- 第十二周项目5 迷宫问题(利用深度遍历算法)
- simplePagination API
- 285. Inorder Successor in BST
- EF+MVC+Bootstrap 项目实践 Day3
- 第十五周 项目2-用哈希法组织关键字
- struts2 Session拦截器
- Viminum设置自己的快捷键
- 微软和 Linux 基金会就 Linux on Azure 认证达成合作
- 微软和 Linux 基金会就 Linux on Azure 认证达成合作
- CSS选择器列表
- [转] 用管道获得shell 命令的输出
- hdu 2604 Queuing 递推+矩阵快速幂
- android常见错误
- Ubuntu常用命令大全
- Linux下Nvidia显卡驱动卸载和卸载后的问题
- ubuntu 下一个神奇的命令--以窗口形式打开某个文件夹