Tentativas leitura e display de imagens usando o skimage

Usando skimage


In [1]:
%matplotlib inline
import numpy as np
import skimage.data as kdata
import skimage.io as kio

In [2]:
kio.available_plugins


Out[2]:
{'fits': ['imread', 'imread_collection'],
 'freeimage': ['imread', 'imsave', 'imread_collection'],
 'gdal': ['imread', 'imread_collection'],
 'gtk': ['imshow'],
 'imageio': ['imread', 'imsave', 'imread_collection'],
 'imread': ['imread', 'imsave', 'imread_collection'],
 'matplotlib': ['imshow', 'imread', 'imshow_collection', 'imread_collection'],
 'pil': ['imread', 'imsave', 'imread_collection'],
 'qt': ['imshow', 'imsave', 'imread', 'imread_collection'],
 'simpleitk': ['imread', 'imsave', 'imread_collection'],
 'test': ['imsave',
  'imshow',
  'imread',
  'imread_collection',
  'imshow_collection'],
 'tifffile': ['imread', 'imsave', 'imread_collection']}

In [3]:
f = kdata.camera()

In [4]:
kio.use_plugin('matplotlib', 'imshow')

In [5]:
f


Out[5]:
array([[156, 157, 160, ..., 152, 152, 152],
       [156, 157, 159, ..., 152, 152, 152],
       [158, 157, 156, ..., 152, 152, 152],
       ..., 
       [121, 123, 126, ..., 121, 113, 111],
       [121, 123, 126, ..., 121, 113, 111],
       [121, 123, 126, ..., 121, 113, 111]], dtype=uint8)

In [6]:
def iaimginfo(f):
    t = type(f)
    if t != np.ndarray:
        return 'Not a ndarray. It is %s' % (t,)
    else:
        dt = f.dtype
        if dt == 'bool':
            return '%s %s %s %s %s' % (t, np.shape(f), f.dtype, f.min(), f.max())
        elif dt == 'uint8':
            return '%s %s %s %d %d' % (t, np.shape(f), f.dtype, f.min(), f.max())
        else:
            return '%s %s %s %f %f' % (t, np.shape(f), f.dtype, f.min(), f.max())

Mostrando imagens uint8 - 0-255


In [7]:
iaimginfo(f)


Out[7]:
"<type 'numpy.ndarray'> (512, 512) uint8 0 255"

In [8]:
kio.imshow(f)


Out[8]:
<matplotlib.image.AxesImage at 0x7f5e6e59e0d0>

Imagens uint8 não existe normalização no Display


In [ ]:
f1 = f//2
print 'f1:',iaimginfo(f1)
#kio.imshow(f1)
f2 = 128+f1
print 'f2:',iaimginfo([f1,f2])
kio.imshow(f2)

In [ ]:
g = f * 1.0

In [ ]:
iaimginfo(g)

In [ ]:
kio.imshow(g)

In [ ]: