histogram in Magick.net

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
JWin
Posts: 1
Joined: 2019-12-13T17:32:17-07:00
Authentication code: 1152

histogram in Magick.net

Post by JWin »

Hi,
I have spent hours trying to get the following command working in Magick.net:
magick.exe input.png -define histogram:unique-colors=true -format %c histogram:info:-

I can use the Histogram like this but I don't know how to get the correct output format (-format %c):

Code: Select all

using (MagickImage image = new MagickImage("input.png"))
{
	var histogram = image.Histogram();
	
	if (histogram.ToString().Contains("55FF00"))
	{
		string yes = "Yes";
	}
}
Please can anyone advise how to get output like this, it's the hex colours I am interested in:

Code: Select all

     3: (255,252,246,  0) #FFFCF600 srgba(255,252,246,0)
        12: (255,252,250,  0) #FFFCFA00 srgba(255,252,250,0)
         5: (255,254,242,  0) #FFFEF200 srgba(255,254,242,0)
       120: (255,255,246,  0) #FFFFF600 srgba(255,255,246,0)
        96: (255,255,250,  0) #FFFFFA00 srgba(255,255,250,0)
    760159: (255,255,255,  0) #FFFFFF00 srgba(255,255,255,0)
    106741: (255,255,255,255) #FFFFFFFF white
Thank you.

J

snibgo
Posts: 12673
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: histogram in Magick.net

Post by snibgo »

Have you searched this forum for "format"? For example, https://www.imagemagick.org/discourse-s ... at#p166289
snibgo's IM pages: im.snibgo.com

User avatar
dlemstra
Posts: 1606
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: histogram in Magick.net

Post by dlemstra »

The Histogram method returns a dictionary with the colors. You will need to do something like this to find the color:

Code: Select all

image.Histogram().ContainsKey(new MagickColor("#55FF00"))
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

Post Reply