What's the best way to split a multi-page TIFF with python? PIL doesn't seem to have support for multi-page images, and I haven't found an exact port for libtiff for python. Would PyLibTiff be the way to go? Can somebody provide a simple example of how I could parse multiple pages within a TIFF?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
You could convert it to PDF and use pyPDF to split the pages
Imagemagick worked for me real good. Wnen splitting a tiff file, basically converting from tiff to tiff, one can use a flag to force saving output files to individual tiff files. To do that, try
The %d operator is a C-Printf style %d. So, if you need a 3 field running sequence, you can say
and so on.. %d is replaced by "scene" number of the image. Now, scene numbers may or may not always start with 0 (or 1, if you want it that way). To setup a sequence the way you want, try
This would start the sequence right from the count you provided.
Magick indeed!! :)
This link to documentation has more details. This works on my windows machine too.
A project (disclosure: which I am one of the main authors, this question was one of the things that prompted me to work on it) which makes this is easy is PIMS. The core of PIMS is essentially a cleaned up and generalized version of the following class.
A class to do basic frame extraction + simple iteration.
I do use ImageMagick as external program to convert multi-page fax into viewable PNGs:
does convert first page to PNG
aaa.tiff[1] would be second page, and so on.
Or to extract all images, do:
So, to just split one multi-page TIFF into many-page TIFF you would have to execute:
and then work with temporary files: /tmp/out-12345-*.tiff
However ImageMagick can do a lot of processing, so you can probably achieve your desired result in one command.
The following splits a tif file with multiple frames into tif files where each file is one frame.