Reduce number of colors without creating new color

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
gamax92
Posts: 3
Joined: 2012-12-08T13:11:23-07:00
Authentication code: 6789

Reduce number of colors without creating new color

Post by gamax92 »

I noticed that -colors seems to create new colors that are not in the original image.
Is there a way to make it use only the colors that were there, and if not can someone recommend me a tool that can?

Would doing a remap afterwards with the original image still give good results?

EDIT: Doing a remap afterwards gives more than 2 colors, and turning off dither produces horrible results
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Reduce number of colors without creating new color

Post by snibgo »

I am surprised that "Doing a remap afterwards gives more than 2 colors". Can you supply sample command and image?

You could:
(1) Find the N most common colours in the image. Make an image containing just those colours.
(2) Remap with the image found from (1).

IM doesn't (yet) contain tools to convert histogram data into images, so step (1) involves a script.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Reduce number of colors without creating new color

Post by fmw42 »

I do not understand. -remap should maintain the colors in the colormap image. Cay you provide an example our your input and output and exact command line. Images can be uploaded to some free hosting site such as dropbox.com (public folder) and you can put the URL her.

Edit: Sorry snibgo, we were posting at the same time.
gamax92
Posts: 3
Joined: 2012-12-08T13:11:23-07:00
Authentication code: 6789

Re: Reduce number of colors without creating new color

Post by gamax92 »

Image - adladl.png
Image - new.png Has new color
Image - new2.png Has three colors
Image - new3.png Is not dithered

Code: Select all

convert adladl.png -colors 2 new.png
convert adladl.png -colors 2 -remap adladl.png new2.png
convert adladl.png -colors 2 +dither -remap adladl.png
Post Reply