determine the number of unique image colors

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
samson
Posts: 5
Joined: 2019-12-01T06:25:32-07:00
Authentication code: 1152

determine the number of unique image colors

Post by samson »

How to determine the number of unique image colors? I tried the image.UniqueColors () method; but it returns the number of all colors in the image. And you need to get the number of unique colors.

User avatar
fmw42
Posts: 26282
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: determine the number of unique image colors

Post by fmw42 »

Please post your image to some free hosting service and put the URL here so we can check it.

Your image probably has many many unique colors that only differ slightly.

samson
Posts: 5
Joined: 2019-12-01T06:25:32-07:00
Authentication code: 1152

Re: determine the number of unique image colors

Post by samson »


User avatar
fmw42
Posts: 26282
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: determine the number of unique image colors

Post by fmw42 »

JPG images are compresses and have millions of colors each of which may be only slightly different from others. So there is no small set of unique colors in your image. You can reduce the number of unique colors using +dither -colors X, were X<=256 or some other method to reduce the number of unique colors in your image.

samson
Posts: 5
Joined: 2019-12-01T06:25:32-07:00
Authentication code: 1152

Re: determine the number of unique image colors

Post by samson »

Please write the C # code

User avatar
fmw42
Posts: 26282
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: determine the number of unique image colors

Post by fmw42 »

Sorry, I do not know Magick.Net, only the command line.

SLS8
Posts: 6
Joined: 2020-03-03T11:26:22-07:00
Authentication code: 1152

Re: determine the number of unique image colors

Post by SLS8 »

For your photo .UniqueColors() returns 105330 colors which is also the number returned by .TotalColors. IM command line returns the same result of 105330 for -unique-colors
anyway, if you want to have less unique colors and find which are those then use the dither suggestion

Code: Select all

         
img.Quantize(new QuantizeSettings() { DitherMethod = DitherMethod.No, Colors = 256 } );

Post Reply