Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to locate freeimage after install of mahotas in Python

Hi I am new to Python and am following the Python Image Tutorial.

The following executes with no errors after installing the packages described in the tutorial

import numpy
import scipy
import pylab
import pymorph
import mahotas
from scipy import ndimage

However when I try reading an image

image = mahotas.imread('picture_file.jpg')

I get

image = mahotas.imread('image_file.jpg') Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/dist-packages/mahotas-0.6.4-py2.6-linux-i686.egg/mahotas/init.py", line 68, in imread raise ImportError('mahotas.imread dependends on freeimage. Could not find it. Error was: %s' % e) ImportError: mahotas.imread dependends on freeimage. Could not find it. Error was: mahotas.freeimage: could not find libFreeImage in any of the following directories: '/usr/local/lib/python2.6/dist-packages/mahotas-0.6.4-py2.6-linux-i686.egg/mahotas', '/lib', '/usr/lib', '/usr/local/lib', '/opt/local/lib'

I tried installing FreeImagePy and can import it with no problems but it does not help. I have tried adding to the Python path using package sys but not help either.

EDIT: I should have mentioned that all the packages except pymorph and mahotas was installed on my linux box doing '*sudo apt-get install package_name*' while pymorph and mahotas was installed by downloading and doing 'sudo python setup.py install'.

like image 309
Michael Avatar asked Nov 06 '22 00:11

Michael


1 Answers

Answer for more recent versions of mahotas

Mahotas itself does not have the functionality to read in images. imread is just a wrapper around one of 3 backends:

  1. mahotas-imread (i.e., https://pypi.python.org/pypi/imread)
  2. FreeImage
  3. matplotlib (which only supports PNG & JPEG)

Thus, you need to install one of the packages above. Freeimage can be installed on Ubuntu as described below.

If you are running on Windows, you may wish to try Christoph Gohlke’s packages.

Original answer (for older versions of mahotas)

You need to install freeimage to be able to use mahotas.imread (everything else will actually work without it, it's an optional dependency). This is not a Python package per se, just a regular library.

I don't know what distribution you are in, but try looking for a freeimage package. On debian/ubuntu, you can just do:

sudo apt-get install libfreeimage3

You will have a file libfreeimage.so in /usr/lib or in a similar place and everything will work.

like image 57
luispedro Avatar answered Nov 10 '22 05:11

luispedro