解密代码

时间:2015-09-20 03:18:28

标签: c++ c matlab

我真的是C的新手。我需要理解一部分代码,其参数我将在下面解释。假设我们有一个sizeI和sizeJ的图像,它与行和列有关。我们应该做基于累积概率的直方图均衡方法。有人可以解释这段代码的含义吗?

int histLevelIndex[256];
int histCumuBefore[256];
int N = totalN / 256; // Average N pixel for each level
for(int color=0; color<3; color++)
{
    memset(histCumuBefore,0,256*sizeof(int));
    memset(histLevelIndex,0,256*sizeof(int));
    memset(histogram,0,256*sizeof(int)); // Initialize it into 0
    for(int i=0; i<SizeI; i++)
    {
        for(int j=0; j<SizeJ; j++)
        {
            histogram[ImageData[i][j][color]] ++;
        }
    }
    histCumuBefore[0] = 0;
    for(int i=1; i<256; i++)
    {
        histCumuBefore[i] = histCumuBefore[i-1] + histogram[i-1];
    }
    // No explicit transfer function used here, since transformation of some pixel is based on pixel's order
    for(int i=0; i<SizeI; i++)
    {
        for(int j=0; j<SizeJ; j++)
        {
            histLevelIndex[ImageData[i][j][color]] ++;
            int L = (histCumuBefore[ImageData[i][j][color]]+histLevelIndex[ImageData[i][j][color]]-1) / N;
            if(L>=256)
                L = 255;
            ImageDataOut[i][j][color] = L;
        }
    }

我知道第一部分是直方图和累积直方图。你能解释一下下一部分在做什么吗?

 for(int i=0; i<SizeI; i++)
    {
        for(int j=0; j<SizeJ; j++)
        {
            histLevelIndex[ImageData[i][j][color]] ++;
            int L = (histCumuBefore[ImageData[i][j][color]]+histLevelIndex[ImageData[i][j][color]]-1) / N;
            if(L>=256)
                L = 255;
            ImageDataOut[i][j][color] = L;
        }
    }

我会感激任何形式的帮助。感谢。

0 个答案:

没有答案
相关问题