1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/usr/bin/env python
# -*- python-mode -*-
# Author: Pearu Peterson
# Created: May 2010
# flake8: noqa
import os # noqa: F401
def runner(parser, options, args):
if not hasattr(parser, 'runner'):
options.output_path = None
assert not args, repr(args)
if options.input_path is None:
parser.error('Expected --input-path but got nothing')
input_path = options.input_path
import libtiff
tiff = libtiff.tiff.TIFFfile(input_path)
if options.memory_usage:
print('Memory usage:')
print('-------------')
tiff.check_memory_usage()
human = options.get(human=False)
print(human)
ifd0 = tiff.IFD[0]
if options.ifd:
for i, ifd in enumerate(tiff.IFD):
print('IFD%s:' % (i))
print('------')
if human:
print(ifd.human())
else:
print(ifd)
else:
if human:
print(ifd0.human())
else:
print(ifd0)
if len(tiff.IFD) > 1:
print('Use --ifd to see the rest of %s IFD entries'
% (len(tiff.IFD)-1))
print('data is contiguous:', tiff.is_contiguous())
if tiff.check_memory_usage(verbose=False):
print('memory usage is ok')
else:
print('memory usage has inconsistencies:')
print('-----')
tiff.check_memory_usage(verbose=True)
print('-----')
for subfile_type in tiff.get_subfile_types():
ifd0 = tiff.get_first_ifd(subfile_type=subfile_type)
for sample_index, n in enumerate(ifd0.get_sample_names()):
print('Sample %s in subfile %s:' % (sample_index, subfile_type))
arr = tiff.get_tiff_array(sample_index=sample_index,
subfile_type=subfile_type)
print(' shape=', arr.shape)
print(' dtype=', arr.dtype)
print(' pixel_sizes=', arr.get_pixel_sizes())
def main():
from optparse import OptionParser
from libtiff.script_options import set_info_options
from libtiff.utils import Options
parser = OptionParser()
set_info_options(parser)
if hasattr(parser, 'runner'):
parser.runner = runner
options, args = parser.parse_args()
runner(parser, Options(options), args)
return
if __name__ == '__main__':
main()
|