Can't Output Monochrome TIFFs with 6.9.3-7

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
karabagh
Posts: 3
Joined: 2016-04-11T20:16:40-07:00
Authentication code: 1151

Can't Output Monochrome TIFFs with 6.9.3-7

Post by karabagh » 2016-04-11T20:38:46-07:00

Hello,

I've been using ImageMagick to convert color images to monochrome TIFFs for years now. But since the start of April, my scripts have been producing grayscale TIFFs instead of monochrome TIFFs. I think it's because of a bug in:

ImageMagick 6.9.3-7 Q16 x86_64 2016-04-01

Here are some test commands:

Code: Select all

convert original.png -threshold 50% monochrome.png
# I correctly get a monochrome PNG.
convert original.png -threshold 50% monochrome.tiff
# I incorrectly get a grayscale TIFF.
convert original.png -threshold 50% -monochrome monochrome.tiff
# I still incorrectly get a grayscale TIFF.
convert original.png -threshold 50% -type Bilevel monochrome.tiff
# I still incorrectly get a grayscale TIFF.

User avatar
fmw42
Posts: 25761
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can't Output Monochrome TIFFs with 6.9.3-7

Post by fmw42 » 2016-04-12T09:29:29-07:00

This works fine for me on IM 6.9.3.8 Q16 Mac OSX Snow Leopard

Code: Select all

convert logo: -threshold 50% logo.tif
identify -verbose logo.tif
Image: logo.tif
Format: TIFF (Tagged Image File Format)
Mime type: image/tiff
Class: DirectClass
Geometry: 640x480+0+0
Units: PixelsPerInch
Type: Bilevel
Base type: Grayscale
Endianess: LSB
Colorspace: Gray
Depth: 8/1-bit
Channel depth:
gray: 1-bit
Channel statistics:
Pixels: 307200
Gray:
min: 0 (0)
max: 255 (1)
mean: 224.39 (0.879961)
standard deviation: 82.8768 (0.325007)
kurtosis: 3.46704
skewness: -2.33817
entropy: 0.529473
Colors: 2
Histogram:
36876: ( 0, 0, 0) #000000 gray(0)
270324: (255,255,255) #FFFFFF gray(255)
...


Can you reproduce that on your 6.9.3.7?

What is your platform?

karabagh
Posts: 3
Joined: 2016-04-11T20:16:40-07:00
Authentication code: 1151

Re: Can't Output Monochrome TIFFs with 6.9.3-7

Post by karabagh » 2016-04-12T09:59:35-07:00

Hello,
fmw42 wrote:What is your platform?
My platform is OS X El Capitan. My package manager is Homebrew, and the latest version in Homebrew is the one with the bug:

ImageMagick 6.9.3-7 Q16 x86_64 2016-04-01
fmw42 wrote:Can you reproduce that on your 6.9.3.7?
You mean reproduce the output of "identify"? Yes, I can:

Code: Select all

convert logo.png -threshold 50% logo.tif
identify -verbose logo.tif
output wrote:Image: logo.tif
Format: TIFF (Tagged Image File Format)
Mime type: image/tiff
Class: DirectClass
Geometry: 1600x900+0+0
Resolution: 28.35x28.35
Print size: 56.4374x31.746
Units: PixelsPerCentimeter
Type: Bilevel
Base type: Grayscale
Endianess: LSB
Colorspace: Gray
Depth: 8/1-bit
Channel depth:
gray: 1-bit
alpha: 1-bit
Channel statistics:
Pixels: 1440000
Gray:
min: 0 (0)
max: 255 (1)
mean: 47.8878 (0.187795)
standard deviation: 99.5899 (0.390548)
kurtosis: 0.556168
skewness: 1.5988
entropy: 0.696836
Alpha:
min: 255 (1)
max: 255 (1)
mean: 255 (1)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
entropy: 0
Colors: 2
My temporary workaround for the bug is to use the PNG format and to run the "sips" command bundled with OS X for the final TIFF output:

Code: Select all

convert logo.png -threshold 50% logo_monochrome.png
sips -s format tiff logo_monochrome.png --out logo.tif
identify -verbose logo.tif
output wrote:Image: logo.tif
Format: TIFF (Tagged Image File Format)
Mime type: image/tiff
Class: DirectClass
Geometry: 1600x900+0+0
Resolution: 72x72
Print size: 22.2222x12.5
Units: PixelsPerInch
Type: Bilevel
Base type: Bilevel
Endianess: MSB
Colorspace: Gray
Depth: 1-bit
Channel depth:
gray: 1-bit
Channel statistics:
Pixels: 1440000
Gray:
min: 0 (0)
max: 1 (1)
mean: 0.187795 (0.187795)
standard deviation: 0.390548 (0.390548)
kurtosis: 0.556168
skewness: 1.5988
entropy: 0.696836
Colors: 2
Last edited by karabagh on 2016-04-12T10:11:08-07:00, edited 1 time in total.

User avatar
fmw42
Posts: 25761
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can't Output Monochrome TIFFs with 6.9.3-7

Post by fmw42 » 2016-04-12T10:01:31-07:00

I do not understand. Your verbose information shows you have a type=bilevel and colorspace gray result. Is the image not black and white?

On my IM 6.9.3.7 Mac SnowLeopard (delegates from MacPorts) and manual install from source, it works just fine

Code: Select all

im6937 convert logo: -threshold 50% logo.tif
the result looks black and white as per the statistics from identify -verbose logo.tif

karabagh
Posts: 3
Joined: 2016-04-11T20:16:40-07:00
Authentication code: 1151

Re: Can't Output Monochrome TIFFs with 6.9.3-7

Post by karabagh » 2016-04-12T10:32:17-07:00

I am not a very smart person, but I think the bug is in not in the number of colors, but in the TIFF tagging, possibly the "Base type" tag. Yes, the TIFF image is practically black & white, but all 3rd party software I've tried identify it as grayscale. For example, in Photoshop, if I go to Image→Mode, it says Grayscale instead of Bitmap.

Unfortunately, some of the 3rd party software I use is closed-source and command-line unfriendly, so I can't "tell it" the image color mode manually. It has to recognize it by itself.

And since the 3rd party software thinks the image is Grayscale, I get file sizes 15-20 times bigger.

User avatar
fmw42
Posts: 25761
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Can't Output Monochrome TIFFs with 6.9.3-7

Post by fmw42 » 2016-04-12T13:21:19-07:00

I think the IM developers will need to check this out.

sjy
Posts: 1
Joined: 2019-02-26T16:27:14-07:00
Authentication code: 1152

Re: Can't Output Monochrome TIFFs with 6.9.3-7

Post by sjy » 2019-02-26T16:32:05-07:00

For anyone else who stumbles across this thread via a search engine, I was able to work around the issue I was having (smoothscan, which only accepts monochrome TIFFs, was saying that my input files were not 1bpp) by adding the '-depth 1' flag to my command. This reduced the quality of my image.

Post Reply