Page 1 of 1

Why does this generate an inverted image?

Posted: 2019-01-14T14:13:15-07:00
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.

Re: Why does this generate an inverted image?

Posted: 2019-01-14T14:21:49-07:00
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

Re: Why does this generate an inverted image?

Posted: 2019-01-14T14:34:36-07:00
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