def SaveImage(FileName, Image, Method="matplotlib", ColourMap=cm.viridis): try: os.mkdir("ImageExport") except OSError: pass if Method == "skimage": # will be in monochrome skimsave("./ImageExport/" + FileName + ".jpeg", Image / np.max(Image), plugin="pil") elif Method == "matplotlib": # has colour map as well plt.imsave("./ImageExport/" + FileName + ".jpeg", Image, cmap=ColourMap)
def SaveImage(self, FileName, Method="matplotlib"): try: os.mkdir("ImageExport") except OSError: pass if Method == "skimage": # will be in monochrome skimsave("./ImageExport/" + FileName + ".jpeg", self.ManipulatedData / np.max(self.ManipulatedData), plugin="pil") elif Method == "matplotlib": # has colour map as well plt.imsave("./ImageExport/" + FileName + ".jpeg", self.ManipulatedData, cmap=self.ColourMap)
def imsave( filepath: str, image: Union[np.ndarray, torch.Tensor], ): """Save image into a file. Args: filepath: string containing path to output file. image: NumPy array or a torch.Tensor to save.""" if not isinstance(image, torch.Tensor): skimsave(filepath, image) else: if image.ndim == 3: image_to_save = image.permute(1, 2, 0).cpu().numpy().squeeze() skimsave(filepath, image_to_save) else: skimsave(filepath, image.cpu().numpy().squeeze())
def imsave(outfile, img): if type(img) is th.Tensor: img = img.cpu().numpy() return skimsave(outfile, img, check_contrast=False)
def imsave(outfile, img): return skimsave(outfile, img, check_contrast=False)