0

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.

Nasiba
  • 321
  • 2
  • 15
  • Since you've tagged this post as MATLAB, I'm assuming you're open to solutions in that language as well. You first need to **understand** how histogram equalization works. Once you do that, the code is very easy to understand. That C code is straight up histogram equalization. Please read the duplicate and figure out how it works first. Once you do that, the code will be simple to understand. – rayryeng Sep 20 '15 at 03:31
  • I know how transfer-function based equalization works. But I want to manipulate the values using bucket-filling method, which basically means that I want a histogram of equal length for all pixels. Do you know how that works? – Nasiba Sep 20 '15 at 03:37
  • Again that's histogram equalization. Read the duplicate. – rayryeng Sep 20 '15 at 03:39
  • Here is the thing, I don't understand the intuition of how that works on coding? – Nasiba Sep 20 '15 at 03:46

0 Answers0