pytiff is a lightweight library for reading chunks from a tiff file

Overview

pytiff

pytiff is a lightweight library for reading chunks from a tiff file. While it supports other formats to some extend, it is focused on reading tiled greyscale/rgb images, that can also be bigtiffs. Writing tiff files is now partly supported. It is able to save uncompressed greyscale images in tiled or scanline format. More information can be found in the documentation. Pytiff supports numpy like slicing and uses numpy arrays to handle image data.

The libtiff library is wrapped using the Cython package.

develop : Build Status master: Build Status coverage: Coverage Status doc: Documentation Status

Dependencies

  • libtiff C library (>= 4.0 for bigtiff access)
  • Cython >= 0.23
  • numpy

Installation

Installation on Linux / Mac

Just use pip

pip install pytiff

or from sources: clone the repo and call setup.py.

git clone https://github.com/FZJ-INM1-BDA/pytiff.git
cd pytiff
pip install -r requirements.txt
pip install . # or python setup.py install

Installation on Windows

Recommended: Use Anaconda

* Install Anaconda or Miniconda
* Install [Microsoft Visual C++ Build Tools](http://landinghub.visualstudio.com/visual-cpp-build-tools)
* Install Visual C++ using Visual Studio (development headers..)
* Set your INCLUDE environment variable to "path\to\anaconda\Library\include"
* Set LIB environment variable to point to "tiff.lib" or Copy tiff.lib from "Anaconda\Library\lib\" into the installation directory
* Start Visual Studio Development CMD
* `python setup.py install`

Development

For development:

git clone https://github.com/FZJ-INM1-BDA/pytiff.git
cd pytiff
# git checkout develop
pip install -r requirements.txt
pip install -e . # or python setup.py develop

can be used, so that no reinstallation is needed for every update. If new updates are pulled the cython part has to be recompiled.

#compile cython part
python setup.py build_ext --inplace

Usage

A small example how pytiff can be used:

Reading:

import pytiff

with pytiff.Tiff("test_data/small_example_tiled.tif") as handle:
  part = handle[100:200, :]

Writing data from pages into a multipage tiff:

import pytiff
with pytiff.Tiff("test_data/tmp.tif", "w") as handle:
  for p in pages:
    handle.write(p, method="scanline")
Comments
  • Encode and decode tags with encoding parameter

    Encode and decode tags with encoding parameter

    I've changed the type casting of tags as strings decoded using an encoding parameter passed to pytiff.Tiff. This will prevent an error on unicode tags in python 3 and will resolve issue #16. This new behavior will allow users to decode the tag values into their preferred encoding. Setting tags also uses the encoding parameter.

    opened by thejohnhoffer 2
  • Missing dependency: Cython

    Missing dependency: Cython

    I found out after installing pytiff that the package cython was missing as a dependency because I did not install it previously.

    The error message (under Windows and Python 3.7.2) with pytiff-0.8.0 said "Cython modules not available". Could you please make sure that during the installation the installer setup checks the availabillity of cython?

    opened by strpeter 2
  • Problems with sliced arrays and method = 'scanline'

    Problems with sliced arrays and method = 'scanline'

    I encountered this proplem as I tried to save a 3D np.array as a stack of tifs.

    What I essentially did was this:

    img_stack = np.zeros((100,100,50), dtype = 'uint8')
    img_stack[30:60,30:60,20:30] = 255
    
    for ind in range(50):
        img_slice = img_stack[:,:,ind]
        with pytiff.Tiff(file_path.format(ind), 'w') as handle:
            handle.write(img_slice, method='scanline')
    

    This produces same strange artefacts, when used on a regular image stack. On this particular 'image stack' it should produce all black tifs, if the problem is reproduceable on other machines.

    The problem does not occur, when the flag method is set to 'tile'. I fixed this py replacing the line img_slice = img_stack[:,:,ind] with img_slice = img_stack[:,:,ind].copy()

    opened by Sifeiros 1
  • pip install pytiff fails when numpy is not available

    pip install pytiff fails when numpy is not available

    pip install pytiff
    Downloading/unpacking pytiff Downloading pytiff-0.7.0.tar.gz (1.3MB): 1.3MB downloaded Running setup.py (path:/tmp/pip-build-3abmxk7b/pytiff/setup.py) egg_info for package pytiff Traceback (most recent call last): File "/tmp/pip-build-3abmxk7b/pytiff/setup.py", line 13, in import numpy ImportError: No module named 'numpy'

    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip-build-3abmxk7b/pytiff/setup.py", line 15, in <module>
        raise Exception("Numpy is needed for installation")
    Exception: Numpy is needed for installation
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
    

    File "/tmp/pip-build-3abmxk7b/pytiff/setup.py", line 13, in

    import numpy
    

    ImportError: No module named 'numpy'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):

    File "", line 17, in

    File "/tmp/pip-build-3abmxk7b/pytiff/setup.py", line 15, in

    raise Exception("Numpy is needed for installation")
    

    Exception: Numpy is needed for installation

    opened by ylep 1
  • test_data/bigtif_example_tiled.tif is not a Bigtiff

    test_data/bigtif_example_tiled.tif is not a Bigtiff

    I was looking for an example of a 'tiled' Bigtiff file, so naturally I opened test_data/bigtif_example_tiled.tif from this repo:

    In [90]: hex( ord( open('test_data/bigtif_example_tiled.tif', 'r').read(4)[2] ) )
    Out[90]: '0x2a'
    

    Whoops, the third byte of a Bigtiff file should be 0x2b, not 0x2a.[1]

    [1]: http://bigtiff.org/

    opened by stuarteberg 1
  • Only pad if it is really necessary.

    Only pad if it is really necessary.

    I noticed that pytiff spends a lot of time for padding data before writing it to file. In the current implementation, padding is always applied, even if the padding is zero in all dimensions.

    I modified the implementation to only pad when padding is actually necessary. In the process, I noticed that pytiff seems to "abuse" the padding to convert the incoming buffer from Fortran memory layout to C memory layout. Thus, if no padding is applied, we have to do this conversion explicitly.

    The check for padding is not the prettiest, but using np.sum instead introduces a significant overhead.

    In my tests (writing a chunked TIFF file, 6000x7000 pixels, plus pyramid), the change reduces the time for pytiff's __setitem__ from 8.93 seconds to 0.807 seconds (so ~10 fold speedup). The results are identical (verified by checksum).

    opened by ch-schiffer 0
  • Not abel to load file paths with symlinks

    Not abel to load file paths with symlinks

    Pytiff gives an OSError: file not found when opening a new image with pytiff.Tiff('filename.tif') in case that the filename path is a symlink. I could overcome this problem by doing from os import readlink; pytiff.Tiff(readlink('filename.tif')); however this is not the expected behaviour.

    opened by dickscheid 1
  • Fatal Python error: deallocating NotImplemented

    Fatal Python error: deallocating NotImplemented

    I am trying to read a large Aperio Imagescope image (BigTIFF format). I can read the image without issues and it is very fast. However, after I am finished, I am running into an error that

     Fatal Python error: deallocating NotImplemented
    

    Has this issue ever come up before? Any way to avoid it? Thanks

    opened by hhoeflin 1
  • Non-ascii data in string tags causes a UnicodeDecodeError on Python 3

    Non-ascii data in string tags causes a UnicodeDecodeError on Python 3

    Although TIFF string tags are only supposed to contain 7-bit ASCII characters, many tools write values in UTF-8 or other encodings that aren't 7-bit clean. OME-TIFF/BioFormats is one such tool, where the XML stored in the ImageDescription tag is explicitly encoded as UTF-8. On Python 3, pytiff.Tiff._read_ascii raises a UnicodeDecodeError upon reading such values. On Python 2, where the treatment of string encoding/decoding isn't as rigorous, the problem is effectively ignored.

    Would you accept a patch to fix this? I think the simplest approach is to always decode strings as UTF-8, perhaps only under Python 3. This actually mirrors the way _set_tag already performs UTF-8 string encoding, only under Python 3. I would also be willing to implement a more flexible approach with a user-controlled encoding if you think that's a better option.

    opened by jmuhlich 4
  • pytiff fails to install on Windows

    pytiff fails to install on Windows

    This issue is related to the one entitled "Missing dependency: Cython", which was closed. I'm very happy to hear about pytiff! It is exactly what I have been looking for, already for some time. At first I installed pytiff as part of my Python 3.6.5 instance (32-bits). When I tried to run it, I got the error "Cython modules not available". Because I read that this problem had been fixed for Python 3.7, I decided to do a fresh install of Python 3.7.4. After installing, I even upgraded pip. Unfortunately, I have to conclude that the issue has not yet been resolved fully. I'm attaching the error messages. I hope this can be resolved, so that I can use pytiff without hesitations as one of the required packages in a package I'm developing myself. pytiff_issue.txt

    opened by sbhoek 13
  • loading 3D .tiff files

    loading 3D .tiff files

    I have image stacks which I am trying to load into pytiff. However, it looks like it only loads the first slice:

        with pytiff.Tiff(input_fpath) as handle:
            img_array = handle
            print(img_array.shape)  # (15, 15) instead of (15,15,15)
    
    opened by crypdick 1
Releases(0.8.0)
  • 0.8.0(Jul 31, 2018)

    Updated Tags

    • Tags now use enums instead of simple strings (pytiff.tags).
    • Fields with a scalar do now return a scalar instead of a numpy array of length 1.

    Page Handling

    • you can no longer iterate over a Tiff object.
    • instead a Tiff object has a tif.pages attribute, that returns a list with each page.
    • the manual way via calling tif.set_page(1) is still valid.
    Source code(tar.gz)
    Source code(zip)
Owner
Big Data Analytics group
Big Data Analytics group at the Institute of Neuroscience and Medicine (INM-1), Forschungszentrum Juelich
Big Data Analytics group
Automatically generates a TypeQL script for doing entity and relationship insertions from a .csv file, so you don't have to mess with writing TypeQL.

Automatically generates a TypeQL script for doing entity and relationship insertions from a .csv file, so you don't have to mess with writing TypeQL.

3 Feb 09, 2022
Test app for importing contact information in CSV files.

Contact Import TestApp Test app for importing contact information in CSV files. Explore the docs » · Report Bug · Request Feature Table of Contents Ab

1 Feb 06, 2022
Uproot is a library for reading and writing ROOT files in pure Python and NumPy.

Uproot is a library for reading and writing ROOT files in pure Python and NumPy. Unlike the standard C++ ROOT implementation, Uproot is only an I/O li

Scikit-HEP Project 164 Dec 31, 2022
Uncompress DEFLATE streams in pure Python

stream-inflate Uncompress DEFLATE streams in pure Python. Installation pip install stream-inflate Usage from stream_inflate import stream_inflate impo

Michal Charemza 7 Oct 13, 2022
An universal file format tool kit. At present will handle the ico format problem.

An universal file format tool kit. At present will handle the ico format problem.

Sadam·Sadik 1 Dec 26, 2021
Maltego transforms to pivot between PE files based on their VirusTotal codeblocks

VirusTotal Codeblocks Maltego Transforms Introduction These Maltego transforms allow you to pivot between different PE files based on codeblocks they

Ariel Jungheit 18 Feb 03, 2022
Utils for streaming large files (S3, HDFS, gzip, bz2...)

smart_open — utils for streaming large files in Python What? smart_open is a Python 3 library for efficient streaming of very large files from/to stor

RARE Technologies 2.7k Jan 06, 2023
A simple file sharing tool written in python

Share it A simple file sharing tool written in python Installation If you are using Windows os you can directly Run .exe file -- download If you are

Sachit Yadav 7 Dec 16, 2022
Various converters to convert value sets from CSV to JSON, etc.

ValueSet Converters Tools for converting value sets in different formats. Such as converting extensional value sets in CSV format to JSON format able

Health Open Terminology Ecosystem 4 Sep 08, 2022
Organize the files into the relevant sub-folders

This program can be used to organize files in a directory by their file extension. And move duplicate files to a duplicates folder.

Thushara Thiwanka 2 Dec 15, 2021
dotsend is a web application which helps you to upload your large files and share file via link

dotsend is a web application which helps you to upload your large files and share file via link

Devocoe 0 Dec 03, 2022
Extract the windows major and minor build numbers from an ISO file, and automatically sort the iso files.

WindowsBuildFromISO Extract the windows major and minor build numbers from an ISO file, and automatically sort the iso files. Features Parse multiple

Podalirius 9 Nov 09, 2022
Python package to read and display segregated file names present in a directory based on type of the file

tpyfilestructure Python package to read and display segregated file names present in a directory based on type of the file. Installation You can insta

Tharun Kumar T 2 Nov 28, 2021
Creates folders into a directory to categorize files in that directory by file extensions and move all things from sub-directories to current directory.

Categorize and Uncategorize Your Folders Table of Content TL;DR just take me to how to install. What are Extension Categorizer and Folder Dumper Insta

Furkan Baytekin 1 Oct 17, 2021
Python interface for reading and appending tar files

Python interface for reading and appending tar files, while keeping a fast index for finding and reading files in the archive. This interface has been

Lawrence Livermore National Laboratory 1 Nov 12, 2021
A bot discord that can create directories, file, rename, move, navigate throw directories etc....

File Manager Discord What is the purpose of this program ? This program is made for a Discord bot. Its purpose is to organize the messages sent in a c

1 Feb 02, 2022
Vericopy - This Python script provides various usage modes for secure local file copying and hashing.

Vericopy This Python script provides various usage modes for secure local file copying and hashing. Hash data is captured and logged for paths before

15 Nov 05, 2022
Search for files under the specified directory. Extract the file name and file path and import them as data.

Search for files under the specified directory. Extract the file name and file path and import them as data. Based on that, search for the file, select it and open it.

G-jon FujiYama 2 Jan 10, 2022
Singer is an open source standard for moving data between databases, web APIs, files, queues, and just about anything else you can think of.

Singer is an open source standard for moving data between databases, web APIs, files, queues, and just about anything else you can think of. Th

Singer 1.1k Jan 05, 2023
Python's Filesystem abstraction layer

PyFilesystem2 Python's Filesystem abstraction layer. Documentation Wiki API Documentation GitHub Repository Blog Introduction Think of PyFilesystem's

pyFilesystem 1.8k Jan 02, 2023