Why does this generate an inverted image?

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
tml
Posts: 2
Joined: 2019-01-14T13:16:23-07:00
Authentication code: 1152

Why does this generate an inverted image?

Post by tml »

For this example, I am just using the built-in "rose:" data, but I see equivalent problems when using actual images. I am trying to separate the CMYK channels, do some processing on them, and then combine them back into a TIFF. When I run the below, the resulting TIFF images have all their colors inverted:

Code: Select all

#!/bin/bash

convert -geometry 1000x1000 rose: -colorspace cmyk -channel C -separate rose_c.tiff
convert -geometry 1000x1000 rose: -colorspace cmyk -channel M -separate rose_m.tiff
convert -geometry 1000x1000 rose: -colorspace cmyk -channel Y -separate rose_y.tiff
convert -geometry 1000x1000 rose: -colorspace cmyk -channel K -separate rose_k.tiff
convert -channel C rose_c.tiff -channel M rose_m.tiff -channel Y rose_y.tiff -channel K rose_k.tiff -combine rose.tiff

If I change

Code: Select all

rose.tiff
in that last line to

Code: Select all

TIFF:- | convert - -negate rose.tiff
it generates a correct looking image. I am just looking to understand WHY this is the case, so I can figure out when I need to negate and when I do not, as I will eventually be running my imagemagick process on around 16MM images (consuming roughly 1.5PB of disk), and I don't want to run it twice.
tml
Posts: 2
Joined: 2019-01-14T13:16:23-07:00
Authentication code: 1152

Re: Why does this generate an inverted image?

Post by tml »

Forgot to provide version information:

Code: Select all

Version: ImageMagick 7.0.8-23 Q16 x86_64 2019-01-07 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib cairo fftw fontconfig freetype jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff webp x xml zlib
OS is MacOS Mojave; ImageMagick is installed via homebrew
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Why does this generate an inverted image?

Post by snibgo »

Your last line doesn't tell IM the input is CMYK, so IM assumes the channels are RGB. Try this instead:

Code: Select all

convert rose_c.tiff rose_m.tiff rose_y.tiff rose_k.tiff -set colorspace CMYK -combine rose.tiff 
snibgo's IM pages: im.snibgo.com
Post Reply