Reading an image in python - experimenting with images -


i'm experimenting little bit working images in python project i'm working on.

this first time ever me programming in python , haven't found tutorial deals issues i'm facing.

i'm experimenting different image decompositions, , want define variable a set image specified folder. i'm looking python's analog of matlab's imread.

after googling bit, found many solutions none seem work me reason.

for example simple code

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

which supposed work (taken http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html) yields error "no module named cv2".

why happen? how can read image?

another thing tried

import numpy np import skimage.io io a=io.imread('c:\users\oria\desktop\test.jpg') io.imshow(a) 

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

all want able read image specified folder, shouldn't hard...should noted database work ppm files. want read , show ppm images.

edit: enviornment pyzo. if matters anything.

edit2: changing slashes forward slashes changes 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' 

the closest analogue matlab's imread scipy.misc.imread, part of scipy package. write code as:

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

now broader questions. reason seems hard because you're coming matlab, uses different philosophy. matlab monolithic install comes out of box huge number of functions. python modular. built-in library relatively small, , install packages depending on want do. instance, packages scipy (scientific computing), cv2 (computer vision), , pil (image processing) can read simple images disk, choose between them depending on else package might want use.

this provides lot more flexibility, require become comfortable installing packages. sadly more difficult on windows on linux-like systems, due lack of "package manager". on linux can sudo apt-get install scipy , install of scipy in 1 line. in windows, might better off installing conda smooths package installation process.


Comments