Problem with resizing 1-bit TIFF image (b/w) to PNG image

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
RemEcho
Posts: 3
Joined: 2014-10-30T11:22:16-07:00
Authentication code: 6789

Problem with resizing 1-bit TIFF image (b/w) to PNG image

Post by RemEcho »

Hi there magickians.

So basically what I want to do is resizing an 1-bit TIFF image with a geometry like 300x300 to create a PNG thumbnail. The problem that I'm facing now, is with IM-6.8.9-9 I can only get 8-bit sRGB 2c PNG images which kinda lost lots details in the image. I also tried using IM-6.6.8-1(not an official release version IM ftp?) at my work place and it's doing the conversion to sRGB 256c, the outcome image looks perfect.

I also tried separating the resizing and format conversion commands and the results are looking different than doing the commands in one line. Here I will give all the commands I played around with, but firstly the 1-bit TIFF I started with (I'll paste the identify info after each image):

https://drive.google.com/file/d/0B7qD3O ... sp=sharing
INFO: test_tiff TIFF 1500x2200 1500x2200+0+0 1-bit Bilevel Gray 172KB 0.000u 0:00.000

and I did:

Code: Select all

convert test_tiff -resize 300x300 thumb_test_tiff.png
https://drive.google.com/file/d/0B7qD3O ... sp=sharing
INFO: thumb_test_tiff.png PNG 205x300 205x300+0+0 8-bit sRGB 2c 1.75KB 0.000u 0:00.000

if I do it in two steps:

Code: Select all

convert test_tiff -resize 300x300 separate_test_tiff
https://drive.google.com/file/d/0B7qD3O ... sp=sharing
INFO: separate_test_tiff TIFF 205x300 205x300+0+0 1-bit Bilevel Gray 7.81KB 0.000u 0:00.000

Code: Select all

convert separate_test_tiff separate_test_tiff.png
https://drive.google.com/file/d/0B7qD3O ... sp=sharing
INFO: separate_test_tiff.png PNG 205x300 205x300+0+0 8-bit sRGB 2c 4.89KB 0.000u 0:00.000

As you can see, the converted PNG images are having pretty small sizes.

thumb_test_tiff.png is like over-exposured and separate_test_tiff.png seems looking good but not good as doing resizing on PNG/JPEG images.
Here is a link to the one I resized from a PNG (thumb_resized_from_png.png):
https://drive.google.com/file/d/0B7qD3O ... sp=sharing
And the same commands I tried on jpeg (greyscale/RGB) images are all working fine.

===============================================================================

However, at my work place I have tried the same thing (notice it's IM 6.6.8-1)

Code: Select all

convert test_tiff_old -resize 300x300 thumb_test_tiff_old.png
https://drive.google.com/file/d/0B7qD3O ... sp=sharing
INFO: thumb_test_tiff_old.png PNG 217x300 217x300+0+0 8-bit PseudoClass 256c 57.3KB 0.000u 0:00.000

If I separate the process commands I got poor PNG (2c and few KB on size) again as before.

===============================================================================

So, I'm wondering if it's expected to get poor PNG images now or I'm missing some cofigurations, or libs on my side. The flow is kinda understandable that scaling an image down might lose details (like texts became little dots), I can see this when I separate the resizing and format conversion, but doing the two together is kinda giving me an over-exposured PNG. I also tried an official version 6.6.8-10 that I downloaded from the IM ftp site and it's doing the same thing with 6.8.9-9.

For this to work correctly/ideally under IM 6.8.9-9, I need to put PNG8: (or PNG24:, PNG32:...) before the destination image so that the colors/pixels are kinda made up completely.

===============================================================================

Any ideas? Any way I could achieve the "pefect" conversion without explicitly using PNG8:(and others)?

Any help/comments would be appreciated :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem with resizing 1-bit TIFF image (b/w) to PNG imag

Post by snibgo »

Try it with "+depth", eg:

Code: Select all

convert test_tiff +depth -resize 300x300 out.png
snibgo's IM pages: im.snibgo.com
RemEcho
Posts: 3
Joined: 2014-10-30T11:22:16-07:00
Authentication code: 6789

Re: Problem with resizing 1-bit TIFF image (b/w) to PNG imag

Post by RemEcho »

Thank you snibgo, that did the trick. I'm more concerning on why this is not required for an old version, but seems like the IM team made a decision to not include that in the conversion? Still confused like why separate the commands and doing one line are processing images differently, and if I can simply apply a lib and add some parameter to ./configure to have +depth auto added to the TIFF->PNG transform.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem with resizing 1-bit TIFF image (b/w) to PNG imag

Post by snibgo »

v6.6.8 is about 200 versions and many years old. I don't know if the need for "+depth" ever changed deliberately. It might have been a side-effect of something else.

With current IM, if the input has bit depth N, the output will usually be the same. In your case, input depth was 2, so the output was also 2.

EDIT: I should add, keeping the same bit depth is often correct. If you were merely cropping the image, you wouldn't want the depth to automatically expand from 2 to 16 (or 32 or 64), massively increasing the file size.

It would be useful if IM could automatically determine the minimum depth when it wrote files.
snibgo's IM pages: im.snibgo.com
RemEcho
Posts: 3
Joined: 2014-10-30T11:22:16-07:00
Authentication code: 6789

Re: Problem with resizing 1-bit TIFF image (b/w) to PNG imag

Post by RemEcho »

Thanks for the reply snibgo.

I agree with you on the massive size increase when depth got expanded. As I have other formats (e.g. JPEG) of images scaled and converted to PNG thumbnail in 8-bit depth, using +depth will give me a PNG that's 2X of the size (yes 16-bit).

I'm guessing the 6.6.8 version I was trying with is somehow doing a PNG8 hard convert, since I still see similar size of the outcome PNG as not using +depth, but if I'm replying on an old version, or even say relying on some kinda bug not being fixed, I should probably go with the newer, more robust version and do the corresponding change that I need to do...

Another thought is to stop using 1-bit TIFF as sources images from my side, but I'll go with the +depth option for now. Many thanks snibgo!
Post Reply