saturate_cast¶
Template function for accurate conversion from one primitive type to another.
-
C++:
template<...> _Tp
saturate_cast
(_Tp2
v
)
¶
-
Parameters: - v – Function parameter.
The functions saturate_cast resemble the standard C++ cast operations, such asstatic_cast<T>() and others. They perform an efficient and accurate conversion from one primitive type to another (see the introduction chapter).saturate in the name means that when the input valuev is out of the range of the target type, the result is not formed just by taking low bits of the input, but instead the value is clipped. For example:
uchar a = saturate_cast<uchar>(-100); // a = 0 (UCHAR_MIN)
short b = saturate_cast<short>(33333.33333); // b = 32767 (SHRT_MAX)
Such clipping is done when the target type is unsignedchar ,signedchar ,unsignedshort orsignedshort . For 32-bit integers, no clipping is done.
When the parameter is a floating-point value and the target type is an integer (8-, 16- or 32-bit), the floating-point value is first rounded to the nearest integer and then clipped if needed (when the target type is 8- or 16-bit).
This operation is used in the simplest or most complex image processing functions in OpenCV.
See also
add(),subtract(),multiply(),divide(),Mat::convertTo()
考虑:为什么上面的函数会用到saturate_cast呢,因为无论是加是减,乘除,都会超出一个像素灰度值的范围(0~255)所以,所以当运算完之后,结果为负,则转为0,结果超出255,则为255。
另外在梯度锐化的函数里,也会涉及到saturate_cast。
如:
from: http://ggicci.blog.163.com/blog/static/210364096201262123236955/
OpenCV图像处理 空间域图像增强(图像锐化 1 基于拉普拉斯算子)
2012-07-21 14:32:36| 分类:OpenCV/EmguCV| 标签:opencv图像处理 opencv图像锐化 拉普拉斯算子 空间域图像增强 opencv |字号大中小 订阅
Title :
- OpenCV
- OpenCV 图像锐化
- 拉普拉斯算子 ( Laplacian operator )
Quote :
It is indeed a well-known result in image processing that if you subtract its Laplacian from an image, the image edges are amplified giving a sharper image. [FromOpenCV 2 Computer Vision Application Programming Cookbook]
- 对于求一个锐化后的像素点(sharpened_pixel),这个基于拉普拉斯算子的简单算法主要是遍历图像中的像素点,根据领域像素确定其锐化后的值
- 计算公式:sharpened_pixel = 5 * current – left – right – up – down ; [见Code1]
- 当一个运算是通过领域像素进行的时候,我们通常用一个矩阵来表示这种运算关系,也就是我们经常所说的核 (Kernel)。那么上面的锐化滤波器 (Sharpening Filter) 就可以用这个矩阵表示为它的核:
-1 | ||
-1 | 5 | -1 |
-1 |
- 因为 滤波 在图像处理中是一个非常普通且常用的操作,所以OpenCV里面已经定义了一个特殊的函数用来执行这个操作。要使用它的话只需要定义一个核,然后作为参数传递就行了。[见Code2]
Code 1 :