LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a Histogram of colors from array of pixels

Solved!
Go to solution

Hi

I'm trying to create a histogram of the colors in a png file. For now my VI open the png and then it take the informations such width height ecc, from a cluster. Then i create an array with all colors fro an image with depth 8 bit (0 to 255), what i tried so far is to compare the array with all the pixels of the image and the array of colors, so that i can remove the colors that aren't in the image from the array and make an Histogram to use later to understand how many colors i have in my image and which are.

How can i remove these colors from my Histogram?

 

Thank you for your time

0 Kudos
Message 1 of 8
(4,058 Views)

(I assume you have a paletted image. can you attach the image?)

 

Initialize an I32 array of zeros with size 256 and put it in a shift register of a FOR loop.

 

Autoindex on the FOR loop with the image data.

 

For each pixel, increment the value corresponding to the color index to create a histogram.

 

At the end, keep only the indices where the element is nonzero. These are the used colors.

0 Kudos
Message 2 of 8
(4,014 Views)

Thank you for the answer

I attached the image, but i didn't really understand the two last point.

Can you be more specific please?

 

0 Kudos
Message 3 of 8
(4,003 Views)
Solution
Accepted by topic author AppenzellerMann

Maybe something like this?

 

0 Kudos
Message 4 of 8
(3,996 Views)

Here is some simple code.

(Note that this will not work for 24bit images. Your image is paletted, so it is OK.)

0 Kudos
Message 5 of 8
(3,992 Views)
0 Kudos
Message 6 of 8
(3,990 Views)

Thank you very much for your help. Now i have the Histogram i need

0 Kudos
Message 7 of 8
(3,980 Views)

Of course you want to add some error handling to detect if the image is not paletted. If so, skip the code and return an error.

Doing the same on a 24bit image would require more expensive algorithms, but is doable.

0 Kudos
Message 8 of 8
(3,968 Views)