Combine images & retain original palettes

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
Garry

Combine images & retain original palettes

Post by Garry »

Hi,

wondering, is this possible with ImageMagick? I've looked through the manual and forum, but couldn't find the appropriate feature ...

I've got two images I need to combine, but I need the palettes of both to remain intact ...

Both images are 8bit PNG with indexed color table, one with transparent areas. Both have a maximum of 128 colors each ... after the combine, the PNG should have the up to 256 colors, with the colors of one image e.g. in the lower 128, the other in the upper 128 ...

My attempts usually end up with a regular RGB picture, non indexed colors anymore (at least when I reload it into my paint program)

Which of the hundreds of options do I need to achieve my goal???

Help appreciated ...

P.S. - as this is mainly a one-time things at the moment, alternative ways of getting this done are also OK ... just want to avoid having to program something just for this ...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine images & retain original palettes

Post by fmw42 »

see http://www.imagemagick.org/script/comma ... .php#remap

and also

http://www.imagemagick.org/Usage/quantize/#map (which I believe should be using remap and not map)

I have not tried using either map or remap, myself, but I probably will try soon as I may need to do something similar.
Garry

Re: Combine images & retain original palettes

Post by Garry »

I think the map/remap function is more or less the opposite of what I want to achieve, defining a certain palette that the existing colors are remapped to ... (instead of IM making up a new palette out of whatever colors the images have). Also I believe map/remap only work on a single image at a time from what I see in the docs ...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine images & retain original palettes

Post by fmw42 »

try appending the two images together and using that as the reference map image
Garry

Re: Combine images & retain original palettes

Post by Garry »

I tried this:

convert -colors 256 -append i1.png i2.png i.png

but I end up with an RGB image instead of PNG8 with a fixed palette, and of course identical color values are then merged together ... here's the two test images:

Image Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine images & retain original palettes

Post by fmw42 »

try posting a link to your two images

or

convert image1.png image2.png +append PNG8:image3.png

convert someimage.png +dither -remap image3.png PNG8:someimage2.png
Garry

Re: Combine images & retain original palettes

Post by Garry »

fmw42 wrote:try posting a link to your two images
well, see my posting above I guess ;)

Anyway, tried this
convert image1.png image2.png +append PNG8:image3.png
on the two images. The PNG8: syntax fixed the RGB/Indexed format selection, but still the palettes are merged, yielding only one green color in the table of the merged image ...

What is supposed to be the result of the merge is this:

Image

The color table has two (identical) green values in it, changing either will make the difference in the image visible ...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine images & retain original palettes

Post by fmw42 »

convert i1.png i2.png +append PNG8:i12.png

resulting i12.png image:
Image

identify -verbose i12.png

Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 400x200+0+0
Resolution: 28.35x28.35
Print size: 14.1093x7.05467
Units: PixelsPerCentimeter
Type: PaletteMatte
Endianess: Undefined
Colorspace: RGB
Depth: 8/1-bit
Channel depth:
red: 1-bit
green: 1-bit
blue: 1-bit
alpha: 1-bit
...
Histogram:
47522: ( 0,255, 0,255) #00FF00 lime
11118: (255, 0, 0,255) #FF0000 red
21360: (255,255,255, 0) #FFFFFF00 rgba(255,255,255,0)


shows red, green (lime) and transparent white

Perhaps you are on an old version of IM and need to upgrade to the latest at v6.5.9.1
Garry

Re: Combine images & retain original palettes

Post by Garry »

True, I'm not on the latest version (6.5.1-0 2009-04-09), but the image your posted combined the greens to a single color, not maintaining different index entries ... here's the resulting table from your image: (same as I had on my attempt)

Image

Digging through the IM docs some more, I don't believe what I need done is possible w/ IM at the moment ...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combine images & retain original palettes

Post by fmw42 »

If the greens are identical, then they should be merged into one color. I would only expect what you want to work if you have two completely different sets of (128) colors. Then you should get a full 256 color palette by merging the images. Otherwise, I agree, I don't think IM can do what you want. I really don't think any system will put multiple same colors into the palette. How will it know which one to use? I don't think that is how palettes are supposed to merge and work (in my opinion, but I am not an expert on palettes). Palettes should have unique colors in them.
Garry

Re: Combine images & retain original palettes

Post by Garry »

In general, true, you want to use as few colors as possible, as it will (usually) aid compression if you use less different colors ...
Guess I need to hack something based on either GD or PNG lib ...
Post Reply