'convert -monochrome' not working for TIFF?

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
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

'convert -monochrome' not working for TIFF?

Post by pipitas »

What's wrong with the following command? I'm especially confused because the error message mentions JPEG, which isn't involved here:

Code: Select all

convert a.tif -monochrome b.tif
   convert: BitsPerSample 1 not allowed for JPEG. `JPEGSetupEncode' @ error/tiff.c/TIFFErrors/508.
The input TIFF is:

Code: Select all

identify a.tif 
  a.tif TIFF 3500x4040 3500x4040+0+0 8-bit Grayscale DirectClass 646KB 0.000u 0:00.000
Isn't this supposed to work?

This is my ImageMagick:

Code: Select all

convert -version
  Version: ImageMagick 6.7.6-9 2012-05-12 Q16 http://www.imagemagick.org
  Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
  Features:   
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: 'convert -monochrome' not working for TIFF?

Post by fmw42 »

Either the tiff has an embedded jpg image or it is jpg compressed. Can you post a link to your image? If not, then what does

identify -verbose yourimage.tif

return
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

WORKS w. IM v6.7.9-0 [Re.: 'convert -monochrome' not working

Post by pipitas »

This version works (the very latest I could get):

Code: Select all

convert -version
  Version: ImageMagick 6.7.9-0 2012-08-17 Q16 http://www.imagemagick.org
  Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

Re: 'convert -monochrome' not working for TIFF?

Post by pipitas »

fmw42 wrote:Either the tiff has an embedded jpg image or it is jpg compressed. Can you post a link to your image? If not, then what does

identify -verbose yourimage.tif

return
A TIFF with an embedded JPEG? I never encountered such a beast!

However...

Code: Select all

identify -verbose a.tif | grep -i compress
  Compression: JPEG
The TIFF indeed had been a JPEG in its previous life, and ImageMagick was the obstetrician to help it into its new life as a TIFF.

So indeed, your assumption about the JPEG compression was correct. Is this the standard behaviour of IM (that it JPEG-compresses TIFFs when converting them from a JPEG input, and when no other compression method is given on the commandline)?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: 'convert -monochrome' not working for TIFF?

Post by fmw42 »

Where did a.jpg come from? IM? Can you post a link to your tif file? I could be wrong about an imbedded jpg, but the compression jpg may be the issue. I don't know enough about tif

Have you tried

convert a.tif -compress none -monochrome b.tif
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

Re: 'convert -monochrome' not working for TIFF?

Post by pipitas »

fmw42 wrote:Where did a.jpg come from? IM? Can you post a link to your tif file? I could be wrong about an imbedded jpg, but the compression jpg may be the issue. I don't know enough about tif

Have you tried

convert a.tif -compress none -monochrome b.tif
;-) Yes -- after I had verified your golden hint about the JPEG compression, I added '-compress zip' and that worked (with the 'convert' version that perviously failed).

Thanks for all your tireless support. I appreciate it very much!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: 'convert -monochrome' not working for TIFF?

Post by anthony »

pipitas wrote:So indeed, your assumption about the JPEG compression was correct. Is this the standard behaviour of IM (that it JPEG-compresses TIFFs when converting them from a JPEG input, and when no other compression method is given on the commandline)?
When converting to TIFF you should reset the image compression properity, as TIFF can save using JPEG compression.

See IM Examples, TIFF...
http://www.imagemagick.org/Usage/formats/#tiff
JPEG to TIFF conversion...

convert image.jpg image.tif

This will either save the image inside the TIFF file using JPEG compression
(whcih was inherited from the JPG input. Or it will error such as...

Error: "JPEG compression support not configured"

This is caused by the TIFF library not including JPEG compression support.

Either way THIS IS BAD.

You can get around this problem by changing the setting to use a different
compression algorithm:

convert image.jpg -compress zip image.tif
convert image.jpg -compress lzw image.tif
convert image.jpg +compress image.tif
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply