I am really a novice in C. I need to understand a portion of code whose parameters I am gonna explain below. Suppose we have an image of sizeI and sizeJ which relates to row and column. We are supposed to do cumulative-probability-based histogram equalization method. Can someone explain what this code means?
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;
}
}
I know that the first part is doing histogram and cumulative histogram. Can you please explain what the next part is doing?
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;
}
}
I would be grateful for any sort of help. Thanks.