图像灰度值调整(C/C++源代码)
2008-04-11 19:11
387 查看
2004年09月23日 16:00:00
图像的象素值变换,包括亮度、对比度和GAMMA校正算法,环境是OPENCV4.0,VC6.0。算法参考了MATLAB函数imadjust
。
//
// perform histgram equalization for single channel image
//
#include "cv.h"
#include "highgui.h"
int ImageAdjust(IplImage* src, IplImage* dst,
double
low, double high, // lowand
high are the intensities of src
double
bottom, double top, // mapped to bottom and top of dst
double
gamma )
{
double low2=
low*255;
double
high2= high*255;
doublebottom2 = bottom*255;
double top2=
top*255;
doubleerr_in
= high2 - low2;
doubleerr_out = top2 - bottom2;
intx,y;
doubleval;
if(low<0 && low>1 &&
high <0 &&high>1 &&
bottom<0 && bottom>1
&&top<0 &&
top>1)
return
1;
//
intensitytransform
for( y = 0;y
< src->height; y++)
{
for
(x = 0; x < src->width; x++)
{
val
= ((uchar*)(src->imageData +
src->widthStep*y))[x];
val
= pow((val - low2)/err_in, gamma) * err_out + bottom2;
if(val>255)
val=255; if(val<0) val=0; // Make sure src is inthe
range [low,high]
((uchar*)(dst->imageData
+ dst->widthStep*y))[x] = (uchar)val;
}
}
return0;
}
Trackback:http://tb.blog.csdn.net/TrackBack.aspx?PostId=114398
分享到新浪微博
图像的象素值变换,包括亮度、对比度和GAMMA校正算法,环境是OPENCV4.0,VC6.0。算法参考了MATLAB函数imadjust
。
//
// perform histgram equalization for single channel image
//
#include "cv.h"
#include "highgui.h"
int ImageAdjust(IplImage* src, IplImage* dst,
double
low, double high, // lowand
high are the intensities of src
double
bottom, double top, // mapped to bottom and top of dst
double
gamma )
{
double low2=
low*255;
double
high2= high*255;
doublebottom2 = bottom*255;
double top2=
top*255;
doubleerr_in
= high2 - low2;
doubleerr_out = top2 - bottom2;
intx,y;
doubleval;
if(low<0 && low>1 &&
high <0 &&high>1 &&
bottom<0 && bottom>1
&&top<0 &&
top>1)
return
1;
//
intensitytransform
for( y = 0;y
< src->height; y++)
{
for
(x = 0; x < src->width; x++)
{
val
= ((uchar*)(src->imageData +
src->widthStep*y))[x];
val
= pow((val - low2)/err_in, gamma) * err_out + bottom2;
if(val>255)
val=255; if(val<0) val=0; // Make sure src is inthe
range [low,high]
((uchar*)(dst->imageData
+ dst->widthStep*y))[x] = (uchar)val;
}
}
return0;
}
Trackback:http://tb.blog.csdn.net/TrackBack.aspx?PostId=114398
分享到新浪微博
相关文章推荐
- 灰度图像亮度对比度调整的简单代码
- 数字图像处理 -灰度变换 之 对数变换(Log Transformation)
- 灰度图像--频域滤波 傅里叶变换之二维离散傅里叶变换
- AMP 学习2 图像灰度,c#比c++ amp快?
- 再学 GDI+[92]: TGPImage(12) - 调整图像透明度
- Qt 图像处理之 灰度变换
- 灰度图像转换为彩色
- 灰度图像拉伸方法
- 【Android】使用OpenCV彩色图像转灰度图像
- 灰度图像 阀值变换
- 【OpenCV入门教程之六】 创建Trackbar & 图像对比度、亮度值调整
- C# 图像灰度处理
- 图像处理------特殊灰度算法技巧
- 灰度与灰度图像
- 在灰度图像上进行Mean Shift迭代搜索目标 ,一维加权直方图 + 巴氏系数 + Mean Shift迭代
- PS 图像调整算法——亮度调整
- CImgProcess::Histeq(CImgProcess * pTo) 图像的灰度 均衡化
- 灰度图像的8位平面分解
- 图像处理之调整亮度与饱和度
- PS 图像调整算法——阈值