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);
}
輸出: