def read_png(filename):
 x = Reader(filename)
 try:
  alpha = x.asDirect()[3]['alpha']
  if alpha:
   y = x.asRGBA8()[2]
   n = 4
  else:
   y = x.asRGB8()[2]
   n = 3
  y = np.array([yy for yy in y], np.uint8)
 finally:
  x.file.close()
 y.shape = (y.shape[0], (y.shape[1] // n), n)
 return y

def read_png ( filename ) : x = Reader ( filename ) try : alpha = x . asDirect ( ) [ 3 ] [ 'alpha' ] if alpha : y = x . asRGBA8 ( ) [ 2 ] n = 4 else : y = x . asRGB8 ( ) [ 2 ] n = 3 y = np . array ( [ yy for yy in y ] , np . uint8 ) finally : x . file . close ( ) y . shape = ( y . shape [ 0 ] , ( y . shape [ 1 ] // n ) , n ) return y
read a png file to rgb8 or rgba8 unlike imread .