def array_to_img(x, dim_ordering=(0, 1, 2), scale=True):
 from PIL import Image
 x = x.transpose(dim_ordering)
 if scale:
  x += max((- np.min(x)), 0)
  x_max = np.max(x)
  if (x_max != 0):
   x = (x / x_max)
  x *= 255
 if (x.shape[2] == 3):
  return Image.fromarray(x.astype('uint8'), 'RGB')
 elif (x.shape[2] == 1):
  return Image.fromarray(x[:, :, 0].astype('uint8'), 'L')
 else:
  raise Exception('Unsupported channel number: ', x.shape[2])

def array_to_img ( x , dim_ordering = ( 0 , 1 , 2 ) , scale = True ) : from PIL import Image x = x . transpose ( dim_ordering ) if scale : x += max ( ( - np . min ( x ) ) , 0 ) x_max = np . max ( x ) if ( x_max != 0 ) : x = ( x / x_max ) x *= 255 if ( x . shape [ 2 ] == 3 ) : return Image . fromarray ( x . astype ( 'uint8' ) , 'RGB' ) elif ( x . shape [ 2 ] == 1 ) : return Image . fromarray ( x [ : , : , 0 ] . astype ( 'uint8' ) , 'L' ) else : raise Exception ( 'Unsupported channel number: ' , x . shape [ 2 ] )
converts a numpy array to pil image object .