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
ValveVMF - A python library to parse Valve's VMF files

ValveVMF ValveVMF is a Python library for parsing .vmf files for the Source Engi

pySourceSDK 2 Jan 02, 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
Simple, convenient and cross-platform file date changing library. 📝📅

Simple, convenient and cross-platform file date changing library.

kubinka0505 15 Dec 18, 2022
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
Convert All TXT Files To One File.

AllToOne Convert All TXT Files To One File. Hi 👋 , I'm Alireza A Python Developer Boy 🔭 I’m currently working on my C# projects 🌱 I’m currently Lea

4 Jun 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
A tool written in python to generate basic repo files from github

A tool written in python to generate basic repo files from github

Riley 7 Dec 02, 2021
This project is a set of programs that I use to create a README.md file.

🤖 codex-readme 📜 codex-readme What is it? This project is a set of programs that I use to create a README.md file. How does it work? It reads progra

Tom Dörr 224 Jan 07, 2023
This is a junk file creator tool which creates junk files in Internal Storage

This is a junk file creator tool which creates junk files in Internal Storage

KiLL3R_xRO 3 Jun 20, 2021
A platform independent file lock for Python

py-filelock This package contains a single module, which implements a platform independent file lock in Python, which provides a simple way of inter-p

Benedikt Schmitt 497 Jan 05, 2023
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
A simple file module for creating, editing and saving files.

A simple file module for creating, editing and saving files.

1 Nov 25, 2021
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
Simple Python File Manager

This script lets you automatically relocate files based on their extensions. Very useful from the downloads folder !

Aimé Risson 22 Dec 27, 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
Remove [x]_ from StudIP zip Archives and archive_filelist.csv completely

This tool removes the "[x]_" at the beginning of StudIP zip Archives. It also deletes the "archive_filelist.csv" file

Kelke vl 1 Jan 19, 2022
BOOTH宛先印刷用CSVから色々な便利なリストを作成してCSVで出力するプログラムです。

BOOTH注文リスト作成スクリプト このPythonスクリプトは、BOOTHの「宛名印刷用CSV」から、 未発送の注文 今月の注文 特定期間の注文 を抽出した上で、各注文を商品毎に一覧化したCSVとして出力するスクリプトです。 簡単な使い方 ダウンロード 通常は、Relaseから、booth_ord

hinananoha 1 Nov 28, 2021
A python script generate password files in plain text

KeePass (or any desktop pw manager?) Helper WARNING: This script will generate password files in plain text. ITS NOT SECURE. I needed help remembering

Eric Thomas 1 Nov 21, 2021
fast change directory with python and ruby

fcdir fast change directory with python and ruby run run python script , chose drirectoy and change your directory need you need python and ruby deskt

XCO 2 Jun 20, 2022
A tiny Configuration File Parser for Python Projects

A tiny Configuration File Parser for Python Projects. Currently working on JSON Config Files only.

Tanmoy Sen Gupta 1 Feb 12, 2022