sparkocr.utils.svs.tiffparser#
Read TIFF(r) file (meta)data.
Data can be read from TIFF, BigTIFF, OME-TIFF, STK, LSM, SGI, NIHImage, ImageJ, MicroManager, FluoView, ScanImage, SEQ, GEL, SVS, SCN, SIS, ZIF, QPTIFF, NDPI, and GeoTIFF files.
- Author:
- Organization:
Laboratory for Fluorescence Dynamics, University of California, Irvine
- License:
BSD 3-Clause
- Version:
2020.2.16
References
TIFF 6.0 Specification and Supplements. Adobe Systems Incorporated. https://www.adobe.io/open/standards/TIFF.html
TIFF File Format FAQ. https://www.awaresystems.be/imaging/tiff/faq.html
MetaMorph Stack (STK) Image File Format. http://mdc.custhelp.com/app/answers/detail/a_id/18862
Image File Format Description LSM 5/7 Release 6.0 (ZEN 2010). Carl Zeiss MicroImaging GmbH. BioSciences. May 10, 2011
The OME-TIFF format. https://docs.openmicroscopy.org/ome-model/5.6.4/ome-tiff/
UltraQuant(r) Version 6.0 for Windows Start-Up Guide. http://www.ultralum.com/images%20ultralum/pdf/UQStart%20Up%20Guide.pdf
Micro-Manager File Formats. https://micro-manager.org/wiki/Micro-Manager_File_Formats
Tags for TIFF and Related Specifications. Digital Preservation. https://www.loc.gov/preservation/digital/formats/content/tiff_tags.shtml
ScanImage BigTiff Specification - ScanImage 2016. http://scanimage.vidriotechnologies.com/display/SI2016/ ScanImage+BigTiff+Specification
CIPA DC-008-2016: Exchangeable image file format for digital still cameras: Exif Version 2.31. http://www.cipa.jp/std/documents/e/DC-008-Translation-2016-E.pdf
ZIF, the Zoomable Image File format. http://zif.photo/
GeoTIFF File Format https://gdal.org/drivers/raster/gtiff.html
Module Contents#
Classes#
Binary file handle. |
|
Series of files containing array data of compatible shape and data type. |
|
Class whose attributes are computed on first access from its methods. |
|
Null context manager. |
|
Keep files open. |
|
Namespace for module constants. |
|
Read image and metadata from TIFF file. |
|
Lightweight TIFF image file directory (IFD). |
|
TIFF image file directory (IFD). |
|
Series of TIFF pages with compatible shape and data type. |
|
Sequence of TIFF image file directories (IFD chain). |
|
TIFF tag structure. |
|
Multidict like interface to TiffTag instances in TiffPage. |
|
Attribute whose value is computed on first access. |
Functions#
|
|
|
Return string as bool if possible, else raise TypeError. |
|
|
|
Return argument as one of types if possible. |
|
Return if byteorder matches the system's byteorder. |
|
Return unicode string from encoded bytes. |
|
Return bytes from unicode string, else pass through. |
|
Return string with compressed whitespace. |
|
|
|
Return enum member from its name or value. |
|
Return short string representation of Enum instance. |
|
Return datetime object from timestamp in Excel serial format. |
|
Return metatata from FluoView image description as dict. |
|
Return file size as string from byte size. |
|
|
|
Return hexdump representation of bytes. |
|
Single argument identity function. |
|
Return ImageJ image description from data shape. |
|
Return metatata from ImageJ image description as dict. |
|
Return IJMetadata tag value as dict. |
|
Return IJMetadata and IJMetadataByteCounts tags from metadata dict. |
|
Return shape normalized to 6D ImageJ hyperstack TZCYXS. |
|
|
|
Return if all characters in string are printable. |
|
Return JSON image description from data shape and other metadata. |
|
Return metatata from JSON formated image description as dict. |
|
Return datetime from days since 1/1/4713 BC and ms since midnight. |
|
Log message with level WARNING. |
|
|
|
|
|
Return metatata from MetaSeries image description as dict. |
|
Return human sorted list of strings. |
|
Null function. |
|
Return OlympusSIS metadata from INI string. |
|
|
|
Return dict with keys from keys|keyvals and values from kwargs|keyvals. |
|
|
|
Return pretty formatted XML. |
|
Return metatata from Pilatus image description as dict. |
|
Return product of sequence of numbers. |
|
Read tag data from file and return as bytes. |
|
Read ColorMap data from file and return as numpy array. |
|
Read CZ_LSMINFO tag from file and return as dict. |
|
Read Zeiss SEM tag and return as dict. |
|
Read EXIF tags from file and return as dict. |
|
Read FEI SFEG/HELIOS headers and return as dict. |
|
Read GPS tags from file and return as dict. |
|
Read Interoperability tags from file and return as dict. |
|
Read JSON tag data from file and return as object. |
Read LSM ChannelColors structure from file and return as dict. |
|
Read LSM events from file and return as list of (time, type, text). |
|
Read LSM sequence of float pairs from file and return as list. |
|
Read LSM positions from file and return as list. |
|
Read LSM ScanInfo structure from file and return as dict. |
|
Read LSM time stamps from file and return as list. |
|
Read MetaSeries non-TIFF hint catalog from file. |
|
Read MicroManager non-TIFF settings from open file and return as dict. |
|
|
Read FluoView mm_header tag from file and return as dict. |
|
Read FluoView mm_stamp tag from file and return as numpy.ndarray. |
|
Read NIH_IMAGE_HEADER tag from file and return as dict. |
|
Read tag data from file and return as numpy array. |
Read ScanImage BigTIFF v3 static and ROI metadata from open file. |
|
|
Read OlympusSIS structure and return as dict. |
|
Read OlympusSIS INI string and return as dict. |
|
Read tags from chain of IFDs and return as list of dicts. |
|
Read TVIPS EM-MENU headers and return as dict. |
|
Read MetaMorph STK UIC1Tag from file and return as dict. |
|
Read MetaMorph STK UIC2Tag from file and return as dict. |
|
Read MetaMorph STK UIC3Tag from file and return as dict. |
|
Read MetaMorph STK UIC4Tag from file and return as dict. |
Read UIC ImagePropertyEx tag from file and return as dict. |
|
|
Read a single UIC tag value from file and return tag name and value. |
|
Read tag data from file and return as unicode string. |
|
Return numpy.recarray as dict. |
|
|
|
|
|
|
|
|
|
Return metatata from ScanImage artist tag as dict. |
|
Return metatata from ScanImage image description as dict. |
|
Return tuple containing value if value is not a tuple or list. |
|
Return string cut to specified length. |
|
|
|
|
|
Return metadata from MetaMorph image description as list of dict. |
|
Return string truncated at last byte that is 7-bit ASCII. |
|
Return string truncated at first null character. |
|
Return metatata from Aperio image description as dict. |
|
|
|
|
|
Update dict with keys and values if keys do not already exist. |
|
Validate TIFF file using jhove -m TIFF-hul. |
|
Return XML as dict. |
Attributes#
- exception TiffFileError#
Bases:
ExceptionException to indicate invalid TIFF structure.
- exception TiffParserError#
Bases:
ExceptionException to indicate parser functionality exceeded
- class FileHandle(file, mode='rb', name=None, offset=None, size=None)#
Binary file handle.
A limited, special purpose file handle that can:
handle embedded files (for CZI within CZI files)
re-open closed files (for multi-file formats, such as OME-TIFF)
read and write numpy arrays and records from file like objects
Only ‘rb’ and ‘wb’ modes are supported. Concurrently reading and writing of the same stream is untested.
When initialized from another file handle, do not use it unless this FileHandle is closed.
- name#
Name of the file.
- Type:
str
- path#
Absolute path to file.
- Type:
str
- size#
Size of file in bytes.
- Type:
int
- is_file#
If True, file has a filno and can be memory-mapped.
- Type:
bool
- All attributes are read-only.
- is_file = False#
- close()#
Close file.
- flush()#
Flush write buffers if applicable.
- memmap_array(dtype, shape, offset=0, mode='r', order='C')#
- open()#
Open or re-open file.
- read(size=-1)#
Read ‘size’ bytes from file, or until EOF is reached.
- read_array(dtype, count=-1, out=None)#
- read_record(dtype, shape=1, byteorder=None)#
Return numpy record from file.
- read_segments(offsets, bytecounts, indices=None, sort=True, lock=None, buffersize=None)#
- readinto(b)#
Read up to len(b) bytes into b, and return number of bytes read.
- seek(offset, whence=0)#
Set file’s current position.
- tell()#
Return file’s current position.
- write(bytestring)#
Write bytes to file.
- write_array(data)#
Write numpy array to binary file.
- write_empty(size)#
Append size bytes to file. Position must be at end of file.
- class FileSequence(fromfile, files, container=None, sort=None, pattern=None, axesorder=None)#
Series of files containing array data of compatible shape and data type.
- files#
List of file names.
- Type:
list
- shape#
Shape of file series. Excludes shape of individual arrays.
- Type:
tuple
- axes#
Labels of axes in shape.
- Type:
str
- axes = ''#
- files#
- fromfile#
- pattern#
- shape#
- asarray(file=None, ioworkers=1, out=None, **kwargs)#
Read image data from files and return as numpy array.
Raise IndexError or ValueError if array shapes do not match.
- Parameters:
file (int or None) – Index or name of single file to read.
ioworkers (int or None) – Maximum number of threads to execute the array read function asynchronously. Default: 1. If None, default to the number of processors multiplied by 5. Using threads can significantly improve runtime when reading many small files from a network share.
out (numpy.ndarray, str, or file-like object) – Buffer where image data will be saved. If None (default), a new array will be created. If numpy.ndarray, a writable array of compatible dtype and shape. If ‘memmap’, create a memory-mapped array in a temporary file. If str or open file, the file name or file object used to create a memory-map to an array stored in a binary file on disk.
kwargs (dict) – Additional parameters passed to the array read function.
- close()#
- class LazyConst(cls)#
Class whose attributes are computed on first access from its methods.
- class NullContext#
Null context manager.
>>> with NullContext(): ... pass
- class OpenFileCache(size, lock=None)#
Keep files open.
- files#
- lock#
- past = []#
- size#
- clear()#
Close all opened files if not in use.
- close(filehandle)#
Close openend file if no longer used.
- open(filehandle)#
Re-open file if necessary.
- class TIFF#
Namespace for module constants.
- ALLOCATIONGRANULARITY()#
- AXES_LABELS()#
- BIG_BE()#
- BIG_LE()#
- CLASSIC_BE()#
- CLASSIC_LE()#
- COLORRESPONSEUNIT()#
- COMPESSORS()#
- COMPRESSION()#
- CZ_LSMINFO()#
- CZ_LSMINFO_DATATYPES()#
- CZ_LSMINFO_DIMENSIONS()#
- CZ_LSMINFO_READERS()#
- CZ_LSMINFO_SCANINFO_ARRAYS()#
- CZ_LSMINFO_SCANINFO_ATTRIBUTES()#
- CZ_LSMINFO_SCANINFO_STRUCTS()#
- CZ_LSMINFO_SCANTYPE()#
- CZ_LSMINFO_TYPEOFDATA()#
- DATATYPES()#
- DATA_DTYPES()#
- DATA_FORMATS()#
- DECOMPESSORS()#
- EXIF_TAGS()#
- EXTRASAMPLE()#
- FILEOPEN_FILTER()#
- FILETYPE()#
- FILE_EXTENSIONS()#
- FILE_FLAGS()#
- FILLORDER()#
- FRAME_ATTRS()#
- GEO_CODES()#
- GEO_KEYS()#
- GPS_TAGS()#
- GRAYRESPONSEUNIT()#
- GROUP4OPT()#
- IOP_TAGS()#
- MAXWORKERS()#
- MM_DIMENSIONS()#
- MM_HEADER()#
- NDPI_LE()#
- NDPI_TAGS()#
- NIH_COLORTABLE_TYPE()#
- NIH_CURVEFIT_TYPE()#
- NIH_IMAGE_HEADER()#
- NIH_LUTMODE_TYPE()#
- NIH_UNITS_TYPE()#
- OFILETYPE()#
- ORIENTATION()#
- PHOTOMETRIC()#
- PILATUS_HEADER()#
- PLANARCONFIG()#
- PREDICTOR()#
- PREDICTORS()#
- RESUNIT()#
- SAMPLEFORMAT()#
- SAMPLE_DTYPES()#
- TAGS()#
- TAG_ATTRIBUTES()#
- TAG_ENUM()#
- TAG_READERS()#
- TAG_TUPLE()#
- THRESHHOLD()#
- TVIPS_HEADER_V1()#
- TVIPS_HEADER_V2()#
- UIC_TAGS()#
- UNPREDICTORS()#
- class TiffFile(arg, name=None, offset=None, size=None, multifile=True, _useframes=None, **kwargs)#
Read image and metadata from TIFF file.
TiffFile instances must be closed using the ‘close’ method, which is automatically called when using the ‘with’ context manager.
TiffFile instances are not thread-safe.
- series#
Sequences of closely related TIFF pages. These are computed from OME, LSM, ImageJ, etc. metadata or based on similarity of page properties such as shape, dtype, and compression.
- Type:
list of TiffPageSeries
- is_flag#
If True, file is of a certain format. Flags are: bigtiff, uniform, shaped, ome, imagej, stk, lsm, fluoview, nih, vista, micromanager, metaseries, mdgel, mediacy, tvips, fei, sem, scn, svs, scanimage, andor, epics, ndpi, pilatus, qpi.
- Type:
bool
- All attributes are read-only.
- asarray(key=None, series=None, out=None, maxworkers=None)#
- close()#
Close open file handle(s).
- fei_metadata()#
Return FEI metadata from SFEG or HELIOS tags as dict.
- flags()#
Return set of file flags.
- fluoview_metadata()#
Return consolidated FluoView metadata as dict.
- fstat()#
Return status of file handle as stat_result object.
- imagej_metadata()#
Return consolidated ImageJ metadata as dict.
- is_mdgel()#
File has MD Gel format.
- is_uniform()#
Return if file contains a uniform series of pages.
- mdgel_metadata()#
Return consolidated metadata from MD GEL tags as dict.
- metaseries_metadata()#
Return MetaSeries metadata from image description as dict.
- micromanager_metadata()#
Return consolidated MicroManager metadata as dict.
- nih_metadata()#
Return NIH Image metadata from NIHImageHeader tag as dict.
- pilatus_metadata()#
Return Pilatus metadata from image description as dict.
- scanimage_metadata()#
Return ScanImage non-varying frame and ROI metadata as dict.
- series()#
Return related pages as TiffPageSeries.
Side effect: after calling this function, TiffFile.pages might contain TiffPage and TiffFrame instances.
- shaped_metadata()#
Return tifffile metadata from JSON descriptions as dicts.
- sis_metadata()#
Return Olympus SIS metadata from SIS and INI tags as dict.
- stk_metadata()#
Return STK metadata from UIC tags as dict.
- class TiffFrame(parent, index, offset=None, keyframe=None, offsets=None, bytecounts=None)#
Lightweight TIFF image file directory (IFD).
Only a limited number of tag values are read from file, e.g. StripOffsets, and StripByteCounts. Other tag values are assumed to be identical with a specified TiffPage instance, the keyframe.
TiffFrame is intended to reduce resource usage and speed up reading image data from file, not for introspection of metadata.
- index#
- is_mdgel = False#
- offset = None#
- pages = None#
- parent#
- asarray(*args, **kwargs)#
Read image data from file and return as numpy array.
- aspage()#
Return TiffPage from file.
- asrgb(*args, **kwargs)#
Read image data from file and return RGB image as numpy array.
- class TiffPage(parent, index, keyframe=None)#
TIFF image file directory (IFD).
- index#
Index of the page in file.
- Type:
int
- dtype#
Data type (native byte order) of the image in IFD.
- Type:
numpy.dtype or None
- shape#
Dimensions of the image in IFD, as returned by asarray.
- Type:
tuple of int
- axes#
Axes label codes for each dimension in shape: ‘X’ width, ‘Y’ height, ‘S’ sample, ‘I’ image series|page|plane, ‘Z’ depth, ‘C’ color|em-wavelength|channel, ‘E’ ex-wavelength|lambda, ‘T’ time, ‘R’ region|tile, ‘A’ angle, ‘P’ phase, ‘H’ lifetime, ‘L’ exposure, ‘V’ event, ‘Q’ unknown, ‘_’ missing
- Type:
str
- colormap#
Color look up table, if exists.
- Type:
numpy.ndarray
- shaped#
Normalized 6 dimensional shape of the image in IFD: 0 : number planes (stk), images (ij), or 1. 1 : separate samplesperpixel or 1. 2 : imagedepth Z (sgi) or 1. 3 : imagelength Y. 4 : imagewidth X. 5 : contig samplesperpixel or 1.
- Type:
tuple of int
- All attributes are read-only.
- axes = ''#
- bitspersample = 1#
- colormap = None#
- compression = 1#
- databytecounts = ()#
- dataoffsets = ()#
- description = ''#
- description1 = ''#
- dtype = None#
- extrasamples = 1#
- fillorder = 1#
- imagedepth = 1#
- imagelength = 0#
- imagewidth = 0#
- index#
- nodata = 0#
- offset#
- parent#
- photometric = 0#
- planarconfig = 1#
- predictor = 1#
- rowsperstrip = 4294967295#
- sampleformat = 1#
- samplesperpixel = 1#
- shape = ()#
- shaped = ()#
- software = ''#
- subfiletype = 0#
- tiledepth = 1#
- tilelength = 0#
- tilewidth = 0#
- andor_tags()#
Return consolidated metadata from Andor tags as dict.
- asarray(out=None, squeeze=True, lock=None, reopen=True, maxsize=None, maxworkers=None)#
- aspage()#
Return self.
- asrgb(uint8=False, alpha=None, colormap=None, dmin=None, dmax=None, **kwargs)#
- decode()#
- epics_tags()#
Return consolidated metadata from EPICS areaDetector tags as dict.
- flags()#
Return set of flags.
- geotiff_tags()#
Return consolidated metadata from GeoTIFF tags as dict.
- hash()#
Return checksum to identify pages in same series.
Pages with the same hash can use the same decode function.
- is_contiguous()#
Return offset and size of contiguous data, else None.
Excludes prediction and fill_order.
- is_final()#
Return if page’s image data are stored in final form.
Excludes byte-swapping.
- is_imagej()#
Return ImageJ description if exists, else None.
- is_memmappable()#
Return if page’s image data in file can be memory-mapped.
- is_ndpi()#
Page contains NDPI metadata.
- is_shaped()#
Return description containing array shape if exists, else None.
- maxworkers()#
Return maximum number of threads for decoding strips ot tiles.
- ndpi_tags()#
Return consolidated metadata from Hamamatsu NDPI as dict.
- pages()#
Return sequence of sub-pages (SubIFDs).
- class TiffPageSeries(pages, shape, dtype, axes, parent=None, name=None, transform=None, kind=None, truncated=False)#
Series of TIFF pages with compatible shape and data type.
- dtype#
Data type (native byte order) of the image array in series.
- Type:
numpy.dtype
- shape#
Dimensions of the image array in series.
- Type:
tuple
- axes#
Labels of axes in shape. See TiffPage.axes.
- Type:
str
- offset#
Position of image data in file if memory-mappable, else None.
- Type:
int or None
- axes = ''#
- dtype#
- index = 0#
- kind = ''#
- name = ''#
- shape#
- transform = None#
- asarray(**kwargs)#
Return image data from series of TIFF pages as numpy array.
- offset()#
Return offset to series data in file, if any.
- class TiffPages(parent)#
Sequence of TIFF image file directories (IFD chain).
Instances of TiffPages have a state (cache, keyframe, etc.) and are not thread-safe.
- pages = []#
- parent = None#
- class TiffTag(parent, tagheader, tagoffset)#
TIFF tag structure.
- name#
Name of tag, TIFF.TAGS[code].
- Type:
string
- code#
Decimal code of tag.
- Type:
int
- dtype#
Datatype of tag data. One of TIFF DATA_FORMATS.
- Type:
str
- count#
Number of values.
- Type:
int
- value#
Tag data as Python object.
- Type:
various types
- offset#
Location of tag structure in file.
- Type:
int
- valueoffset#
Location of value in file.
- Type:
int
- All attributes are read-only.
- code#
- count#
- dtype#
- offset#
- value#
- valueoffset#
- class TiffTags#
Multidict like interface to TiffTag instances in TiffPage.
Differences to a regular dict:
values are instances of TiffTag.
keys are TiffTag.code (int).
multiple values can be stored per key.
can be indexed with TiffTag.name (str), although slower than by key.
iter() returns values instead of keys.
values() and items() contain all values sorted by offset stored in file.
len() returns the number of all values.
get() takes an optional index argument.
some functions are not implemented, e.g. update, setdefault, pop.
- add(tag)#
Add a tag.
- get(key, default=None, index=None)#
Return tag of code or name if exists, else default.
- getall(key, default=None)#
Return list of all tags of code or name if exists, else default.
- items()#
Return all (code, tag) pairs in order tags are stored in file.
- keys()#
Return new view of all codes.
- values()#
Return all tags in order they are stored in file.
- apply_colormap(image, colormap, contig=True)#
- asbool(value, true=(b'true', 'true'), false=(b'false', 'false'))#
Return string as bool if possible, else raise TypeError.
>>> asbool(b' False ') False
- askopenfilename(**kwargs)#
- astype(value, types=None)#
Return argument as one of types if possible.
>>> astype('42') 42 >>> astype('3.14') 3.14 >>> astype('True') True >>> astype(b'Neee-Wom') 'Neee-Wom'
- byteorder_isnative(byteorder)#
Return if byteorder matches the system’s byteorder.
>>> byteorder_isnative('=') True
- bytes2str(b, encoding=None, errors='strict')#
Return unicode string from encoded bytes.
- bytestr(s, encoding='cp1252')#
Return bytes from unicode string, else pass through.
- clean_whitespace(string, compact=False)#
Return string with compressed whitespace.
- create_output(out, shape, dtype, mode='w+', suffix=None)#
- enumarg(enum, arg)#
Return enum member from its name or value.
>>> enumarg(TIFF.PHOTOMETRIC, 2) <PHOTOMETRIC.RGB: 2> >>> enumarg(TIFF.PHOTOMETRIC, 'RGB') <PHOTOMETRIC.RGB: 2>
- enumstr(enum)#
Return short string representation of Enum instance.
- excel_datetime(timestamp, epoch=None)#
Return datetime object from timestamp in Excel serial format.
Convert LSM time stamps.
>>> excel_datetime(40237.029999999795) datetime.datetime(2010, 2, 28, 0, 43, 11, 999982)
- fluoview_description_metadata(description, ignoresections=None)#
Return metatata from FluoView image description as dict.
The FluoView image description format is unspecified. Expect failures.
>>> descr = ('[Intensity Mapping]\nMap Ch0: Range=00000 to 02047\n' ... '[Intensity Mapping End]') >>> fluoview_description_metadata(descr) {'Intensity Mapping': {'Map Ch0: Range': '00000 to 02047'}}
- format_size(size, threshold=1536)#
Return file size as string from byte size.
>>> format_size(1234) '1234 B' >>> format_size(12345678901) '11.50 GiB'
- getdtype(d)#
- hexdump(bytestr, width=75, height=24, snipat=-2, modulo=2, ellipsis=None)#
Return hexdump representation of bytes.
>>> hexdump(binascii.unhexlify('49492a00080000000e00fe0004000100')) '49 49 2a 00 08 00 00 00 0e 00 fe 00 04 00 01 00 II*.............'
- identityfunc(arg, *args, **kwargs)#
Single argument identity function.
>>> identityfunc('arg') 'arg'
- imagej_description(shape, rgb=None, colormaped=False, version=None, hyperstack=None, mode=None, loop=None, **kwargs)#
Return ImageJ image description from data shape.
ImageJ can handle up to 6 dimensions in order TZCYXS.
>>> imagej_description((51, 5, 2, 196, 171)) ImageJ=1.11a images=510 channels=2 slices=5 frames=51 hyperstack=true mode=grayscale loop=false
- imagej_description_metadata(description)#
Return metatata from ImageJ image description as dict.
Raise ValueError if not a valid ImageJ description.
>>> description = 'ImageJ=1.11a\nimages=510\nhyperstack=true\n' >>> imagej_description_metadata(description) {'ImageJ': '1.11a', 'images': 510, 'hyperstack': True}
- imagej_metadata(data, bytecounts, byteorder)#
Return IJMetadata tag value as dict.
The ‘Info’ string can have multiple formats, e.g. OIF or ScanImage, that might be parsed into dicts using the matlabstr2py or oiffile.SettingsFile functions. ‘ROI’ and ‘Overlays’ are returned as bytes, which can be parsed with the ImagejRoi.frombytes() function of the roifile package.
- imagej_metadata_tag(metadata, byteorder)#
Return IJMetadata and IJMetadataByteCounts tags from metadata dict.
The tags can be passed to TiffWriter.save() as extratags.
The metadata dict may contain the following keys and values:
- Infostr
Human-readable information as string.
- Labelssequence of str
Human-readable labels for each channel.
- Rangessequence of doubles
Lower and upper values for each channel.
- LUTssequence of (3, 256) uint8 ndarrays
Color palettes for each channel.
- Plotbytes
Undocumented ImageJ internal format.
- ROI: bytes
Undocumented ImageJ internal region of interest format.
- Overlaysbytes
Undocumented ImageJ internal format.
- imagej_shape(shape, rgb=None)#
Return shape normalized to 6D ImageJ hyperstack TZCYXS.
Raise ValueError if not a valid ImageJ hyperstack shape.
>>> imagej_shape((2, 3, 4, 5, 3), False) (2, 3, 4, 5, 3, 1)
- imshow(data, photometric=None, planarconfig=None, bitspersample=None, nodata=0, interpolation=None, cmap=None, vmin=None, vmax=None, figure=None, title=None, dpi=96, subplot=None, maxdim=None, **kwargs)#
- isprintable(string)#
Return if all characters in string are printable.
>>> isprintable('abc') True >>> isprintable(b'') False
- json_description(shape, **metadata)#
Return JSON image description from data shape and other metadata.
Return UTF-8 encoded JSON.
>>> json_description((256, 256, 3), axes='YXS') b'{"shape": [256, 256, 3], "axes": "YXS"}'
- json_description_metadata(description)#
Return metatata from JSON formated image description as dict.
Raise ValuError if description is of unknown format.
>>> description = '{"shape": [256, 256, 3], "axes": "YXS"}' >>> json_description_metadata(description) {'shape': [256, 256, 3], 'axes': 'YXS'} >>> json_description_metadata('shape=(256, 256, 3)') {'shape': (256, 256, 3)}
- julian_datetime(julianday, milisecond=0)#
Return datetime from days since 1/1/4713 BC and ms since midnight.
Convert Julian dates according to MetaMorph.
>>> julian_datetime(2451576, 54362783) datetime.datetime(2000, 2, 2, 15, 6, 2, 783)
- log_warning(msg, *args, **kwargs)#
Log message with level WARNING.
- lsm2bin(lsmfile, binfile=None, tile=None, verbose=True)#
- matlabstr2py(string)#
- metaseries_description_metadata(description)#
Return metatata from MetaSeries image description as dict.
- natural_sorted(iterable)#
Return human sorted list of strings.
E.g. for sorting file names.
>>> natural_sorted(['f1', 'f2', 'f10']) ['f1', 'f2', 'f10']
- nullfunc(*args, **kwargs)#
Null function.
>>> nullfunc('arg', kwarg='kwarg')
- olympusini_metadata(inistr)#
Return OlympusSIS metadata from INI string.
No documentation is available.
- parse_filenames(files, pattern, axesorder=None)#
- parse_kwargs(kwargs, *keys, **keyvalues)#
Return dict with keys from keys|keyvals and values from kwargs|keyvals.
Existing keys are deleted from kwargs.
>>> kwargs = {'one': 1, 'two': 2, 'four': 4} >>> kwargs2 = parse_kwargs(kwargs, 'two', 'three', four=None, five=5) >>> kwargs == {'one': 1} True >>> kwargs2 == {'two': 2, 'four': 4, 'five': 5} True
- pformat(arg, width=79, height=24, compact=True)#
- pformat_xml(xml)#
Return pretty formatted XML.
- pilatus_description_metadata(description)#
Return metatata from Pilatus image description as dict.
Return metadata from Pilatus pixel array detectors by Dectris, created by camserver or TVX software.
>>> pilatus_description_metadata('# Pixel_size 172e-6 m x 172e-6 m') {'Pixel_size': (0.000172, 0.000172)}
- product(iterable)#
Return product of sequence of numbers.
Equivalent of functools.reduce(operator.mul, iterable, 1). Multiplying numpy integers might overflow.
>>> product([2**8, 2**30]) 274877906944 >>> product([]) 1
- read_bytes(fh, byteorder, dtype, count, offsetsize)#
Read tag data from file and return as bytes.
- read_colormap(fh, byteorder, dtype, count, offsetsize)#
Read ColorMap data from file and return as numpy array.
- read_cz_lsminfo(fh, byteorder, dtype, count, offsetsize)#
Read CZ_LSMINFO tag from file and return as dict.
- read_cz_sem(fh, byteorder, dtype, count, offsetsize)#
Read Zeiss SEM tag and return as dict.
See https://sourceforge.net/p/gwyddion/mailman/message/29275000/ for unnamed values.
- read_exif_ifd(fh, byteorder, dtype, count, offsetsize)#
Read EXIF tags from file and return as dict.
- read_fei_metadata(fh, byteorder, dtype, count, offsetsize)#
Read FEI SFEG/HELIOS headers and return as dict.
- read_gps_ifd(fh, byteorder, dtype, count, offsetsize)#
Read GPS tags from file and return as dict.
- read_interoperability_ifd(fh, byteorder, dtype, count, offsetsize)#
Read Interoperability tags from file and return as dict.
- read_json(fh, byteorder, dtype, count, offsetsize)#
Read JSON tag data from file and return as object.
- read_lsm_channelcolors(fh)#
Read LSM ChannelColors structure from file and return as dict.
- read_lsm_eventlist(fh)#
Read LSM events from file and return as list of (time, type, text).
- read_lsm_floatpairs(fh)#
Read LSM sequence of float pairs from file and return as list.
- read_lsm_positions(fh)#
Read LSM positions from file and return as list.
- read_lsm_scaninfo(fh)#
Read LSM ScanInfo structure from file and return as dict.
- read_lsm_timestamps(fh)#
Read LSM time stamps from file and return as list.
- read_metaseries_catalog(fh)#
Read MetaSeries non-TIFF hint catalog from file.
Raise ValueError if the file does not contain a valid hint catalog.
- read_micromanager_metadata(fh)#
Read MicroManager non-TIFF settings from open file and return as dict.
The settings can be used to read image data without parsing the TIFF file.
Raise ValueError if the file does not contain valid MicroManager metadata.
- read_mm_header(fh, byteorder, dtype, count, offsetsize)#
Read FluoView mm_header tag from file and return as dict.
- read_mm_stamp(fh, byteorder, dtype, count, offsetsize)#
Read FluoView mm_stamp tag from file and return as numpy.ndarray.
- read_nih_image_header(fh, byteorder, dtype, count, offsetsize)#
Read NIH_IMAGE_HEADER tag from file and return as dict.
- read_numpy(fh, byteorder, dtype, count, offsetsize)#
Read tag data from file and return as numpy array.
- read_scanimage_metadata(fh)#
Read ScanImage BigTIFF v3 static and ROI metadata from open file.
Return non-varying frame data as dict and ROI group data as JSON.
The settings can be used to read image data and metadata without parsing the TIFF file.
Raise ValueError if file does not contain valid ScanImage v3 metadata.
- read_sis(fh, byteorder, dtype, count, offsetsize)#
Read OlympusSIS structure and return as dict.
No specification is avaliable. Only few fields are known.
- read_sis_ini(fh, byteorder, dtype, count, offsetsize)#
Read OlympusSIS INI string and return as dict.
- read_tags(fh, byteorder, offsetsize, tagnames, customtags=None, maxifds=None)#
Read tags from chain of IFDs and return as list of dicts.
The file handle position must be at a valid IFD header.
- read_tvips_header(fh, byteorder, dtype, count, offsetsize)#
Read TVIPS EM-MENU headers and return as dict.
- read_uic1tag(fh, byteorder, dtype, count, offsetsize, planecount=None)#
Read MetaMorph STK UIC1Tag from file and return as dict.
Return empty dictionary if planecount is unknown.
- read_uic2tag(fh, byteorder, dtype, planecount, offsetsize)#
Read MetaMorph STK UIC2Tag from file and return as dict.
- read_uic3tag(fh, byteorder, dtype, planecount, offsetsize)#
Read MetaMorph STK UIC3Tag from file and return as dict.
- read_uic4tag(fh, byteorder, dtype, planecount, offsetsize)#
Read MetaMorph STK UIC4Tag from file and return as dict.
- read_uic_image_property(fh)#
Read UIC ImagePropertyEx tag from file and return as dict.
- read_uic_tag(fh, tagid, planecount, offset)#
Read a single UIC tag value from file and return tag name and value.
UIC1Tags use an offset.
- read_utf8(fh, byteorder, dtype, count, offsetsize)#
Read tag data from file and return as unicode string.
- recarray2dict(recarray)#
Return numpy.recarray as dict.
- reorient(image, orientation)#
- repeat_nd(a, repeats)#
- reshape_axes(axes, shape, newshape, unknown=None)#
- reshape_nd(data_or_shape, ndim)#
- scanimage_artist_metadata(artist)#
Return metatata from ScanImage artist tag as dict.
- scanimage_description_metadata(description)#
Return metatata from ScanImage image description as dict.
- sequence(value)#
Return tuple containing value if value is not a tuple or list.
>>> sequence(1) (1,) >>> sequence([1]) [1] >>> sequence('ab') ('ab',)
- snipstr(string, width=79, snipat=None, ellipsis=None)#
Return string cut to specified length.
>>> snipstr('abcdefghijklmnop', 8) 'abc...op'
- squeeze_axes(shape, axes, skip=None)#
- stack_pages(pages, out=None, maxworkers=None, **kwargs)#
- stk_description_metadata(description)#
Return metadata from MetaMorph image description as list of dict.
The MetaMorph image description format is unspecified. Expect failures.
- stripascii(string)#
Return string truncated at last byte that is 7-bit ASCII.
Clean NULL separated and terminated TIFF strings.
>>> stripascii(b'string\x00string\n\x01\x00') b'string\x00string\n' >>> stripascii(b'\x00') b''
- stripnull(string, null=b'\x00')#
Return string truncated at first null character.
Clean NULL terminated C strings. For unicode strings use null=’0’.
>>> stripnull(b'string\x00') b'string' >>> stripnull('string\x00', null='\0') 'string'
- svs_description_metadata(description)#
Return metatata from Aperio image description as dict.
The Aperio image description format is unspecified. Expect failures.
>>> svs_description_metadata('Aperio Image Library v1.0') {'Aperio Image Library': 'v1.0'}
- transpose_axes(image, axes, asaxes=None)#
- unpack_rgb(data, dtype=None, bitspersample=None, rescale=True)#
- update_kwargs(kwargs, **keyvalues)#
Update dict with keys and values if keys do not already exist.
>>> kwargs = {'one': 1, } >>> update_kwargs(kwargs, one=None, two=2) >>> kwargs == {'one': 1, 'two': 2} True
- validate_jhove(filename, jhove=None, ignore=None)#
Validate TIFF file using jhove -m TIFF-hul.
Raise ValueError if jhove outputs an error message unless the message contains one of the strings in ‘ignore’.
JHOVE does not support bigtiff or more than 50 IFDs.
- xml2dict(xml, sanitize=True, prefix=None)#
Return XML as dict.
>>> xml2dict('<?xml version="1.0" ?><root attr="name"><key>1</key></root>') {'root': {'key': 1, 'attr': 'name'}} >>> xml2dict('<level1><level2>3.5322</level2></level1>') {'level1': {'level2': 3.5322}}
- itemsizes#