pyexttiff — Classes to read Tiff

This module aims at reading tiff with private IFDs. It uses PIL for image reading.

This module uses code from pylibtiff (https://pypi.python.org/pypi/libtiff, https://code.google.com/p/pylibtiff or https://github.com/hmeine/pylibtiff)

Classes

class epygram.extra.pyexttiff.PyexttiffError[source]

Bases: Exception

Error handling for pyexttiff.

class epygram.extra.pyexttiff.TiffFile(filename, subIFDpaths=[], method=1)[source]

Bases: object

This class allows the access to the entire tiff file (tags and images).

Opens a tiff file, reads header and IFDs. filename is the filename containing the tiff subIFDpaths is the list of tag path whose values are offset to private IFDs

a tag path is a tuple representing the path to a given tag which must represent an IFD (34665) means that tag 34665 of any given public IFD is an offset to a private IFD (32001, 521) means that tag 32001 of any given public IFD is an offset to a private IFD

and that tag 521 of any private tag referenced by a 32001 public tag is also an offset to a private IFD

method is the method used to read data:

1: f=open(…, ‘rb’) ; numpy.frombuffer(f.read(), dtype=numpy.ubyte) 2: f=open(…, ‘rb’) ; numpy.ndarray(buffer=mmap(f), dtype=numpy.ubyte) 3: same as 2 but with modifications allowed - DANGEROUS

close()[source]

Closes the file.

get_PILImage()[source]

Returns the PIL image object of the file.

get_data()[source]

Returns the ndarray containing the data.

class epygram.extra.pyexttiff.IFD[source]

Bases: list

This class represent an IFD.

Initialisation method of IFD class.

as_dict(keys='value')[source]

Returns a dictionary containing all entries. :param keys: keys to use for the dictionary, among (‘value’, ‘name’) :return: the dictionary

get_entry(tag)[source]

Returns the entry for a tag :param tag: tag to look for, as an integer or a name :return: the entry associated to the tag

get_image()[source]

Returns the image

get_tagNames()[source]

Returns the list of the tag names

get_tagValues()[source]

Returns the list of the tags as decimal values

get_value(tag, human=True)[source]

Returns the value for a tag :param tag: tag to look for, as an integer or a name :param human: if True, value is modified:

  • value[0] is returned instead of value if array contains only one element

  • conversion in string is achieved for arrays representing strings

Returns

the value associated to the tag

has_image()[source]

Returns True if one tag is an image

has_tag(tag)[source]

Returns True if an entry fits the tag given :param tag: tag to look for, as an integer or a name :return: True if tag exists

class epygram.extra.pyexttiff.IFDEntry(tag, entrytype, value=None)[source]

Bases: object

This class represent an IFD entry

tag is the tag number of the entry entrytype is the type of the entry value is the value associated to the tag

get_tagName()[source]

Returns the tag name

get_tagValue()[source]

Returns the tag

get_type()[source]

Returns the type of entry.

get_value(human=True)[source]

Returns the value if human=True, value is modified:

  • value[0] is returned instead of value if array contains only one element

  • conversion in string is achieved for arrays representing strings

is_IFD()[source]

Returns True if content is an IFD.

is_image()[source]

Returns True if content in an image

set_value(value)[source]

Sets the value of the entry.