LUT函数可以用于图像元素的查找、扫描和其他操作。
LUT函数定义
/** @brief Performs a look-up table transform of an array.
The function LUT fills the output array with values from the look-up table. Indices of the entries
are taken from the input array. That is, the function processes each element of src as follows:
\f[\texttt{dst} (I) \leftarrow \texttt{lut(src(I) + d)}\f]
where
\f[d = \fork{0}{if \(\texttt{src}\) has depth \(\texttt{CV_8U}\)}{128}{if \(\texttt{src}\) has depth \(\texttt{CV_8S}\)}\f]
@param src input array of 8-bit elements.
@param lut look-up table of 256 elements; in case of multi-channel input array, the table should
either have a single channel (in this case the same table is used for all channels) or the same
number of channels as in the input array.
@param dst output array of the same size and number of channels as src, and the same depth as lut.
@sa convertScaleAbs, Mat::convertTo
*/
CV_EXPORTS_W void LUT(InputArray src, InputArray lut, OutputArray dst);
- src表示的是输入图像(可以是单通道也可是3通道)
- lut表示查找表(查找表也可以是单通道,也可以是3通道,如果输入图像为单通道,那查找表必须为单通道,若输入图像为3通道,查找表可以为单通道,也可以为3通道,若为单通道则表示对图像3个通道都应用这个表,若为3通道则分别应用 )
- dst表示输出图像,大小和通道必须与src相同
例子:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
int main() {
Mat image = imread("C:\\Users\\thor\\Desktop\\1.png");
uchar table[256];
int divideWith = 100;
for (int i = 0; i < 256; i++)
table[i] = (i / divideWith)*divideWith;
Mat lut(1, 256, CV_8UC1, table);
Mat outputImage;
LUT(image, lut, outputImage);
imshow("原始图像", image);
imshow("输出图像", outputImage);
waitKey(0);
}
输出: