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. import numpy as np
02. import ia636 as ia
03. 
04. r = np.array([[4,5,6],[4,2,4]])
05. g = np.array([[0,1,2],[0,4,0]])
06. b = np.array([[1,0,2],[1,2,2]])
07. f = np.array([r,g,b])
08. 
09. print 'f.shape=',f.shape
10. print 'f[0]=\n', f[0]
11. print 'f[1]=\n', f[1]
12. print 'f[2]=\n', f[2]
13. 
14. g = ia.iargb2gray(f)
15. print 'g=\n',g
f.shape= (3, 2, 3)
f[0]=
[[4 5 6]
 [4 2 4]]
f[1]=
[[0 1 2]
 [0 4 0]]
f[2]=
[[1 0 2]
 [1 2 2]]
g=
[[1 2 3]
 [1 3 1]]
1. f = adread('boat.ppm')
2. adshow(f)
3. g = ia.iargb2gray(f)
4. adshow(g)

See Also