def pil_from_ndarray(ndarray):
 try:
  if ((ndarray.dtype == 'float32') or (ndarray.dtype == 'float64')):
   assert (ndarray.min() >= 0.0)
   assert (ndarray.max() <= 1.0)
   ndarray = np.cast['uint8']((ndarray * 255))
   if ((len(ndarray.shape) == 3) and (ndarray.shape[2] == 1)):
    ndarray = ndarray[:, :, 0]
  ensure_Image()
  rval = Image.fromarray(ndarray)
  return rval
 except Exception as e:
  logger.exception('original exception: ')
  logger.exception(e)
  logger.exception('ndarray.dtype: {0}'.format(ndarray.dtype))
  logger.exception('ndarray.shape: {0}'.format(ndarray.shape))
  raise
 assert False

def pil_from_ndarray ( ndarray ) : try : if ( ( ndarray . dtype == 'float32' ) or ( ndarray . dtype == 'float64' ) ) : assert ( ndarray . min ( ) >= 0.0 ) assert ( ndarray . max ( ) <= 1.0 ) ndarray = np . cast [ 'uint8' ] ( ( ndarray * 255 ) ) if ( ( len ( ndarray . shape ) == 3 ) and ( ndarray . shape [ 2 ] == 1 ) ) : ndarray = ndarray [ : , : , 0 ] ensure_Image ( ) rval = Image . fromarray ( ndarray ) return rval except Exception as e : logger . exception ( 'original exception: ' ) logger . exception ( e ) logger . exception ( 'ndarray.dtype: {0}' . format ( ndarray . dtype ) ) logger . exception ( 'ndarray.shape: {0}' . format ( ndarray . shape ) ) raise assert False
converts an ndarray to a pil image .