convert png -color incorrect amount of output color #7310
-
ImageMagick version7.1.1-32 Operating system, version and so onmacOS 14.4.1 DescriptionWhen i use |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
-colors does not guarantee the exact number of colors. You can use -kmeans 3 to get the correct number of colors, but you may need to turn alpha off before -kmeans and then turn alpha on after -kmeans. I do not know how alpha is treated, but it may be included when doing the kmeans. Is your alpha channel 100% opaque. If so, just turn it off. |
Beta Was this translation helpful? Give feedback.
-
sadly neither of these make a difference: I am still getting 4 colors |
Beta Was this translation helpful? Give feedback.
-
IM will add the background colour to the palette, unless it is already there. The default background colour is white. You can make the bacground colour anything you want. For example, if you know your palette will contain black, use |
Beta Was this translation helpful? Give feedback.
-
When I do -colors 3 on your image, it only has 3 colors according to the histogram. The color map has 4, but one is apparently unused. That color in the color map looks like your background color. I think you may have been looking at the colormap not the histogram, which shows the colors in the image.
|
Beta Was this translation helpful? Give feedback.
-
The background colour is added to the palette when a PNG file is written. It doesn't matter what has happened before then.
EDIT: another way to stop the background colour being added to the palette is by inserting |
Beta Was this translation helpful? Give feedback.
magick input.png -kmeans 3 -strip x.png
works well, whilemagick input.png -kmeans 3 -background none x.png
leaves a black color in the palette.