can't get quantize to match posterize

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
tsftd
Posts: 28
Joined: 2012-01-14T11:46:55-07:00
Authentication code: 8675308

can't get quantize to match posterize

Post by tsftd »

Ok, so I'm wanting to posterize an image via magick++, searched the api, didn't find it, searched the forum, found someone asking if magick++ has it (several years ago), but he got no answer.

so, figuring that posterization was pretty similar to quantization, i started playing with that option. unfortunately, while i can get close, i can't quite match it. I'm using a grayscale image, reduced to 4 colors (i figured this would make differences glaringly apparent, and it does), and after turning off dithering, the primary difference is that for some reason, quantize seems to slightly tint all the colors -- meaning, the "black" (darkest color) is slightly lighter and the "white" (lightest color) is slightly darker -- than both the original and the posterized versions. i've tried every colorspace (and while most are the same, CMYKColorspace gives the LEAST tint), so that's not the problem. given what im going from and to, i don't see any difference (not even a single byte) between the tree length options.

so does anyone know how to replicate posterize's functionality exactly? otherwise, i'm going to have to call convert.exe externally instead of using magick++.

EDIT: FURTHER TOMFOOLERY GOING ON

also, maybe someone could explain what's going on, because when i checked the actual color levels i got this:

r:\>identify "color-8post.png" color-8post.png PNG 1736x1200 1736x1200+0+0 8-bit PseudoClass 170c 886KB 0.000u 0:00.000

r:\>identify "color-8quant.png" color-8quant.png PNG 1736x1200 1736x1200+0+0 8-bit PseudoClass 9c 398KB 0.000u 0:00.001

r:\>identify "gray-4post.png" gray-4post.png PNG 1647x1100 1647x1100+0+0 8-bit PseudoClass 4c 101KB 0.000u 0:00.000

r:\>identify "gray-4quant.png" gray-4quant.png PNG 1647x1100 1647x1100+0+0 8-bit PseudoClass 256c 117KB 0.000u 0:00.000

now, i get that it won't always get to the exact number you tell it to -- ie, "color-8quant.png" only went to 9c instead of the 8 i told it to. but "gray-4quant.png" didn't change the color count at all (despite actually visibly changing the image). what's weird is that for the color image, quantization was closest, but for the grayscale image, posterization was. granted, i highly doubt that anyone is going to reduce even a grayscale image to only 4 colors, but it's still odd.

EDIT:

have done another, more thorough investigation -- and having bruteforced all variables, it is indeed impossible to duplicate posterize. however, using the correct settings, you can actually match or exceed posterize, so it isn't as big of a deal. it would just be nice if you could duplicate posterize, given that it's what people use most often and are thus most familiar with.
Post Reply