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
A python module to parse text files with contains secret variables.

A python module to parse text files with contains secret variables.

0 Dec 05, 2022
Nmap XML output to CSV and HTTP/HTTPS URLS.

xml-to-csv-url Convert NMAP's XML output to CSV file and print URL addresses for HTTP/HTTPS ports. NOTE: OS Version Parsing is not working properly ye

1 Dec 21, 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
A Python script to organize your files in a given directory.

File-Organizer A Python script to organize your files in a given directory. It organizes your files based on the file extension and moves them into sp

Imira Randeniya 1 Sep 11, 2022
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
This is a file deletion program that asks you for an extension of a file (.mp3, .pdf, .docx, etc.) to delete all of the files in a dir that have that extension.

FileBulk This is a file deletion program that asks you for an extension of a file (.mp3, .pdf, .docx, etc.) to delete all of the files in a dir that h

Enoc Mena 1 Jun 26, 2022
shred - A cross-platform library for securely deleting files beyond recovery.

shred Help the project financially: Donate: https://smartlegion.github.io/donate/ Yandex Money: https://yoomoney.ru/to/4100115206129186 PayPal: https:

4 Sep 04, 2021
PyDeleter - delete a specifically formatted file in a directory or delete all other files

PyDeleter If you want to delete a specifically formatted file in a directory or delete all other files, PyDeleter does it for you. How to use? 1- Down

Amirabbas Motamedi 1 Jan 30, 2022
Ini adalah program python untuk mengubah background foto dalam 1 folder, tidak perlu satu satu

Myherokuapp my web drive You can see my web drive and can request film/Application do you want in here my blog you can visit my blog RemBg ini adalah

XnuxersXploitXen 13 Dec 01, 2022
🧹 Create symlinks for .m2ts files and classify them into directories in yyyy-mm format.

🧹 Create symlinks for .m2ts files and classify them into directories in yyyy-mm format.

Nep 2 Feb 07, 2022
CleverCSV is a Python package for handling messy CSV files.

CleverCSV is a Python package for handling messy CSV files. It provides a drop-in replacement for the builtin CSV module with improved dialect detection, and comes with a handy command line applicati

The Alan Turing Institute 1k Dec 19, 2022
OnedataFS is a PyFilesystem interface to Onedata virtual file system

OnedataFS OnedataFS is a PyFilesystem interface to Onedata virtual file system. As a PyFilesystem concrete class, OnedataFS allows you to work with On

onedata 0 Jan 10, 2022
Python code snippets for extracting PDB codes from .fasta files

Python_snippets_for_bioinformatics Python code snippets for extracting PDB codes from .fasta files If you have a single .fasta file for all protein se

Sofi-Mukhtar 3 Feb 09, 2022
Python library for reading and writing tabular data via streams.

tabulator-py A library for reading and writing tabular data (csv/xls/json/etc). [Important Notice] We have released Frictionless Framework. This frame

Frictionless Data 231 Dec 09, 2022
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
The best way to convert files on your computer, be it .pdf to .png, .pdf to .docx, .png to .ico, or anything you can imagine.

The best way to convert files on your computer, be it .pdf to .png, .pdf to .docx, .png to .ico, or anything you can imagine.

JareBear 2 Nov 20, 2021
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
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
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
Pti-file-format - Reverse engineering the Polyend Tracker instrument file format

pti-file-format Reverse engineering the Polyend Tracker instrument file format.

Jaap Roes 14 Dec 30, 2022