Package: readlif
readlif README fileThe readlif package was developed to be a fast, python only, reader for Leica Lif files. This is tested in Python 3.6 through 3.9.The basic premise is to read an image from a Lif file into a Pillow object. The only additional requirement for this package is Pillow>=7.2.0.This code is inspired by theOpen Microscopy Bio-Formats project.Auto-generated documentation is availablehere.InstallationThis package is available on pypi, so you can install it with pippip install readlifAlternatively, clone the git repo and install with setuptoolspython setup.py installKnown issuesThere may be an issue where a truncated 16-bit file will load incorrectly, however
this is not tested. If you have an example file, open an issue!There is not support for FlipX, FlipY and SwapXY metadata. If you need this,
please open an issue!Truncated images are returned as blank images.There is currently no support for returning arbitrary planes fromget_planeby specifyingdisplay_dims. This is in progress.12- and 16-bit imagesAs of 0.3.0,reaflifwill now support images with bit depth greater than 8.However, note that while some images will be returned as a 16 bit array, they may
actually 10 or 12 bit images. It is not simple to easily convert these without
the potential of losing data, so a newbit_depthattribute has been added
toLifImageto indicate the bit depth of each channel in the image.It is up to the user to decide how, or if, to convert these. There is an upscaling example below.ExamplesEverything in this package is numbered starting from 0, which is not consistent with how things like ImageJ operate.The basic object is the LifFile object.fromreadlif.readerimportLifFilenew=LifFile('./path/to/file.lif')This object contains a few methods to access the images contained within the Lif file. All images, in a folder or not, will be accessible sequentially from theLifFileobject.# Access a specific image directlyimg_0=new.get_image(0)# Create a list of images using a generatorimg_list=[iforiinnew.get_iter_image()]The resultingLifImageobject has a few methods to access the specific two-dimensional frame contained in the image, where z is the z position, t is the timepoint, and c is the channel.# Access a specific itemimg_0.get_frame(z=0,t=0,c=0)# Iterate over different itemsframe_list=[iforiinimg_0.get_iter_t(c=0,z=0)]z_list=[iforiinimg_0.get_iter_z(t=0,c=0)]channel_list=[iforiinimg_0.get_iter_c(t=0,z=0)]The two dimensional images returned by these methods are Pillow objects, so the applicable methods (.show()) will work with them.If it is necessary to scale a 12-bit image to the full 16-bit range, it is possible to do this with numpy.importnumpyasnp# Assumes all channels have the same bit depthscale_factor=(16-img_0.bit_depth[0])**2frame=img_0.get_frame(z=0,t=0,c=0)img_array=np.uint16(np.array(frame)*scale_factor)Image.fromarray(img_array).show()This has only been tested on Lif files that were generated with Leica LAS X and Leica LAS AF. There will likely be files that will not work with this software. In that case, please open an issue on github!Changelog0.6.5Added a new attributesettingstoLifImagewhich contains useful capture settingsThanks to PR from @tmtenbrink0.6.4Fixed bug and incompatibility in 0.6.3Added preliminary fix for images captured with stage navigator0.6.3Added support for updated LasX with additional data in the Lif fileChanged the way file names are assigned, now includes folder pathThis fix is intended to clarify imaging sets with many duplicate names0.6.2Fixed bug where the time and image scale were calculated incorrectlyClarified scaling documentation0.6.1Update readme0.6.0Added support for non-XY images withget_plane(). See docs for usage.Note: Reading arbitrary planes (i.e. an XZ plane of an XY image) is not yet supported.0.5.2Bugfix: Fix error in mosaic parsing.PosXmetadata was incorrectly read fromPosY0.5.1Bugfix: switch fromio.BufferedIOBasetoio.IOBase0.5.0Added support for loading files from buffersThans to PR from @JacksonMaxfield0.4.1Fixed critical documentaiton error:LifImage.scaleis in px/µm, not px/nm for X and Y dimensions0.4.0Added support for tiled imagesmwas added as a new dimension (for tiled images)LifImagechanges:Newget_iter_m()functionNewmosaic_positionattribute with(FieldX, FieldY, PosX, PosY)Under the hood changesLifImage.dimsis now a named tuple for clearer codeOther thingsPrettier outputs forrepr()Switch to github CI0.3.1Added error message for tiled images, pending feature addition0.3.0Added support for 16-bit images, increased minimum Pillow version to 7.2.0.NewLifImageattributebit_depthis a tuple of intigers descibing the bit
depth for each channel in the image.Thanks to @DirkRemmers for providing the example file.Changed type fromstrtointfordimsandchannelsin theinfodictionaryAdded python 3.9 to build testing0.2.1FixedZeroDivisionErrorwhen the Z-dimension is defined, but has a length of 0. Clarified an error message. Added fix for truncated files.0.2.0LifImage.scalenow returns px/nm conversions0.1.1Style changes0.1.0Initial release