[mmset2mat] [Up] [mmcmp] | Image file I/O |
mmreadgray
reads the image in
filename
and stores it in
y
, an uint8 gray-scale image (without colormap). If the input file is a color RGB image, it is converted to gray-scale using the equation: y = 0.2989 R + 0.587 G + 0.114 B. This functions uses de PIL module.
>>> a=mmreadgray('cookies.tif')
>>> mmshow(a)
![]() |
|
a |
def mmreadgray(filename): import adpil import Numeric y = adpil.adread(filename) if (len(y.shape) == 3) and (y.shape[0] == 3): if Numeric.alltrue(Numeric.alltrue(y[0,:,:] == y[1,:,:] and y[0,:,:] == y[2,:,:])): y = y[0,:,:] else: print 'Warning: converting true-color RGB image to gray' y = mmubyte(0.2989 * y[0,:,:] + 0.5870 * y[1,:,:] + 0.1140 * y[2,:,:]) elif (len(y.shape) == 2): pass else: raise ValueError, 'Error, it is not 2D image' return y
[mmset2mat] [Up] [mmcmp] | ![]() |
Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center. |