def mpl_image_to_rgba(mpl_image):
 image = mpl_image.get_array()
 if (image.ndim == 2):
  input_range = (mpl_image.norm.vmin, mpl_image.norm.vmax)
  image = rescale_intensity(image, in_range=input_range)
  image = mpl_image.cmap(img_as_float(image))
 elif ((image.ndim == 3) and (image.shape[2] == 3)):
  image = np.dstack((image, np.ones_like(image)))
 return img_as_float(image)

def mpl_image_to_rgba ( mpl_image ) : image = mpl_image . get_array ( ) if ( image . ndim == 2 ) : input_range = ( mpl_image . norm . vmin , mpl_image . norm . vmax ) image = rescale_intensity ( image , in_range = input_range ) image = mpl_image . cmap ( img_as_float ( image ) ) elif ( ( image . ndim == 3 ) and ( image . shape [ 2 ] == 3 ) ) : image = np . dstack ( ( image , np . ones_like ( image ) ) ) return img_as_float ( image )
return rgb image from the given matplotlib image object .