Page 1 of 2
Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T12:02:09-07:00
by locriani
Hello!
With either the latest ImageMagick 6.9.5 or ImageMagick 7.0.2, tiff multipage extraction does not function correctly:
Code: Select all
vagrant@vagrant-ubuntu-trusty-64:~$ convert --version
Version: ImageMagick 7.0.2-9 Q16 x86_64 2016-08-26 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP
Delegates (built-in): bzlib djvu fontconfig freetype gvc jbig jng jpeg lcms lqr lzma openexr png tiff wmf x xml zlib
Code: Select all
vagrant@vagrant-ubuntu-trusty-64:~$ identify 5c7cf6f8-7d4d-47a8-b2f4-fff17911a224.tif
5c7cf6f8-7d4d-47a8-b2f4-fff17911a224.tif[0] TIFF 2025x650 2025x650+0+0 8-bit CIELab 218KB 0.010u 0:00.000
5c7cf6f8-7d4d-47a8-b2f4-fff17911a224.tif[1] TIFF 2025x650 2025x650+0+0 8-bit CIELab 0.110u 0:00.120
vagrant@vagrant-ubuntu-trusty-64:~$ convert 5c7cf6f8-7d4d-47a8-b2f4-fff17911a224.tif[0] out.tiff
vagrant@vagrant-ubuntu-trusty-64:~$ identify out.tiff
out.tiff[0] TIFF 2025x650 2025x650+0+0 8-bit CIELab 378KB 0.010u 0:00.009
out.tiff[1] TIFF 2025x650 2025x650+0+0 8-bit CIELab 0.110u 0:00.120
vagrant@vagrant-ubuntu-trusty-64:~$ convert 5c7cf6f8-7d4d-47a8-b2f4-fff17911a224.tif[1] out_1.tiff
vagrant@vagrant-ubuntu-trusty-64:~$ identify out_1.tiff
out_1.tiff TIFF 2025x650 2025x650+0+0 8-bit CIELab 5.332MB 0.010u 0:00.000
Code: Select all
vagrant@vagrant-ubuntu-trusty-64:~$ convert 5c7cf6f8-7d4d-47a8-b2f4-fff17911a224.tif -scene 0 a%d.tif
vagrant@vagrant-ubuntu-trusty-64:~$ identify a0.tif
a0.tif[0] TIFF 2025x650 2025x650+0+0 8-bit CIELab 378KB 0.010u 0:00.010
a0.tif[1] TIFF 2025x650 2025x650+0+0 8-bit CIELab 0.110u 0:00.119
vagrant@vagrant-ubuntu-trusty-64:~$ identify a1.tif
a1.tif[1] TIFF 2025x650 2025x650+0+0 8-bit CIELab 285KB 0.000u 0:00.000
The expected behavior would be for index 0 to extract the first page of the tiff out. Instead, it copies the image. The expected behavior for index 1 .. whatever is for it to extract that specific page. That does work properly.
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T12:25:54-07:00
by dlemstra
Can you share your file on something like dropbox?
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T12:31:48-07:00
by snibgo
What do you think doesn't work correctly?
locriani wrote:convert 5c7cf6f8-7d4d-47a8-b2f4-fff17911a224.tif -scene 0 a%d.tif
When the input tiff contains two images, this should create one output tiff file that contains those two images. The output file will be named "a0.tif".
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T12:32:12-07:00
by locriani
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T12:33:01-07:00
by locriani
snibgo wrote:What do you think doesn't work correctly?
locriani wrote:convert 5c7cf6f8-7d4d-47a8-b2f4-fff17911a224.tif -scene 0 a%d.tif
When the input tiff contains two images, this should create one output tiff file that contains those two images. The output file will be named "a0.tif".
It is impossible to extract both images from the tiff into separate images. You can extract [0, 1] into one image, and [1] into another image, but not [0].
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T12:35:39-07:00
by snibgo
locriani wrote:It is impossible to extract both images from the tiff into separate images. You can extract [0, 1] into one image, and [1] into another image, but not [0].
Have you tried using "[0]"?
Code: Select all
convert 5c7cf6f8-7d4d-47a8-b2f4-fff17911a224.tif[0] -scene 0 a%d.tif
("-scene 0" is irrelevant, as that is the default.)
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T12:36:29-07:00
by locriani
snibgo wrote:locriani wrote:It is impossible to extract both images from the tiff into separate images. You can extract [0, 1] into one image, and [1] into another image, but not [0].
Have you tried using "[0]"?
Code: Select all
convert 5c7cf6f8-7d4d-47a8-b2f4-fff17911a224.tif[0] -scene 0 a%d.tif
("-scene 0" is irrelevant, as that is the default.)
Yes, look above. Second code block in the original post.
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T12:44:00-07:00
by snibgo
Ah, yes, I didn't see that. Can you make a simple reproducible example, eg:
Code: Select all
convert rose: wizard: a.tiff
convert a.tiff[0] out.tiff
If that works fine, then can you post the problem tiff.
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T12:45:35-07:00
by locriani
Here's an image with the issue:
https://assets.weaveup.com/uploads/uplo ... 11a224.tif
It appears to affect all the images we have had uploaded (generally created in Photoshop or NedGraphics), but not the example generated by imagemagick you just posted.
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T12:49:49-07:00
by locriani
It appears the difference is that the images I have with the issue have the following subfile tag:
While the generated image above that works has the following subfile tag:
Code: Select all
Subfile Type: multi-page document (2 = 0x2)
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T14:29:20-07:00
by fmw42
Your image from the link has only one layer and the channels are LAB as reported by my Photoshop CS.
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T21:05:46-07:00
by locriani
The subfile is there, I assure you.
As per the TIFF spec:
There may be more than one IFD in a TIFF file. Each IFD defines a subfile. One potential use of subfiles is to describe related images, such as the pages of a facsimile transmission. A Baseline TIFF reader is not required to read any IFDs beyond the first one.
Photoshop is not required to read any additional subfiles. However, the first subfile is the canonical image in this case. ImageMagick is incapable of extracting the canonical image from this TIFF representation.
It's another TIFF format extension that implements paging support, as in PDFs. ImageMagick handles that case correctly, but not the subfile case correctly.
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-26T21:25:13-07:00
by locriani
Here's another example image:
https://assets.weaveup.com/print_raster ... 2325b7.tif
Code: Select all
locriani@Schreckhorn:~ $ identify c6f95170d8a5aebb1ee7e32bf52325b7.tif
c6f95170d8a5aebb1ee7e32bf52325b7.tif[0] TIFF 1013x325 1013x325+0+0 8-bit CIELab 232KB 0.000u 0:00.000
c6f95170d8a5aebb1ee7e32bf52325b7.tif[1] TIFF 2025x650 2025x650+0+0 8-bit CIELab 0.070u 0:00.069
locriani@Schreckhorn:~ $ convert c6f95170d8a5aebb1ee7e32bf52325b7.tif[0] out_0.tiff
locriani@Schreckhorn:~ $ identify out_0.tiff
out_0.tiff[0] TIFF 1013x325 1013x325+0+0 8-bit CIELab 232KB 0.000u 0:00.000
out_0.tiff[1] TIFF 2025x650 2025x650+0+0 8-bit CIELab 0.070u 0:00.070
locriani@Schreckhorn:~ $ convert c6f95170d8a5aebb1ee7e32bf52325b7.tif[1] out_1.tiff
locriani@Schreckhorn:~ $ identify out_1.tiff
out_1.tiff TIFF 2025x650 2025x650+0+0 8-bit CIELab 5.332MB 0.000u 0:00.009
As you can see, the 2 images in this file are different sizes (and have different colors). It is possible to extract image[1], but not the image[0]. Instead, you extract image[0, 1] (basically copying the image), which is not useful.
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-27T00:09:24-07:00
by dlemstra
You have found a feature that was added last year. The first image has a resource block that contains layer information. Extracting one of the layers is possible as you have seen. But you cannot 'only' get the first image because the second image (layer) is part of the first image. You can disable this feature with the following define:
Code: Select all
D:\>identify -define tiff:ignore-layers=true c6f95170d8a5aebb1ee7e32bf52325b7.tif
c6f95170d8a5aebb1ee7e32bf52325b7.tif TIFF 1013x325 1013x325+0+0 8-bit CIELab 232KB 0.000u 0:00.000
Re: Multipage Tiff Extraction Functions Incorrectly
Posted: 2016-08-27T04:53:37-07:00
by locriani
For anyone else who encounters this issue, you can use libtiff directly to isolate the first extent: