Posterize acting different in PerlMagick vs command line

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
scubanarc
Posts: 2
Joined: 2018-07-07T08:12:08-07:00
Authentication code: 1152

Posterize acting different in PerlMagick vs command line

Post by scubanarc »

Linux Version: ImageMagick 6.7.8-9 2016-06-16 Q16 on CentOS 7
Windows Version: ImageMagick 7.0.8-5 Q16 x64 on Windows 10

I'm using PerlMagick and I need to reduce images down to the following basic colors:

0x000000 (black)
0x0000FF (blue)
0x00FF00 (green)
0x00FFFF (cyan, or html aqua)
0xFF0000 (red)
0xFF00FF (magenta, or html fuchsia)
0xFFFF00 (yellow)
0xFFFFFF (white)

I've been playing with posterize but I can't quite figure out how to make sure that those are the only colors in the output.

It works great in Win10 with the following command:

Code: Select all

magick input.png -posterize 2 output.png
Yet when I run the following in PerlMagick on CentOS I only get the desired result in MOST files:

Code: Select all

$image->Read("input.png");
$image->Posterize(levels => 2, dither => 'false');  # dither doesn't make a difference either way
$image->write('output.png');
The result image has colors that are definitely not in that pallet.

Code: Select all

    160392: (  0,  0,  0,255) #000000FF black
         8: (  0,  0,  0,213) #000000D5 srgba(0,0,0,0.835294)
         7: (  0,  0,  0,230) #000000E6 srgba(0,0,0,0.901961)
         6: (  0,  0,  0,250) #000000FA srgba(0,0,0,0.980392)
         3: (  0,  0,  0,244) #000000F4 srgba(0,0,0,0.956863)
      1013: (  0,255,255,255) #00FFFFFF cyan
       570: (125, 25,130,255) #7D1982FF srgba(125,25,130,1)
     88001: (255,255,255,255) #FFFFFFFF white
I'm starting to think it's down to PerlMagick's implementation, or the differences between Windows and Linux versions. Any suggestions?
scubanarc
Posts: 2
Joined: 2018-07-07T08:12:08-07:00
Authentication code: 1152

Re: Posterize acting different in PerlMagick vs command line

Post by scubanarc »

Update: The command line version of ImageMagick 6.7.8-9 2016-06-16 Q16 CentOs 7 and ImageMagick 7.0.8-5 Q16 x64 Win10 generate the same output, so this is not a version issue, it's a PerlMagick issue.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Posterize acting different in PerlMagick vs command line

Post by snibgo »

Perhaps it was a bug in PerlMagick v6.7.8-9. That is a very old version, and I suggest you upgrade.
snibgo's IM pages: im.snibgo.com
Post Reply