//opencv 拆分像素處理映射
Mat Temp_Image = This->cv_Image;
int Width = Temp_Image.cols;
int Height = Temp_Image.rows;
float HuiDu[256];
float TongJi[256];
memset(&HuiDu, 0, 256);
memset(&TongJi, 0, 256);
//統計影像每個灰度級像素個數
for (int H = 0; H < Height; H++)
{
uchar* ptr = Temp_Image.ptr<uchar>(H);
for (int W = 0; W < Width; W++)
{
int temp = ptr[W];
HuiDu[temp]++;
}
}
//統計影像每個灰度級像素的累積個數
for (int c = 0; c <256; c++)
{
TongJi[c] = HuiDu[c] / Width * Height * 1.0f;//每一個像素點的概率
}
//均衡處理
float Linshi[256];
int nDstGray[256];
memset(&Linshi, 0, 256);
memset(&nDstGray, 0, 256);
for (int a = 0; a < 256; a++)
{
if (a == 0)
{
Linshi[0] = TongJi[0];
}
else
{
Linshi[a] = Linshi[a - 1] + TongJi[a];//每個像素點的累積概率
}
nDstGray[a] = (255.0f * Linshi[a] + 0.5f);
}
//映射
Mat New_Image = Temp_Image;
New_Image.rows = Height;
New_Image.cols = Width;
//uchar* ptr = Temp_Image.ptr<uchar>(Height);
//uchar* N_ptr = New_Image.ptr<uchar>(New_Image.rows);
for (int G = 0; G < New_Image.rows; G++)
{
//uchar* ptr = Temp_Image.ptr<uchar>(G);
uchar* N_ptr = New_Image.ptr<uchar>(G);
for (int K = 0; K < New_Image.cols; K++)
{
int temp = N_ptr[K];
N_ptr[K] = nDstGray[temp];
}
}
imshow("ZhiFangTu",New_Image);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/74886.html
標籤:圖形處理/算法
