05-05-2017 08:25 AM
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
Solved! Go to Solution.
05-05-2017 10:39 AM - edited 05-05-2017 10:55 AM
(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.
05-05-2017 11:09 AM
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?
05-05-2017 11:16 AM - edited 05-05-2017 11:17 AM
05-05-2017 11:23 AM
Here is some simple code.
(Note that this will not work for 24bit images. Your image is paletted, so it is OK.)
05-05-2017 11:26 AM - edited 05-05-2017 11:26 AM
05-05-2017 12:11 PM
Thank you very much for your help. Now i have the Histogram i need
05-05-2017 12:41 PM
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.