# mmreadgray
Read an image from a commercial file format and stores it as a gray-scale image.

## Synopsis

y = mmreadgray( filename )

Implemented in Python.

### Input

filename | String Name of file to read.

### Output

y | Image Gray-scale (uint8 or uint16) or binary image.

## Description

`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.

## Examples

    >>> a=mmreadgray('cookies.tif')

    >>> mmshow(a)

a |

## Source Code

    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

## See also

[`mmset2mat`] [Up] [`mmcmp`] |
Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center.