Reading an image in python - experimenting with images
Question: I'm experimenting a little bit working with images in Python for a project I'm
working on.

This is the first time ever for me programming in Python and I haven't found a
tutorial that deals with the issues I'm facing.

I'm experimenting with different image decompositions, and I want to define
some variable `A` as a set image from a specified folder. Basically I'm
looking for Python's analog of Matlab's `imread`.

After googling for a bit, I found many solutions but none seem to work for me
for some reason.

For example even this simple code

    
    
    import numpy as np
    import cv2
    
    # Load an color image in grayscale
    img = cv2.imread('messi5.jpg',0)
    

which is supposed to work (taken from <http://opencv-python-
tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html>)
yields the error "No module named cv2".

Why does this happen? How can I read an image?

Another thing I tried is

    
    
    import numpy as np
    import skimage.io as io
    A=io.imread('C:\Users\Oria\Desktop\test.jpg')
    io.imshow(A)
    

which yields the error "SyntaxError: (unicode error) 'unicodeescape' codec
can't decode bytes in position 2-3: truncated \UXXXXXXXX escape"

All I want to do is be able to read an image from a specified folder,
shouldn't be hard...Should also be noted that the database I work with is ppm
files. So I want to read and show ppm images.

Edit: My enviornment is Pyzo. If it matters for anything.

Edit2: Changing the back slashes into forward slashes changes the error to

    
    
    Traceback (most recent call last):
      File "<tmp 1>", line 3, in <module>
        A=io.imread('C:/Users/Oria/Desktop/test.jpg')
      File "F:\pyzo2015a\lib\site-packages\skimage\io\_io.py", line 97, in imread
        img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
      File "F:\pyzo2015a\lib\site-packages\skimage\io\manage_plugins.py", line 209, in call_plugin
        return func(*args, **kwargs)
      File "F:\pyzo2015a\lib\site-packages\matplotlib\pyplot.py", line 2215, in imread
        return _imread(*args, **kwargs)
      File "F:\pyzo2015a\lib\site-packages\matplotlib\image.py", line 1258, in imread
        'more images' % list(six.iterkeys(handlers.keys)))
      File "F:\pyzo2015a\lib\site-packages\six.py", line 552, in iterkeys
        return iter(d.keys(**kw))
    AttributeError: 'builtin_function_or_method' object has no attribute 'keys'
    


Answer: The closest analogue to Matlab's imread is
[scipy.misc.imread](http://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.misc.imread.html),
part of the [scipy](http://scipy.org/) package. I would write this code as:

    
    
    import scipy.misc
    image_array = scipy.misc.imread('filename.jpg')
    

Now to your broader questions. The reason this seems hard is because you're
coming from Matlab, which uses a different philosophy. Matlab is a monolithic
install that comes out of the box with a huge number of functions. Python is
modular. The built-in library is relatively small, and then you install
packages depending on what you want to do. For instance, the packages `scipy`
(scientific computing), `cv2` (computer vision), and `PIL` (image processing)
can all read simple images from disk, so you choose between them depending on
what else from the package you might want to use.

This provides a lot more flexibility, but it does require you to become
comfortable installing packages. Sadly this is much more difficult on Windows
than on Linux-like systems, due to the lack of a "package manager". On Linux I
can `sudo apt-get install scipy` and install all of scipy in one line. In
Windows, you might be better off installing something like
[conda](http://conda.pydata.org/miniconda.html) that smooths the package
installation process.

