Question

I wanted to plot the RGB intensity graph of an image like sinusoidal waves for 3 colours. Can anyone please suggest any idea to do this ?

Was it helpful?

Solution

There are (in general) 256 levels (8-bits) for each color component. If the image has an alpha channel then the overall image bits per pixel will be 32, else for an RGB only image it will be 24.

I will push this out algorithmically to get the image histogram, it will be up to you to write the drawing code.

// Arrays for the histogram data
int histoR[256];  // Array that will hold the counts of how many of each red VALUE the image had
int histoG[256];  // Array that will hold the counts of how many of each green VALUE the image had
int histoB[256];  // Array that will hold the counts of how many of each blue VALUE the image had
int histoA[256];  // Array that will hold the counts of how many of each alpha VALUE the image had

// Zeroize all histogram arrays
for(num = 0 through 255){
    histoR[num] = 0;
    histoG[num] = 0;
    histoB[num] = 0;
    histoA[num] = 0;
}

// Move through all image pixels counting up each time a pixel color value is used
for(x = 0 through image width){
    for(y = 0 through image height){
        histoR[image.pixel(x, y).red]   += 1;
        histoG[image.pixel(x, y).green] += 1;
        histoB[image.pixel(x, y).blue]  += 1;
        histoA[image.pixel(x, y).alpha] += 1;
    }
}

You now have the histogram data, it is up to you to plot it. PLEASE REMEMBER THE ABOVE IS ONLY AN ALGORITHMIC DESCRIPTION, NOT ACTUAL CODE

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top