灰度级分层是为了更好地提取图像某些区域灰度的亮度特征,常常应用于修复某些场景下造成的图像质量缺陷。常用的分成方法有两种:
- 将待提取的感兴趣区域的灰度值映射为同一值,其他不感兴趣的映射成另一值。最终的输出图像为二值图像。
- 将待提取的感兴趣区域映射变大或者变小,其他不感兴趣的灰度值保持不变,最终输出图像仍是灰度图像。
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
Mat grayLayered(Mat srcImage)
{
Mat resultImage = srcImage.clone();
int nRows = resultImage.rows;
int nCols = resultImage.cols;
if (resultImage.isContinuous())
{
nCols = nRows*nCols;
nRows = 1;
}
uchar *pDataMat;
int controlMin = 150;
int controlMax = 200;
for (int j = 0;