How do I invert the colors of an image using the ImageMagick convert tool, so that black becomes white and white becomes black?
In other words, I want to turn this:
into this:
How do I invert the colors of an image using the ImageMagick convert tool, so that black becomes white and white becomes black?
In other words, I want to turn this:
into this:
Use the -negate option:
convert input.png -channel RGB -negate output.png
The -negate option replaces each pixel with its complementary color. The -channel RGB option is necessary as of ImageMagick 7 to prevent the alpha channel (if present) from being negated. (Thanks to goto-bus-stop for this insight.)
See also the documentation for -negate.
ImageMagick 6.x can invert color intensities with -negate option only. ref) https://www.imagemagick.org/script/command-line-options.php#negate
convert input.png -negate output.png
ImageMagick 7.x requires the -channel option with -negate. ref) https://imagemagick.org/script/porting.php#cli Changed Options
convert input.png -channel RGB -negate output.png
This is because the default active channels contain transparency(opaque/alpha) in ImageMagick 7.x
ImageMagick6: DefaultChannels = ((AllChannels | SyncChannels) &~ OpacityChannel)
ImageMagick7: DefaultChannels = AllChannels
Most algorithms update the red, green, blue, black (for CMYK), and alpha channels. Usability of -negate seems to be sacrificed for overall consistency.
More detail for you. http://blog.awm.jp/2018/11/18/im7negate/
convert input.png -negate output.png works fine for me on ImageMagick 7.0.8 (ArchLinux)
– msrd0
Nov 23 '18 at 16:38
identify -verbose input.png | grep Type It ouput TrueColor or TrueColorAlpha.
– yoya
Nov 28 '18 at 05:48
-channel RGB to my answer.
– Jo Liss
Nov 29 '18 at 18:06
For powershell (Windows OS) need use:
magick input.png -channel RGB -negate output.png
Note. I using it in imagemagick 7.1.1-18
-channel RGB -negateto avoid that. – goto-bus-stop Oct 07 '18 at 13:48-channel RGBisn't necessary. It only inverts the alpha channel if I pass-channel RGBA -negate. I'm not sure what explains the different behavior. – Jo Liss Oct 18 '18 at 15:57identifysees the input as "8-bit sRGB", the output is "8-bit Grayscale Gray". – user74094 Nov 26 '18 at 00:25