BW-TIF to BW-JP2 conversion

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
Erik
Posts: 12
Joined: 2016-04-30T00:18:15-07:00
Authentication code: 1151

BW-TIF to BW-JP2 conversion

Post by Erik »

Version: ImageMagick 6.9.4-1 Q16 x86_64 2016-05-17 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib freetype jng jp2 jpeg lcms ltdl lzma png tiff webp wmf xml zlib
I am converting Black-White-TIF images to Black-White-JP2 images.

The JP2 files are part of a PDF which I upload to Amazon/Createspace. But the JP2 images always appear to be completely black in the Createspace preview. Locally, these invalid JP2 files show a gray background in GIMP ... but not in the PDF-viewer Preview.

I get around this problem by converting TIF to JPG to JP2. In this case, the valid JP2 files are way too large.

I compared the invalid JP2 images with the valid JP2 images using "identify -verbose", trying to spot the problem. I tried everything from changing the colorspace, normalizing, thresholding, changing the alpha colors and removing the alpha channel.

Could you help me out?


Input
https://drive.google.com/file/d/0BxivpP ... sp=sharing


Result Invalid

Code: Select all

convert input.tif resut_not_ok.jp2
https://drive.google.com/file/d/0BxivpP ... sp=sharing


Result Valid

Code: Select all

convert input.tif tmp.jpg
convert tmp.jpg -monochrome result_ok.jp2
JPG: TMP
https://drive.google.com/file/d/0BxivpP ... sp=sharing

JP2
https://drive.google.com/file/d/0BxivpP ... sp=sharing
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: BW-TIF to BW-JP2 conversion

Post by fmw42 »

From identify -verbose, the difference seems to be that the OK colorspace=sRGB, type=bilevel and the NOT OK one is colorspace=Grayscale, type=bilevel

Also the input has
Depth: 1-bit
Gray:
min: 0 (0)
max: 1 (1)

The OK one has
Depth: 8/1-bit
Gray:
min: 0 (0)
max: 255 (1)

Which is fine for 8/1-bit.

The NOT OK one has
Depth: 2/1-bit
Gray:
min: 0 (0)
max: 3 (1)


So it looks like you need an 8/1 bit sRGB bilevel result.

So try this:

Code: Select all

convert input.tif -set colorspace sRGB -depth 8 test.jp2
Which has
Type: Bilevel
Colorspace: sRGB
Depth: 8/1-bit
Gray:
min: 0 (0)
max: 255 (1)
Erik
Posts: 12
Joined: 2016-04-30T00:18:15-07:00
Authentication code: 1151

Re: BW-TIF to BW-JP2 conversion

Post by Erik »

Thank you, that set me on the right track.

As it turns out, using "-depth 8" only is sufficient, as this allows the gray-max-value to reach 255.

I wasn't aware that the "depth" is related to the min/max values.

Code: Select all

Gray:
      min: 0 (0)
      max: 255 (1)
      mean: 228.765 (0.897117)
      standard deviation: 77.4704 (0.303806)
      kurtosis: 4.83449
      skewness: -2.61429
      entropy: 0.478067
Post Reply