1、直方图均衡化
把集中分布的像素范围扩大,使像素分布更加均衡,起到增强的作用。至itk5没有现成函数,以下是实现代码:
void image_enhance_grayhis(InternalImageType::Pointer image, InternalImageType::Pointer OriImage)
{
int width = image->GetLargestPossibleRegion().GetSize()[0];
int heigth = image->GetLargestPossibleRegion().GetSize()[1];
unsigned int his[256] = { 0 };
float p_hist[256] = { 0 };
float s_hist[256] = { 0 };
float total = width * heigth;
for (int i = 0; i < width; i++)
{
for (int j = 0; j < heigth; j++)
{
int nPixel = fPixel;
if (nPixel < 0)
nPixel = 0;
else if (nPixel > 255)
nPixel = 255;
his[nPixel]++;
}
}
for (int i = 0; i < 256; i++)
{
p_hist[i] = (float)his[i] / total;
if (i == 0)s_hist[i] = p_hist[i];
else s_hist[i] = s_hist[i - 1] + p_hist[i];
}
InternalImageType::IndexType pixelIndex;
float