Speeding up replacing of colors in large files?

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
koemer

Speeding up replacing of colors in large files?

Post by koemer »

Hello everybody. This is my first post, so cheers everyone!

The main question is bold.

I want to switch white to black and vice versa, leaving the other colors as they are.

I tried "-fill" and "+negate" and it works just fine but my problem is, that the source file is very large (464MB), so the process lasts over 15 minutes on a modern quad core machine.

A much faster way would be, just to change the colors in the color palette, but i don't know how to do this.

How can i replace a color in the color palette, so for example what was white will turn black in the picture?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Speeding up replacing of colors in large files?

Post by fmw42 »

some approaches to changing a few colors are at: http://www.imagemagick.org/Usage/color/#replace

you may be able to use -map (or +map) to play with the color table, but I have never tried that.

Perhaps someone else can give you more advice.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Speeding up replacing of colors in large files?

Post by magick »

ImageMagick 6.4.2-2 Beta negates an image in parallel. On a quad-core processor you can expect upwards of a 300% speed-up for any algorithm that is parallelized.
koemer

Re: Speeding up replacing of colors in large files?

Post by koemer »

Is the Beta available?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Speeding up replacing of colors in large files?

Post by magick »

Try the current release, 6.4.2-1.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Speeding up replacing of colors in large files?

Post by anthony »

negating images, global color change, and replacing individual colors can all be done easily with ImageMagick. see IM examples
http://imagemagick.org/Usage/color/

however other than specific color to color replacement, or gradient color replacement there is no "palette" color replacement functions. In fact internally IM does not really make use of 'palette' colors, until the image is actually saved. It is designed more to deal with global 'millions' of colors, than a pallette of colors.

Of course you can fudge things. Saving an image say in uncompressed XPM format for example will have a text representation of the 'palette' in the header of the image, which can then be replaced very easily with a plain text editor or othe text processing methods.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply