10 examples of 'save numpy array as image' in Python

Every line of 'save numpy array as image' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
12def save_img(im_array, output_path):
13 imageio.imwrite(output_path, im_array)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

614def save_array(self, array, outfile):
615
616 print('Writing {}'.format(outfile))
617 georeference = self.image.rasterio_geometry
618
619 if array.dtype == bool:
620 georeference['dtype'] = rasterio.uint8
621 array = array.reshape(1, array.shape[0], array.shape[1])
622 with rasterio.open(outfile, 'w', **georeference) as dst:
623 dst.write(array.astype(rasterio.uint8))
624
625 else:
626 georeference['dtype'] = array.dtype
627 array = array.reshape(1, array.shape[0], array.shape[1])
628 with rasterio.open(outfile, 'w', **georeference) as dst:
629 dst.write(array.astype(georeference['dtype']))
630
631 return None
415def save_np_image(image, output_file, save_format='jpeg'):
416 """Saves an image to disk.
417
418 Args:
419 image: 3-D numpy array of shape [image_size, image_size, 3] and dtype
420 float32, with values in [0, 1].
421 output_file: str, output file.
422 save_format: format for saving image (eg. jpeg).
423 """
424 image = np.uint8(image * 255.0)
425 buf = io.BytesIO()
426 scipy.misc.imsave(buf, np.squeeze(image, 0), format=save_format)
427 buf.seek(0)
428 f = tf.gfile.GFile(output_file, 'w')
429 f.write(buf.getvalue())
430 f.close()
151def save_figure_to_numpy(fig):
152 # save it to a numpy array.
153 data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
154 data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
155 return data
106def save_to_image(arr, image_path):
107 """ save common-formatted images
108 :param arr: array of shape (height, width, 3) or (height, width)
109 :param image_path: string
110
111 :return: None
112 """
113 Image.fromarray(arr.astype(np.uint8)).save(image_path)
56def save_image(image_numpy, image_path):
57 image_pil = Image.fromarray(image_numpy)
58 image_pil.save(image_path)
273def save_img_np(img_np, fname):
274 """Save image (numpy array, ZYX) as a TIFF."""
275 with omeTifWriter.OmeTifWriter(fname, overwrite_file=True) as fo:
276 fo.save(img_np)
277 print('saved:', fname)
75def save_img(file_name, img):
76 from skimage import io
77
78 if isinstance(img, Variable):
79 img = img.data.cpu().numpy()
80
81 if len(img.shape) == 4:
82 img = img.squeeze(0)
83
84 img = img.transpose(2, 1, 0)
85 img = img.clip(0, 255)
86 img = img.astype(np.uint8)
87
88 io.imsave(file_name, img)
27def save_img(data):
28 filename, image = data
29 cv2.imwrite(filename, image)
41def save_to_array(arr_name, arr_object):
42 """
43 Saves data object as a NumPy file. Used for saving train and test arrays.
44
45 INPUT
46 arr_name: The name of the file you want to save.
47 This input takes a directory string.
48 arr_object: NumPy array of arrays. This object is saved as a NumPy file.
49
50 OUTPUT
51 NumPy array of image arrays
52 """
53 return np.save(arr_name, arr_object)

Related snippets