Console for converting images to indexed color

I have image.png in truecolor, palette.png (N colors, where N> 256) or a text file where the RGB color palette is displayed. How to get an image with this palette?

If I use imagemagick:

convert image.png -remap palette.png remap_image.png 

Does not work.

 convert image.png -map palette.png remap_image.png 

It gives a very poor quality. The image is very noisy. The file size is bigger than ever.

The best quality gives GIMP:

 onvert image to indexed color > use custom palette 

But GIMP is gui. I need to convert many images to the console without starting gimp and X.org

+5
source share
3 answers

Using a common palette on multiple images requires a carefully thought-out palette. If you are not particularly careful when using the same image palette in many images, the result will be unsatisfactory.

This, however, is not difficult. If you have access to a GIMP (or other tool) that supports truecolor graphics, you can create a large image and place smaller and smaller images in it, then quantize the image to N colors, and then use this palette as a source.

you should be able to accurately simulate the GIMP behavior in the console using ImageMagick

Once you get a truecolor image with all the colors you want to quantize,

 # Create an 8-bit png from our source, with a 235-color palette as an example. convert truecolor_source.png -colors 235 palette.png # Create an 8-bit png from an arbitrary image and use the palette in palette.png convert sample.png -map palette.png output.png 

There are a number of options for flowers down, for example dithering . See the ImageMagickv6 sample page for a great overview with sample images and code.

Although I still do not quite understand what you want to do, your last comment ("Yes, from RGB to the palette will be set independently. You need to set the correct number of colors"), this is like everything you want to do sets a strict limit on the amount colors of a bunch of images, but they don’t need to use the same palette.

In this case, the solution is very simple:

 convert sample.png -colors 135 output.png 

Try playing with the quantization parameters if the result does not match your satisfaction.

If the output image is too large to your liking, you can experiment with the -quality option.

If this is still unsatisfactory, try to explain your purpose in more detail. Good luck

+6
source

cat photo.png | pngnq -s 1> photoindexed.png

+1
source

I strive to get good results with the functions "-remap" (single imge) or "+ remap" (multiple images) combined with "-colors". Read about these features here . Note that β€œusingβ€œ -remap ”you provide IM the final set of colors that you want to use for the image, whether you plan to smooth these colors or just replace them with the nearest neighbors.”, Which means just remapping / replacing may not look good enough because the colors from the input image are simply replaced by the colors from the palette image. Some form of blurring will be necessary to distribute pixel color conversion errors across the entire output image, because not all colors in the palette match the colors of the input image.
I would advise you to use the "-colors N" option for this. This will reduce the number of colors in the output image to 64. By default, ImageMagick implicitly uses "-dither Riemersma" when you specify "-colors N". Other options for smoothing options are also available.

0
source

All Articles