0

I have a 4-D ndarray and I would like to iterate over it to save them as images.

preds_test_t.shape

(14, 464, 512, 1)

For example, the shape of the ndarray represents 14 images with size in 464*512 and 1 single channel.

I am now stucked and have no idea to save them individually as images. Previous attempt has been made to save them one by one. However, this does not applicable for a large amount of images. For examples,

# generate_images_path = '/content/drive/My Drive/test/predicted image/'
# dpi = 96
# figsize = 512 / float(dpi), 462 / float(dpi)



# fig = plt.figure(figsize=figsize) 
# ax = fig.add_axes([0, 0, 1, 1])
# ax.imshow(preds_test_t[0,:,:,0], cmap=plt.cm.gray, interpolation = "nearest")
# plt.axis('off')
# ax.set(xlim=[-0.5, 512 - 0.5], ylim=[462 - 0.5, -0.5], aspect=1)
# fig.savefig(generate_images_path + 'predicted image (1).tiff', dpi=dpi, bbox_inches='tight', pad_inches = 0)
# plt.show()


# fig = plt.figure(figsize=figsize) 
# ax = fig.add_axes([0, 0, 1, 1])
# ax.imshow(preds_test_t[1,:,:,0], cmap=plt.cm.gray, interpolation = "nearest")
# plt.axis('off')
# ax.set(xlim=[-0.5, 512 - 0.5], ylim=[462 - 0.5, -0.5], aspect=1)
# fig.savefig(generate_images_path + 'predicted image (10).tiff', dpi=dpi, bbox_inches='tight', pad_inches = 0)
# plt.show()
warauuu
  • 15
  • 3

0 Answers0