Total Unique Colors of an image?

Jan 21, 2015 at 6:20 PM
Edited Jan 21, 2015 at 6:20 PM
I need to get the total number of unique colors, currently i use this:
        Dim histogram As Dictionary(Of MagickColor, Integer) = IMG.Histogram
        MsgBox(histogram.Count)
Works great, however i wondered if there is a property in Magick.NET that already has read the number of colors when i load an image into it? I am trying to save up on operations :)

Thanks!
Coordinator
Jan 21, 2015 at 7:36 PM
Edited Jan 21, 2015 at 7:50 PM
The number of colors will always be calculated. There is a TotalColors property on the MagickImage class but I don't know if this will make a huge difference.
Jan 23, 2015 at 9:08 AM
dlemstra wrote:
The number of colors will always be calculated. There is a TotalColors property on the MagickImage class but I don't know if this will make a huge difference.
Awesome, thats what I needed! Well, atleast it will save me a line of code :)

One more question i have:

For same image In Magick.NET IMG.ColorType.ToString returns PaletteMatte
while in the command line identify -verbose img.png returns Type: PaletteAlpha

Is that due to the version difference of IM 6 in the command line and IM7 in Magick.NET?

Thanks!
Coordinator
Jan 23, 2015 at 11:08 AM
I committed a change yesterday when I also noticed the difference. ColorType will use Alpha instead of Matte.
Jan 23, 2015 at 5:24 PM
dlemstra wrote:
I committed a change yesterday when I also noticed the difference. ColorType will use Alpha instead of Matte.
Great, thank you :)