CvScalar
定义可存放1—4个数值的数值,其结构如下。
typedef struct CvScalar
{
}
CvScalar;
------------------------------------------------
CvScalar pt;
如果使用的图像是1通道的,则pt.val[0]中存储数据
如果使用的图像是3通道的,则pt.val[0],pt.val[1],pt.val[2]中存储数据
==============================
获得/更改图像像素参数值
cvGet2D 获得某个点的值, idx0=hight 行值, idx1=width 列值。
CVAPI(CvScalar) cvGet2D( const CvArr* arr, int idx0, int idx1 );
cvSet2D 给某个点赋值。
CVAPI(void) cvSet2D( CvArr* arr, int idx0, int idx1, CvScalar value );
还有cvSet3D cvSetND
对于单通道我们有double cvmget( const CvMat* mat, int row, int col);
和 void cvSet2D(const CvMat* mat, int idx0, int idx1, double value);
二值化函数
Threshold
对数组元素进行固定阈值操作 事实上是对于单通道的数组进行处理,即src为单通道的
void cvThreshold( const CvArr* src, CvArr* dst, double threshold, double max_value, int threshold_type );
-
src
- 原始数组 (单通道 , 8-bit of 32-bit 浮点数). dst
- 输出数组,必须与 src 的类型一致,或者为 8-bit. threshold
- 阈值 max_value
- 使用 CV_THRESH_BINARY 和 CV_THRESH_BINARY_INV 的最大值. threshold_type
- 阈值类型 (见讨论)
函数 cvThreshold 对单通道数组应用固定阈值操作。该函数的典型应用是对灰度图像进行阈值操作得到二值图像。(cvCmpS 也可以达到此目的) 或者是去掉噪声,例如过滤很小或很大象素值的图像点。本函数支持的对图像取阈值的方法由 threshold_type 确定:
threshold_type=CV_THRESH_BINARY:
dst(x,y) = max_value, if src(x,y)>threshold ;=0, otherwise.
threshold_type=CV_THRESH_BINARY_INV:
dst(x,y) = 0, if src(x,y)>threshold; dst(x,y) = max_value, otherwise.
threshold_type=CV_THRESH_TRUNC:
dst(x,y) =
max_value,
if src(x,y)>threshold; dst(x,y) = src(x,y), otherwise.
threshold_type=CV_THRESH_TOZERO:
dst(x,y) = src(x,y), if (x,y)>threshold ; dst(x,y) = 0, otherwise.
threshold_type=CV_THRESH_TOZERO_INV:
dst(x,y) = 0, if src(x,y)>threshold ; dst(x,y) = src(x,y), otherwise.
自适应二值化函数---效果比较好
void cvAdaptiveThreshold(xxxxxx)
图像保存函数cvSaveImage(),需要include "highgui.h",具体参数如下:
int cvSaveImage( const char* filename, const CvArr* image);
filename:文件名,如果对应文件名存在将自动覆盖
image:想要存储的图片
函数cvSaveImage保存图像到指定文件。图像格式的的选择依赖于filename的扩展名,请参考cvLoadImage。只有8位单通道或者3通道(通道顺序为'BGR' )可以使用这个函数保存。如果格式,深度或者通道不符合要求,请先用cvCvtScale 和cvCvtColor转换;或者使用通用的cvSave保存图像为XML或者YAML格式。