Giter VIP home page Giter VIP logo

imread's Introduction

mahotas-imread: Read Image Files

image image image Test mahotas-imread

IO with images and numpy arrays.

Mahotas-imread is a simple module with a small number of functions:

  • imread: Reads an image file
  • imread_multi: Reads an image file with multiple images. Currently, TIFF and STK (a TIFF sub-based format) support this function.
  • imsave: Writes an image file

Example (which uses mahotas for Gaussian filtering):

from imread import imread, imsave
from mahotas import gaussian_filter
lena = imread('lena.jpeg')

lena = gaussian_filter(lena.astype(float), 4.)
imsave('lena-filtered.jpeg', lena)

This grew out of frustration at current image loading solutions in Python, in either my packages [mahotas] or packages from others [scikit-image, for example].

The relationship with numpy is very contained and this could be easily repurposed to load images in other frameworks, even other programming languages.

Online documentation

Python versions 2.6, 2.7, 3.3+ are officially supported.

Python 3.2 (and earlier versions in the Python 3 series) are officially not supported. Patches will be accepted if they do not mess up anything else, but bug reports will not be considered as very high priority.

Citation

::: {#Citation} If you use imread on a published publication, please cite the main mahotas paper (imread is a spin-off of mahotas): :::

Luis Pedro Coelho Mahotas: Open source software for scriptable computer vision in Journal of Open Research Software, vol 1, 2013. [DOI]

In Bibtex format:

@article{mahotas,
    author = {Luis Pedro Coelho},
    title = {Mahotas: Open source software for scriptable computer vision},
    journal = {Journal of Open Research Software},
    year = {2013},
    doi = {https://dx.doi.org/10.5334/jors.ac},
    month = {July},
    volume = {1}
}

Installation/Dependencies

The easiest environment to install mahotas-imread is anaconda, through conda-forge. Just use:

conda config --add channels conda-forge
conda install imread

To compile on debian/ubuntu:

sudo apt-get install libpng12-dev libtiff4-dev libwebp-dev
sudo apt-get install xcftools

To compile on Mac:

sudo port install libpng tiff webp

Either way, you can then compile with:

python setup.py build

and install with:

python setup.py install

On Windows, you can also just download a pre-built package from C. Gohlke's repository

On nix, you can use:

nix-env -iA nixpkgs.python3Packages.imread

or use the pkgs.python3Packages.imread object in your *.nix files.

Links & Contacts

History

Version 0.7.5 (2023-11-22)

  • Fix build issue (#43, patch by @carlosal1015)

Version 0.7.4 (2020-04-14)

  • Add missing header files to distribution

Version 0.7.3 (2020-04-09)

  • Add missing test data to distribution

Version 0.7.2 (2020-03-24)

  • Fix several memory access bugs in parsers (reported by Robert Scott)

Version 0.7.1 (2019-05-09)

  • Fix 16-bit RGB/RGBA TIFF write (patch by Tomi Aarnio)

Version 0.7.0 (2018-09-30)

  • Add support for reading ImageJ ROIs

Version 0.6.1 (2018-02-15)

  • Support pathlib paths as function arguments
  • Fix 16 bit PNG write support (patch by Tomi Aarnio)

Version 0.6 (2016-09-21)

  • Add [supports_format]{.title-ref} function
  • Make png compression level tunable when calling imsave
  • Add imsave_multi
  • Add partial support for reading PNG files in Gray+alpha format

Version 0.5.1 (2014-11-06)

  • Improve tests to work after installation
  • Fix compilation in MSVC (patch by Christoph Gohlke)

Version 0.5 (2014-10-16)

  • Add magic-number based format auto-detection
  • Auto detect whether webp is installed
  • Fix WebP reading (update to newer API)

Version 0.4 (2014-07-21)

  • Add configuration for TIFF saving
  • Correctly save 16 bit PNG images
  • Better error messages for JPEG

Version 0.3.2 (2013-10-06)

  • Added imload*/imwrite synonyms as suggested by Thouis (Ray) Jones
  • Options framework
  • Allow user to specify JPEG quality when saving
  • Fix loading of 16 bit PNG images

Version 0.3.1 (2013-06-20)

  • Fix possible crash on error with TIFF
  • Fix compilation on Windows (reported by Volker Hilsenstein)
  • Make it easy to compile without WebP

Version 0.3.0 (2013-07-29)

  • Support for reading from in-memory blobs
  • Support for reading & writing TIFF metadata
  • Add PHOTOMETRIC tag to TIFF (reported by Volker Hilsenstein)
  • Support writing RGB TIFFs

Version 0.2.6 (2013-06-19)

  • Fix hard crash when saving with non-existing file type
  • Fix compilation on MacOS (patch by Alexander Bohn)
  • Add verbose argument to tests.run()
  • Better error when attempting to save floating point images

Version 0.2.5 (2012-10-29)

  • Correctly accept uppercase extensions
  • Python 3 support (patch by Christoph Gohlke [pull request 8 on github])
  • Read 1-Bit PNGs
  • Read simple BMPs (compression and many bit types not supported)
  • More complete debug mode (export DEBUG=2 when building), more checks

Version 0.2.4 (2012-06-26)

  • Add lzw.cpp to source distribution
  • Support saving 16-bit TIFF
  • Better Mac OS support (patch from Alexander Bohn)

Version 0.2.3 (2012-06-8)

  • Fix imread_multi

Version 0.2.2 (2012-06-5)

  • Add [formatstr]{.title-ref} argument to imread
  • Open files in binary mode on Windows (patch by Christoph Gohlke)
  • Read-only support for LSM files
  • Read-only support for XCF files (through [xcf2png]{.title-ref})
  • Fix writing of non-contiguous images (at least PNG was affected)

Version 0.2.1 (2012-02-11)

  • Add missing files to distribution

Version 0.2 (2012-03-19)

  • Compile on MSVC++ (Patches by Christoph Gohlke)
  • Support for WebP
  • Support for 1-bit TIFFs
  • Better error message
  • Support for multi-page TIFF reading
  • Experimental read-only support for STK files

Version 0.1 (2012-02-28)

  • Support for PNG
  • Support for TIFF
  • Support for JPEG

imread's People

Contributors

carlosal1015 avatar cdeil avatar cgohlke avatar epicwink avatar ericbuehl avatar fish2000 avatar luispedro avatar pgajdos avatar thouis avatar toaarnio avatar wtollett-usgs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imread's Issues

Installation failed before installing numpy

Downloading imread-0.6.tar.gz (116kB)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/tmp/pip-build-z49ubwd6/imread/setup.py", line 19, in <module>
import numpy as np
ImportError: No module named 'numpy'

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-z49ubwd6/imread
You are using pip version 7.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
error: build error: non-zero (13) exit code from registry.access.redhat.com/rhscl/python-35-rhel7@sha256:ba3115fddc7aece697d11dabfa6463c337725e00e088fe9cc4f51f8f2a1f801b

Problems installing imread on Mac OS X with Enthought - possibly 64 bit / 32 bit issue

I wrote some scripts using imread on a windows machine using Chris Gohlke's pre-compiled binary version.
Now I'm developing on a Mac and I have trouble installing imread. I am using the Enthought python distribution in the 32 bit version on a 64 bit machine, this is recommended by Enthought due to some issues with the 64 bit version.
I believe my problems might be a 64/32 bit issue but I'm not sure ... might be something else entirely.

mac-book:~ volkerh$ uname -a
Darwin mac-book.XXXXXX 2.1.0 Darwin Kernel Version 12.1.0: Tue Aug 14 13:29:55 PDT 2012; root:xnu-2050.9.2~1/RELEASE_X86_64 x86_64

mac-book:~ volkerh$ python --version
Python 2.7.3 -- EPD 7.3-2 (32-bit)

mac-book:imread volkerh$ sudo python setup.py install --record files.txt
running install
running bdist_egg
running egg_info
running build_src
build_src
building extension "imread._imread" sources
build_src: building npy-pkg config files
writing imread.egg-info/PKG-INFO
writing top-level names to imread.egg-info/top_level.txt
writing dependency_links to imread.egg-info/dependency_links.txt
reading manifest file 'imread.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'imread.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.5-i386/egg
running install_lib
running build_py
creating build
creating build/lib.macosx-10.5-i386-2.7
creating build/lib.macosx-10.5-i386-2.7/imread
copying imread/init.py -> build/lib.macosx-10.5-i386-2.7/imread
copying imread/imread.py -> build/lib.macosx-10.5-i386-2.7/imread
copying imread/imread_version.py -> build/lib.macosx-10.5-i386-2.7/imread
copying imread/special.py -> build/lib.macosx-10.5-i386-2.7/imread
creating build/lib.macosx-10.5-i386-2.7/imread/tests
copying imread/tests/init.py -> build/lib.macosx-10.5-i386-2.7/imread/tests
copying imread/tests/test_error.py -> build/lib.macosx-10.5-i386-2.7/imread/tests
copying imread/tests/test_imread.py -> build/lib.macosx-10.5-i386-2.7/imread/tests
copying imread/tests/test_jpeg.py -> build/lib.macosx-10.5-i386-2.7/imread/tests
copying imread/tests/test_png.py -> build/lib.macosx-10.5-i386-2.7/imread/tests
copying imread/tests/test_tiff.py -> build/lib.macosx-10.5-i386-2.7/imread/tests
copying imread/tests/test_webp.py -> build/lib.macosx-10.5-i386-2.7/imread/tests
copying imread/tests/test_xcf.py -> build/lib.macosx-10.5-i386-2.7/imread/tests
creating build/lib.macosx-10.5-i386-2.7/imread/tests/data
copying imread/tests/data/diag.xcf -> build/lib.macosx-10.5-i386-2.7/imread/tests/data
copying imread/tests/data/error.jpg -> build/lib.macosx-10.5-i386-2.7/imread/tests/data
copying imread/tests/data/error.png -> build/lib.macosx-10.5-i386-2.7/imread/tests/data
copying imread/tests/data/error.tif -> build/lib.macosx-10.5-i386-2.7/imread/tests/data
copying imread/tests/data/error.unknown -> build/lib.macosx-10.5-i386-2.7/imread/tests/data
copying imread/tests/data/error.webp -> build/lib.macosx-10.5-i386-2.7/imread/tests/data
copying imread/tests/data/good -> build/lib.macosx-10.5-i386-2.7/imread/tests/data
copying imread/tests/data/good.png -> build/lib.macosx-10.5-i386-2.7/imread/tests/data
copying imread/tests/data/mono.tif -> build/lib.macosx-10.5-i386-2.7/imread/tests/data
copying imread/tests/data/palette_zero.png -> build/lib.macosx-10.5-i386-2.7/imread/tests/data
copying imread/tests/data/stack.tiff -> build/lib.macosx-10.5-i386-2.7/imread/tests/data
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
building 'imread._imread' extension
compiling C++ sources
C compiler: g++ -fno-strict-aliasing -fno-common -dynamic -arch i386 -DNDEBUG -g -O3 -arch i386

creating build/temp.macosx-10.5-i386-2.7
creating build/temp.macosx-10.5-i386-2.7/imread
creating build/temp.macosx-10.5-i386-2.7/imread/lib
compile options: '-I/usr/local/include -I/usr/X11/include -I/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/numpy/core/include -I/Library/Frameworks/Python.framework/Versions/7.3/include/python2.7 -c'
g++: imread/lib/_png.cpp
g++: imread/lib/_lsm.cpp
g++: imread/lib/formats.cpp
g++: imread/lib/numpy.cpp
g++: imread/lib/_tiff.cpp
g++: imread/lib/_webp.cpp
g++: imread/_imread.cpp
g++: imread/lib/_jpeg.cpp
g++ -bundle -undefined dynamic_lookup -g -arch i386 build/temp.macosx-10.5-i386-2.7/imread/_imread.o build/temp.macosx-10.5-i386-2.7/imread/lib/formats.o build/temp.macosx-10.5-i386-2.7/imread/lib/numpy.o build/temp.macosx-10.5-i386-2.7/imread/lib/_jpeg.o build/temp.macosx-10.5-i386-2.7/imread/lib/_lsm.o build/temp.macosx-10.5-i386-2.7/imread/lib/_png.o build/temp.macosx-10.5-i386-2.7/imread/lib/_tiff.o build/temp.macosx-10.5-i386-2.7/imread/lib/_webp.o -L/usr/local/lib -L/usr/X11/lib -lpng -ljpeg -ltiff -lwebp -lzlib -o build/lib.macosx-10.5-i386-2.7/imread/_imread.so
ld: warning: ld: warning: ld: warning: ld: warning: ignoring file /usr/local/lib/libpng.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (i386): /usr/local/lib/libpng.dylibignoring file /usr/local/lib/libtiff.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (i386): /usr/local/lib/libtiff.dylibignoring file /usr/local/lib/libzlib.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/libzlib.aignoring file /usr/local/lib/libwebp.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (i386): /usr/local/lib/libwebp.dylib

running scons
creating build/bdist.macosx-10.5-i386
creating build/bdist.macosx-10.5-i386/egg
creating build/bdist.macosx-10.5-i386/egg/imread
copying build/lib.macosx-10.5-i386-2.7/imread/init.py -> build/bdist.macosx-10.5-i386/egg/imread
copying build/lib.macosx-10.5-i386-2.7/imread/_imread.so -> build/bdist.macosx-10.5-i386/egg/imread
copying build/lib.macosx-10.5-i386-2.7/imread/imread.py -> build/bdist.macosx-10.5-i386/egg/imread
copying build/lib.macosx-10.5-i386-2.7/imread/imread_version.py -> build/bdist.macosx-10.5-i386/egg/imread
copying build/lib.macosx-10.5-i386-2.7/imread/special.py -> build/bdist.macosx-10.5-i386/egg/imread
creating build/bdist.macosx-10.5-i386/egg/imread/tests
copying build/lib.macosx-10.5-i386-2.7/imread/tests/init.py -> build/bdist.macosx-10.5-i386/egg/imread/tests
creating build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/data/diag.xcf -> build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/data/error.jpg -> build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/data/error.png -> build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/data/error.tif -> build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/data/error.unknown -> build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/data/error.webp -> build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/data/good -> build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/data/good.png -> build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/data/mono.tif -> build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/data/palette_zero.png -> build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/data/stack.tiff -> build/bdist.macosx-10.5-i386/egg/imread/tests/data
copying build/lib.macosx-10.5-i386-2.7/imread/tests/test_error.py -> build/bdist.macosx-10.5-i386/egg/imread/tests
copying build/lib.macosx-10.5-i386-2.7/imread/tests/test_imread.py -> build/bdist.macosx-10.5-i386/egg/imread/tests
copying build/lib.macosx-10.5-i386-2.7/imread/tests/test_jpeg.py -> build/bdist.macosx-10.5-i386/egg/imread/tests
copying build/lib.macosx-10.5-i386-2.7/imread/tests/test_png.py -> build/bdist.macosx-10.5-i386/egg/imread/tests
copying build/lib.macosx-10.5-i386-2.7/imread/tests/test_tiff.py -> build/bdist.macosx-10.5-i386/egg/imread/tests
copying build/lib.macosx-10.5-i386-2.7/imread/tests/test_webp.py -> build/bdist.macosx-10.5-i386/egg/imread/tests
copying build/lib.macosx-10.5-i386-2.7/imread/tests/test_xcf.py -> build/bdist.macosx-10.5-i386/egg/imread/tests
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/init.py to init.pyc
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/imread.py to imread.pyc
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/imread_version.py to imread_version.pyc
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/special.py to special.pyc
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/tests/init.py to init.pyc
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/tests/test_error.py to test_error.pyc
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/tests/test_imread.py to test_imread.pyc
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/tests/test_jpeg.py to test_jpeg.pyc
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/tests/test_png.py to test_png.pyc
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/tests/test_tiff.py to test_tiff.pyc
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/tests/test_webp.py to test_webp.pyc
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/tests/test_xcf.py to test_xcf.pyc
creating stub loader for imread/_imread.so
byte-compiling build/bdist.macosx-10.5-i386/egg/imread/_imread.py to _imread.pyc
creating build/bdist.macosx-10.5-i386/egg/EGG-INFO
copying imread.egg-info/PKG-INFO -> build/bdist.macosx-10.5-i386/egg/EGG-INFO
copying imread.egg-info/SOURCES.txt -> build/bdist.macosx-10.5-i386/egg/EGG-INFO
copying imread.egg-info/dependency_links.txt -> build/bdist.macosx-10.5-i386/egg/EGG-INFO
copying imread.egg-info/top_level.txt -> build/bdist.macosx-10.5-i386/egg/EGG-INFO
writing build/bdist.macosx-10.5-i386/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating 'dist/imread-0.2.4_git-py2.7-macosx-10.5-i386.egg' and adding 'build/bdist.macosx-10.5-i386/egg' to it
removing 'build/bdist.macosx-10.5-i386/egg' (and everything under it)
Processing imread-0.2.4_git-py2.7-macosx-10.5-i386.egg
removing '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/imread-0.2.4_git-py2.7-macosx-10.5-i386.egg' (and everything under it)
creating /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/imread-0.2.4_git-py2.7-macosx-10.5-i386.egg
Extracting imread-0.2.4_git-py2.7-macosx-10.5-i386.egg to /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages
imread 0.2.4-git is already the active version in easy-install.pth

Installed /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/imread-0.2.4_git-py2.7-macosx-10.5-i386.egg
Processing dependencies for imread==0.2.4-git
Finished processing dependencies for imread==0.2.4-git
writing list of installed files to 'files.txt'
mac-book:imread volkerh$ python
Enthought Python Distribution -- www.enthought.com
Version: 7.3-2 (32-bit)

Python 2.7.3 |EPD 7.3-2 (32-bit)| (default, Apr 12 2012, 11:28:34)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "credits", "demo" or "enthought" for more information.

import imread
Traceback (most recent call last):
File "", line 1, in
File "imread/init.py", line 7, in
from .imread import imread, imsave, imread_multi
File "imread/imread.py", line 9, in
from . import _imread
ImportError: cannot import name _imread

Issue installing on Mac OS X

Hi there,

I had an issue installing on Mac OS X 10.7.5 - the install linked with -lzlib, but it wasn't found. I solved it by symlinking the existing libz.dylib into the new name:

ln -s /usr/lib/libz.dylib /usr/local/lib/libzlib.dylib

I'm not sure if this is something that you would want to fix, but that's the fix that worked for me.

Write to buffer or return bytes

This is more a question or feature request / idea rather than an issue.

If I am not mistaken it's currently not possible to write to a buffer or return the written bytes somehow right? What do you think about expanding the interface to support something like:

buf = BytesIO()
imsave(buf, my_fancy_array, formatstr='png')

If this is out of scope never mind. I am just curious.

wheels?

I noticed that #23 discussed uploading wheels.

Has that effort been stalled?I ask because imread is being used by scikit-image to test the imread backend. Installing imread from source sometimes breaks the build system.

We also had to create a special case for it since it did not have "wheels" so we couldn't recommend our users install it by default as a general "optional dependency".

Here is an example of a troublesome build
https://travis-ci.org/scikit-image/scikit-image/jobs/530681267

Does not build using python3.4

I'm trying to build the imread module using python3.4. I was able to build it using python2 (submitted to the Arch User repository here https://aur.archlinux.org/packages/python2-imread/). However using 3.4 I get the following errors:


building 'imread._imread' extension
compiling C++ sources
C compiler: g++ -pthread -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -g -fwrapv -O3 -Wall -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -fPIC

compile options: '-DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -DPY_ARRAY_UNIQUE_SYMBOL=MahotasImread_PyArray_API_Symbol -I/usr/local/include -I/usr/lib/python3.4/site-packages/numpy/core/include -I/usr/include/python3.4m -c'
g++: imread/_imread.cpp
In file included from /usr/include/python3.4m/pyatomic.h:8:0,
from /usr/include/python3.4m/Python.h:53,
from imread/lib/numpy.h:11,
from imread/_imread.cpp:23:
/usr/include/python3.4m/dynamic_annotations.h:472:3: error: template with C linkage
template
^
In file included from /usr/include/python3.4m/pyatomic.h:8:0,
from /usr/include/python3.4m/Python.h:53,
from imread/lib/numpy.h:11,
from imread/_imread.cpp:23:
/usr/include/python3.4m/dynamic_annotations.h:472:3: error: template with C linkage
template
^

error: Command "g++ -pthread -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -g -fwrapv -O3 -Wall -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -fPIC -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -DPY_ARRAY_UNIQUE_SYMBOL=MahotasImread_PyArray_API_Symbol -I/usr/local/include -I/usr/lib/python3.4/site-packages/numpy/core/include -I/usr/include/python3.4m -c imread/_imread.cpp -o build/temp.linux-x86_64-3.4/imread/_imread.o" failed with exit status 1

Any idea where the error may come from? I hope this helps.

AttributeError: 'dict' object has no attribute '__NUMPY_SETUP__'

Hi, when I run these commands

$ curl -LO https://github.com/luispedro/imread/archive/v0.7.4.tar.gz
$ tar -xvf v0.7.4.tar.gz
$ cd imread-0.7.4
$ python -m build --wheel --skip-dependency-check --no-isolation

We have the following message error

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
    main()
  File "/usr/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 335, in main
    json_out['return_val'] = hook(**hook_input['kwargs'])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
    return _build_backend().build_wheel(wheel_directory, config_settings,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/setuptools/build_meta.py", line 416, in build_wheel
    return self._build_with_temp_dir(['bdist_wheel'], '.whl',
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/setuptools/build_meta.py", line 401, in _build_with_temp_dir
    self.run_setup()
  File "/usr/lib/python3.11/site-packages/setuptools/build_meta.py", line 488, in run_setup
    self).run_setup(setup_script=setup_script)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/setuptools/build_meta.py", line 338, in run_setup
    exec(code, locals())
  File "<string>", line 138, in <module>
  File "/usr/lib/python3.11/site-packages/setuptools/__init__.py", line 107, in setup
    return distutils.core.setup(**attrs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 185, in setup
    return run_commands(dist)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
    dist.run_commands()
  File "/usr/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.11/site-packages/setuptools/dist.py", line 1234, in run_command
    super().run_command(command)
  File "/usr/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.11/site-packages/wheel/bdist_wheel.py", line 343, in run
    self.run_command("build")
  File "/usr/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.11/site-packages/setuptools/dist.py", line 1234, in run_command
    super().run_command(command)
  File "/usr/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.11/site-packages/setuptools/_distutils/command/build.py", line 131, in run
    self.run_command(cmd_name)
  File "/usr/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.11/site-packages/setuptools/dist.py", line 1234, in run_command
    super().run_command(command)
  File "/usr/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 987, in run_command
    cmd_obj.ensure_finalized()
  File "/usr/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 111, in ensure_finalized
    self.finalize_options()
  File "<string>", line 27, in finalize_options
AttributeError: 'dict' object has no attribute '__NUMPY_SETUP__'

ERROR Backend subprocess exited when trying to invoke build_wheel

Badly readed gray image

Hi, I wanted to read an 8bit png image with imread() function. But the loaded image has incorrectly 3 channels and also strange values in them. I'm using the package downloaded from http://www.lfd.uci.edu/~gohlke/pythonlibs/ (version for python 3.3 32bit).
Could you please look at it and tell me if this is a bug or mistake at my side? Thanks.

Test errors on Windows

I am building imread from git master with msvc9 on win32-py2.7, linking statically against tiff-3.9.6, libpng-1.5.10, jpeg-8d, libwebp-0.1.3, and zlib-1.2.6. The link libraries all test OK. There are no warnings during build. Running setup.py test results in the following errors:

<snip>
imread.tests.test_error.test_error ... ok
imread.tests.test_imread.test_with_dot ... ERROR
imread.tests.test_imread.test_no_ext ... ok
imread.tests.test_imread.test_formatstr ... ERROR
imread.tests.test_jpeg.test_jpeg ... Corrupt JPEG data: 53 extraneous bytes before marker 0xc0
ok
imread.tests.test_jpeg.test_error ... ok
imread.tests.test_png.test_png_raw ... ERROR
imread.tests.test_png.test_asym ... ERROR
imread.tests.test_png.test_error ... ok
imread.tests.test_png.test_regression ... ERROR
imread.tests.test_tiff.test_read_back ... ERROR
imread.tests.test_tiff.test_error ... ok
imread.tests.test_tiff.test_monochrome ... ERROR
imread.tests.test_webp.test_error ... ok
imread.tests.test_xcf.test_xcf ... The process cannot access the file because it is being used by another process.
ERROR

======================================================================
ERROR: imread.tests.test_imread.test_with_dot
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "imread-git\imread\tests\test_imread.py", line 7, in test_with_dot
    f = imread('./imread/tests/data/good.png')
  File "imread-git\imread\imread.py", line 45, in imread
    im = reader(filename, formatstr)
RuntimeError: Read Error

======================================================================
ERROR: imread.tests.test_imread.test_formatstr
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "imread-git\imread\tests\test_imread.py", line 16, in test_formatstr
    f = imread('./imread/tests/data/good', formatstr='png')
  File "imread-git\imread\imread.py", line 45, in imread
    im = reader(filename, formatstr)
RuntimeError: Not a PNG file

======================================================================
ERROR: imread.tests.test_png.test_png_raw
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "imread-git\imread\tests\test_png.py", line 21, in test_png_raw
    back = imread(_filename)
  File "imread-git\imread\imread.py", line 45, in imread
    im = reader(filename, formatstr)
RuntimeError: Read Error

======================================================================
ERROR: imread.tests.test_png.test_asym
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "imread-git\imread\tests\test_png.py", line 29, in test_asym
    back = imread(_filename)
  File "imread-git\imread\imread.py", line 45, in imread
    im = reader(filename, formatstr)
RuntimeError: Read Error

======================================================================
ERROR: imread.tests.test_png.test_regression
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "imread-git\imread\tests\test_png.py", line 38, in test_regression
    im = imread('imread/tests/data/palette_zero.png')
  File "imread-git\imread\imread.py", line 45, in imread
    im = reader(filename, formatstr)
RuntimeError: Read Error

======================================================================
ERROR: imread.tests.test_tiff.test_read_back
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "imread-git\imread\tests\test_tiff.py", line 20, in test_read_back
    back = imread(_filename)
  File "imread-git\imread\imread.py", line 45, in imread
    im = reader(filename, formatstr)
RuntimeError: imread.imread._tiff: libtiff error: `internal: Read error at scanline 4294967295; got 16 bytes, expected 291`

======================================================================
ERROR: imread.tests.test_tiff.test_monochrome
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "imread-git\imread\tests\test_tiff.py", line 28, in test_monochrome
    mono = imread('imread/tests/data/mono.tif')
  File "imread-git\imread\imread.py", line 45, in imread
    im = reader(filename, formatstr)
RuntimeError: imread.imread._tiff: libtiff error: `internal: Can not read TIFF directory`

======================================================================
ERROR: imread.tests.test_xcf.test_xcf
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "imread-git\imread\tests\test_xcf.py", line 4, in test_xcf
    im = imread('imread/tests/data/diag.xcf')
  File "imread-git\imread\imread.py", line 45, in imread
    im = reader(filename, formatstr)
  File "imread-git\imread\special.py", line 36, in readxcf
    return imread.imread(N.name)
  File "imread-git\imread\imread.py", line 45, in imread
    im = reader(filename, formatstr)
OSError: File does not exist

----------------------------------------------------------------------
Ran 15 tests in 0.065s

FAILED (errors=8)
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "X:\Python27\lib\atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "X:\Python27\lib\multiprocessing\util.py", line 284, in _exit_function
    info('process shutting down')
TypeError: 'NoneType' object is not callable
Error in sys.exitfunc:
Traceback (most recent call last):
  File "X:\Python27\lib\atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "X:\Python27\lib\multiprocessing\util.py", line 284, in _exit_function
    info('process shutting down')
TypeError: 'NoneType' object is not callable

Wheel building repository

Hi,

I just made a repository that will build Linux and OSX wheels for imread, here:

https://github.com/MacPython/imread-wheels

travis-ci builds the wheels:

https://travis-ci.org/MacPython/imread-wheels

and uploads them to:

https://3f23b170c54c2533c070-1c8a9b3114517dc5fe17b7c3f8c63a43.ssl.cf2.rackcdn.com

I've given @luispedro admin permission to the wheel building repo. The README at the top level of the repository should be self-explanatory.

Would you consider uploading the built wheels to pypi? I'm happy to do that if you like, I do that for quite a few other projects (numpy, scipy, matplotlib and so on).

Thanks for imread.

PNG reads in inverted

This image (which I hope uploads without change, MD5 = b655482e6c500210caca8950d6ce4bd9) loads in imread 0.3.1incorrectly. It looks right if I xor it with 255, but I don't think that's all that's wrong.

04_labeled

imread_multi() returns 1 image of 3997

I'm unsure what's wrong with this image, but imread.imread_multi() only returns one image. (As do several other python tiff wrappers).

https://drive.google.com/file/d/0Bx-14WwcXFgebmlLUGYwV1ZUc0E/view?usp=sharing

Sorry for the large size; I couldn't create a smaller test case.

tiffinfo reports:
TIFF Directory at offset 0x8 (8)
Subfile Type: (0 = 0x0)
Image Width: 1024 Image Length: 544
Resolution: 0.307669, 0.307669 (unitless)
Bits/Sample: 16
Compression Scheme: None
Photometric Interpretation: min-is-black
Samples/Pixel: 1
Rows/Strip: 544
Planar Configuration: single image plane
ImageDescription: ImageJ=1.47u
images=3997
frames=3997
unit=micron
finterval=0.10010010004043579
loop=false
min=1037.0
max=2281.0

Msvc9 build errors

Hi Luis,

thank you for creating this project! It will be very useful also for a number of other packages.

I get the following compile errors with Visual Studio 2008:

_imread.cpp
X:\imread-git\imread\lib/file.h(17) : error C2039: 'close' : is not a member of '`global namespace''
X:\imread-git\imread\lib/file.h(17) : error C3861: 'close': identifier not found
X:\imread-git\imread\lib/file.h(20) : error C2039: 'read' : is not a member of '`global namespace''
X:\imread-git\imread\lib/file.h(20) : error C2660: 'fd_source_sink::read' : function does not take 3 arguments
X:\imread-git\imread\lib/file.h(23) : error C2039: 'lseek' : is not a member of '`global namespace''
X:\imread-git\imread\lib/file.h(23) : error C3861: 'lseek': identifier not found
X:\imread-git\imread\lib/file.h(24) : error C2039: 'lseek' : is not a member of '`global namespace''
X:\imread-git\imread\lib/file.h(24) : error C3861: 'lseek': identifier not found
X:\imread-git\imread\lib/file.h(25) : error C2039: 'lseek' : is not a member of '`global namespace''
X:\imread-git\imread\lib/file.h(25) : error C3861: 'lseek': identifier not found
X:\imread-git\imread\lib/file.h(29) : error C2039: 'write' : is not a member of '`global namespace''
X:\imread-git\imread\lib/file.h(29) : error C2660: 'fd_source_sink::write' : function does not take 3 arguments
X:\imread-git\imread\lib/numpy.h(71) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
error: Command "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG  -IX:\Python27\lib\site-packages\numpy\core\include -IX:\Python27\include -IX:\Python27\PC /Tpimread/_imread.cpp /Fobuild\
temp.win32-2.7\Release\imread/_imread.obj /Zm1000" failed with exit status 2

imsave does not work with 16-bit PNGs

First of all I want to thank you for developing the library, and especially the 16-bit PNG support. I think I've found a bug in it, though: It seems that saving 16-bit RGB data does not work properly. Only the first 5 columns in the generated file have the expected values, others contain some garbage. Note that 8-bit read/write and 16-bit read are working fine.

I'm running imread version 0.6 on 64-bit Ubuntu 14.04, tested on both Python 2.7.6 and 3.4.3.

Compilation on Mojave / Xcode 10

When attempting to install imread on a fresh Mojave install (Xcode 10.1), I see the following:

warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead
[-Wstdlibcxx-not-found]
imread/_imread.cpp:17:10: fatal error: 'sstream' file not found

This seems to be related to Apple deprecating stdlibc++ support as of 10.9/whichever xcode version that was, but officially ending the support with the latest release. I just submitted a pull request (#30), which allows compilation to go forward.

imread_multi

Hi Pedro,

We would like to use mahotas 1.4.5 to read multi-page tiff files, but we could not find the
mahotas.imread_multi function....

Could you help us?

Consider adding imwrite/imload

My impression has been that the usual pairings of verbs are read/write and load/save. I always have to stop and think about which pair imread uses, because it doesn't use either of these.

Would you consider adding imwrite and imload as aliases for the other two?

Known vulnerabilities in C libraries which imread depends on.Can you help upgrade to patch versions?

Hi, @luispedro, @cgohlke , I'd like to report a vulnerability issue in imread_0.7.4.

Dependency Graph between Python and Shared Libraries

image

Issue Description

As shown in the above dependency graph (Here shows part of the dependency graph, which depends on vulnerable shared libraries), imread_0.7.4 directly or transitively depends on 5 C libraries (.so). However, I noticed that some C libraries are vulnerable, containing the following CVEs:
libpng12-640ca796.so.0.49.0from C project libpng(version:<=1.2.54) exposed 10 vulnerabilities:
CVE-2011-3045, CVE-2014-9495, CVE-2013-7354, CVE-2013-7353, CVE-2017-12652, CVE-2015-8472, CVE-2016-10087, CVE-2016-3751, CVE-2015-0973, CVE-2015-8540
libwebp-9d84cf2c.so.5.0.3from C project libwebp(version:<=0.4.4) exposed 11 vulnerabilities:
CVE-2018-25009, CVE-2018-25014, CVE-2018-25013, CVE-2018-25012, CVE-2018-25011, CVE-2018-25010, CVE-2020-36331, CVE-2020-36330, CVE-2020-36328, CVE-2020-36329, CVE-2020-36332

Furthermore, the vulnerable methods in these vulnerable shared libraries can be actually invoked by Python code.
For instance, the following call chain starting from png_read_info() can reach the vulnerable method static png_size_t png_inflate(png_structp png_ptr, const png_byte *data, png_size_t size, png_bytep output, png_size_t output_size) in pngrutil.c reported by CVE-2011-3045:

call chain -----
png_read_info() -> png_handle_iCCP() -> png_decompress_chunk() -> png_inflate() 

Suggested Vulnerability Patch Versions

libpng has fixed the vulnerabilities in versions >=1.6.32
libwebp has fixed the vulnerabilities in versions >=1.0.1

Python build tools cannot report vulnerable C libraries, which may induce potential security issues to many downstream Python projects.
As a popular python package (imread has 5,577 downloads per month), could you please upgrade the above shared libraries to their patch versions?

Thanks for your help~
Best regards,
Joe Gardner

Security Address

Hello!

I may have found a security issue in latest version of Imread. Following responsible disclosure, is there an email or other private channel where I could share the details?
Thank you

Error in greyscale conversion during imread

I'm using the macport py27 versions of imread, mahotas, and numpy. When I load image_0011.jpg from the "ant" category of the Caltech 101 dataset, I receive the error

" in ()
----> 1 image = mahotas.imread('/Users/*****/datasets/caltech101/data/ant/image_0011.jpg', as_grey=True)

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/imread/imread.pyc in imread(filename, as_grey, formatstr)
50 # these are the values that wikipedia says are typical
51 transform = np.array([ 0.30, 0.59, 0.11])
---> 52 return np.dot(im, transform)
53 return im
54

ValueError: objects are not aligned"

This particular image is already greyscale, so essentially, imread isn't checking to ensure that the image has three channels. I'm not sure if this is intended behaviour and isn't noted in the documentation, or the check wasn't implemented.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.