Function iargb2gray

Synopse

Convert True Color RGB to gray image from its luminance.

  • g = iargb2gray(f)
    • g: Image. grayscale.
    • f: Image. RGB color model.
1. from numpy import *
2. 
3. def iargb2gray(f):
4. 
5.     g =  f[0,:,:]*0.299 + f[1,:,:]*0.587 + f[2,:,:]*0.114
6.     return g.astype(f.dtype)

Description

Convert RGB values to gray image using its luminance component.

Examples

01. from ia636 import iargb2gray
02. 
03. r = [[4,5,6],[4,2,4]]
04. g = [[0,1,2],[0,4,0]]
05. b = [[1,0,2],[1,2,2]]
06. f = zeros((3,2,3))
07. f[0,:,:], f[1,:,:], f[2,:,:] = r, g, b
08. print f[0,:,:]
09. print f[1,:,:]
10. print f[2,:,:]
11. g = iargb2gray(f)
12. print g
[[ 4.  5.  6.]
 [ 4.  2.  4.]]
[[ 0.  1.  2.]
 [ 0.  4.  0.]]
[[ 1.  0.  2.]
 [ 1.  2.  2.]]
[[ 1.31   2.082  3.196]
 [ 1.31   3.174  1.424]]
1. from ia636 import iargb2gray
2. 
3. f = adread('boat.ppm')
4. adshow(f)
5. g = iargb2gray(f)
6. adshow(g)

See Also