I have been trying to save my image without the axis, white spaces, legends etc... without using imshow, this is because I don't want the image to/ try to appear in another window. Instead, I would like it to just save as image.png.
This is what I have tried so far but both try to show the image in another window which I don't want. But it does succeed in saving the image with no axis etc...
viz
here is my data as it were.
viz = display_images(outputs.copy()) #(outputs.copy(), inputs.copy())
I've tried:
fig = plt.figure(frameon=False)
fig.set_size_inches(6.4,4.8)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(viz, aspect='auto')
fig.savefig('image.png')
To make this more clear, I have included the code for display_images
although it may not be required to help with the initial issue.
def display_images(outputs, inputs=None, gt=None, is_colormap=True, is_rescale=True):
import matplotlib.pyplot as plt
import skimage
from skimage.transform import resize
plasma = plt.get_cmap('plasma')
shape = (outputs[0].shape[0], outputs[0].shape[1], 3)
all_images = []
for i in range(outputs.shape[0]):
imgs = []
if isinstance(inputs, (list, tuple, np.ndarray)):
x = to_multichannel(inputs[i])
x = resize(x, shape, preserve_range=True, mode='reflect', anti_aliasing=True )
imgs.append(x)
if isinstance(gt, (list, tuple, np.ndarray)):
x = to_multichannel(gt[i])
x = resize(x, shape, preserve_range=True, mode='reflect', anti_aliasing=True )
imgs.append(x)
if is_colormap:
rescaled = outputs[i][:,:,0]
if is_rescale:
rescaled = rescaled - np.min(rescaled)
rescaled = rescaled / np.max(rescaled)
imgs.append(plasma(rescaled)[:,:,:3])
else:
imgs.append(to_multichannel(outputs[i]))
img_set = np.hstack(imgs)
all_images.append(img_set)
all_images = np.stack(all_images)
return skimage.util.montage(all_images, multichannel=True, fill=(0,0,0))
return skimage.util.montage(all_images, multichannel=True, fill=(0,0,0))