How to produce plain black cmyk

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
rouckas
Posts: 3
Joined: 2013-01-24T02:14:14-07:00
Authentication code: 6789

How to produce plain black cmyk

Post by rouckas »

Dear all,
Short question: how to produce a plain black CMYK grayscale image in ImageMagick?

Long story: I have a grayscale image and I want to convert it to a plain black CMYK file i.e. only black channel is nonzero. However, using

Code: Select all

convert 1219-1054.jpg -colorspace CMYK 0103_cmyk_matrix.tif
produces image, where the gray is composed of CMY, e.g. cmyk(251,251,251,0)...
So I tried to copy the Y channel to K using -color-matrix:

Code: Select all

convert 1219-1054.jpg -colorspace CMYK -color-matrix \
     " 0.0 0.0 0.0 0.0, 0.0, 0. \
       0.0 0.0 0.0 0.0, 0.0, 0. \
       0.0 0.0 0.0 0.0, 0.0, 0. \
       0.0 0.0 1.0 0.0, 0.0,  0.0 \
       0.0 0.0 0.0 0.0, 1.0,  0.0 \
       0.0 0.0 0.0 0.0, 0.0,  1.0" -colorspace CMYK 0103_cmyk_matrix.tif
But imagemagick seems to completely ignore the -color-matrix in this case
However, converting the image first to CMYK tiff and the using then color matrix, I can manipulate CMY channels and copy for example the Cyan to Yellow channel like this

Code: Select all

convert 1219-1054.jpg -colorspace CMYK 0103-cmyk-IM.tif
convert 0103-cmyk-IM.tif -colorspace CMYK -color-matrix \
     " 0.0 0.0 0.0 0.0, 0.0, 0. \
       0.0 0.0 0.0 0.0, 0.0, 0. \
       1.0 0.0 0.0 0.0, 0.0, 0. \
       0.0 0.0 0.0 0.0, 0.0,  0.0 \
       0.0 0.0 0.0 0.0, 1.0,  0.0 \
       0.0 0.0 0.0 0.0, 0.0,  1.0" -colorspace CMYK 0103_cmyk_matrix.tif
(the result is inverted, but it can be fixed easily) Unfortunately, this doesn't work for black. Using

Code: Select all

convert 1219-1054.jpg -colorspace CMYK 0103-cmyk-IM.tif
convert 0103-cmyk-IM.tif -colorspace CMYK -color-matrix \
     " 0.0 0.0 0.0 0.0, 0.0, 0. \
       0.0 0.0 0.0 0.0, 0.0, 0. \
       0.0 0.0 0.0 0.0, 0.0, 0. \
       1.0 0.0 0.0 0.0, 0.0,  0.0 \
       0.0 0.0 0.0 0.0, 1.0,  0.0 \
       0.0 0.0 0.0 0.0, 0.0,  1.0" -colorspace CMYK 0103_cmyk_matrix.tif
Produces just plain white image.
Rather surprisingly, the only command to produce plain black tiff was

Code: Select all

convert 1219-1054.jpg -colorspace CMYK 0103-cmyk-IM.jpg
but the resulting cmyk jpg is blurred and unusable probably due to subsampling problems.
So, is there some reliable way to produce a plain black cmyk file with imagemagick?

A sample file can be downloaded from
https://www.dropbox.com/s/ys38p8sa74799fq/1219-1054.jpg

Thanks in advance for any help

Stepan
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to produce plain black cmyk

Post by snibgo »

Your sample is monochrome. When I convert it to CMYK, I get what I would expect: zero values in the CMY channels, with loads of values in K.

Code: Select all

"%IMG%convert" 1219-1054.jpg -colorspace cmyk 1219_c.tiff
"%IMG%identify" -verbose 1219_c.tiff
  Channel statistics:
    Cyan:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Magenta:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Yellow:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
    Black:
      min: 0 (0)
      max: 255 (1)
      mean: 171.338 (0.671915)
      standard deviation: 66.152 (0.25942)
      kurtosis: -1.50334
      skewness: -0.214819
I can get a file of just the K channel:

Code: Select all

"%IMG%convert" 1219_c.tiff channel K -separate 1219_s.tiff
When I view this file, it looks negative, of course, because the value represents the amount of black ink that should be placed.

This is on IM 6.7.9 in Windows 7. If your results are different, what are you on?
snibgo's IM pages: im.snibgo.com
rouckas
Posts: 3
Joined: 2013-01-24T02:14:14-07:00
Authentication code: 6789

Re: How to produce plain black cmyk

Post by rouckas »

My results are different indeed:

Code: Select all

$ convert 1219-1054.jpg -colorspace cmyk 1219_c.tiff
$ identify -verbose 1219_c.tiff
  Channel statistics:
    Cyan:
      min: 0 (0)
      max: 255 (1)
      mean: 135.364 (0.53084)
      standard deviation: 69.0691 (0.270859)
      kurtosis: -1.25183
      skewness: -0.338258
    Magenta:
      min: 0 (0)
      max: 255 (1)
      mean: 135.364 (0.53084)
      standard deviation: 69.0691 (0.270859)
      kurtosis: -1.25183
      skewness: -0.338258
    Yellow:
      min: 0 (0)
      max: 255 (1)
      mean: 135.364 (0.53084)
      standard deviation: 69.0691 (0.270859)
      kurtosis: -1.25183
      skewness: -0.338258
    Black:
      min: 0 (0)
      max: 0 (0)
      mean: 0 (0)
      standard deviation: 0 (0)
      kurtosis: 0
      skewness: 0
I am using

Code: Select all

$ convert -version 
Version: ImageMagick 6.6.9-7 2012-08-17 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP   
on Ubuntu 12.04.

Btw, I understand why the single separated K channel looks inverted, but I thought that when this channel is inserted into a CMYK file, it should be interpreted and displayed correctly. But this is not a problem for me.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to produce plain black cmyk

Post by snibgo »

I have a vague memory that IM, a long time ago, confused CMYK with CMY. It isn't populating your K channel, and it should. I suggest you upgrade.
snibgo's IM pages: im.snibgo.com
rouckas
Posts: 3
Joined: 2013-01-24T02:14:14-07:00
Authentication code: 6789

Re: How to produce plain black cmyk

Post by rouckas »

snibgo wrote:I have a vague memory that IM, a long time ago, confused CMYK with CMY. It isn't populating your K channel, and it should. I suggest you upgrade.
This could be the problem. I will try the upgrade.

Thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to produce plain black cmyk

Post by snibgo »

Incidentally, I can directly get the K-channel from your image with:

Code: Select all

convert 1219-1054.jpg -colorspace RGB -negate 1219_k.tiff
This is because (http://www.imagemagick.org/script/comma ... colorspace):
K = min (quantum-R, quantum-G, quantum-B)
where R,G,B are the values in the linear RGB colorspace, and your image has R=G=B. Your jpg is in non-linear sRGB colorspace.

However, your IM version was in the days when IM was confused about RGB and sRGB, so the command might need tweaking for 6.6.9.
snibgo's IM pages: im.snibgo.com
Post Reply