Quite a busy one-liner, but here it is:

  1. First ensure your NumPy array, myarray, is normalised with the max value at 1.0.
  2. Apply the colormap directly to myarray.
  3. Rescale to the 0-255 range.
  4. Convert to integers, using np.uint8().
  5. Use Image.fromarray().

And you're done:

from PIL import Image
from matplotlib import cm
im = Image.fromarray(np.uint8(cm.gist_earth(myarray)*255))

with plt.savefig():

with im.save():

Answer from fraxel on Stack Overflow
Discussions

python - Converting a NumPy array to a PIL image - Stack Overflow
I want to create a PIL image from a NumPy array. Here is my attempt: # Create a NumPy array, which has four elements. The top-left should be pure # red, the top-right should be pure blue, the bottom- More on stackoverflow.com
🌐 stackoverflow.com
Converting between PIL Image and 2d pixel array?
Are you trying to translate a image into ascii art? More on reddit.com
🌐 r/learnpython
5
3
May 11, 2022
python - Numpy array to PIL image format - Stack Overflow
I would suggest you follow the ... rescale (0-255), convert to uint8, etc. ... Save this answer. ... Show activity on this post. In my comments I meant that you do something like this: Copyimport numpy as np from PIL import Image img = np.array(image) mean = 0 # var = ... More on stackoverflow.com
🌐 stackoverflow.com
How to convert numpy array into image using PIL? - Stack Overflow
import numpy as np from PIL import Image # Create black 1-bit array arr2 = np.full((200,200), False, dtype=bool) # Set some bits white arr2[80:120,80:120]=True im = Image.fromarray(arr2) im.save('a.png') print(im) More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-a-numpy-array-to-an-image
Convert a NumPy array to an image - GeeksforGeeks
July 15, 2025 - The plt.imshow() function takes the NumPy array and renders it as an image. While not specifically focused on image processing, Matplotlib’s visualization capabilities are convenient for displaying arrays as images, especially when analyzing ...
🌐
Medium
medium.com › @whyamit101 › step-by-step-guide-to-convert-numpy-array-to-pil-image-f7f8492cd785
Step-by-Step Guide to Convert NumPy Array to PIL Image | by why amit | Medium
February 9, 2025 - Grayscale images are simpler to handle, with just one channel. You created a grayscale NumPy array and converted it to a PIL image using the 'L' mode.
🌐
Delft Stack
delftstack.com › "delft stack" › "howto" › "python matplotlib howto's" › "how to convert a numpy array to pil image in python"
How to Convert a NumPy Array to PIL Image in Python | Delft Stack
March 13, 2025 - This tutorial explains how to convert a NumPy array to a PIL image using the Image.fromarray() function from the PIL package. Learn step-by-step methods for handling both RGB and grayscale images, and discover how to customize image properties ...
🌐
GitHub
github.com › mthiboust › array2image
GitHub - mthiboust/array2image: Converts a Numpy array to a PIL image. · GitHub
def array_to_image( arr, spatial_dims: tuple[int, ...] | None = None, channel_dim: int | None = None, cmap: Callable | None = None, inverted_colors: bool = False, bin_size: int | tuple[int, int] | None = None, target_total_size: int = 200, grid_thickness: int | tuple[int, ...] = 0, norm: bool = False, ) -> PIL.Image ... spatial_dims: Spatial dimensions of the array. If None, spatial dimensions are automatically guessed. channel_dim: Channel dimension of the array. Only 1, 2 or 3 channel dimension arrays can be converted to an image.
Find elsewhere
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-109.php
Python NumPy: Convert a numpy array to an image - w3resource
August 29, 2025 - img = Image.fromarray(data, 'RGB'): Convert the NumPy array 'data' to a PIL Image object with the mode 'RGB' (red, green, blue).
🌐
Pythoninformer
pythoninformer.com › python-libraries › numpy › numpy-and-images
PythonInformer - Image processing with pillow and NumPy
October 2, 2022 - Now let's fill the array with orange pixels (red=255, green=128, blue=0). We use slices to do this, the three values are broadcast across all the rows and columns of the array: ... The PIL function Image.fromarray function creates a PIL image from a NumPy array.
🌐
GitHub
gist.github.com › walsvid › e5048001b4ff89b6a7e1aec4b5bb41f1
How to convert between NumPy array and PIL Image · GitHub
How to convert between NumPy array and PIL Image. GitHub Gist: instantly share code, notes, and snippets.
🌐
TutorialsPoint
tutorialspoint.com › convert-a-numpy-array-to-an-image
Convert a NumPy array to an image
August 9, 2023 - In the following example, we are passing the array as the input argument to the Image() function of the PIL library then the array will be converted into an image. import numpy as np from PIL import Image img_array = np.random.randint(0, 256, ...
🌐
YouTube
youtube.com › how to fix your computer
PYTHON : How to convert a NumPy array to PIL image applying matplotlib colormap - YouTube
PYTHON : How to convert a NumPy array to PIL image applying matplotlib colormap [ Gift : Animated Search Engine : https://www.hows.tech/p/recommended.html ] ...
Published: December 6, 2021
Views: 361
🌐
Codegive
codegive.com › blog › numpy_array_to_image_pil.php
Numpy array to image pil
NumPy: For numerical operations and array manipulation. Pillow: For image processing and file handling. You can install them using pip: ... The heart of converting a NumPy array to a PIL image is the PIL.Image.fromarray() function.
🌐
Reddit
reddit.com › r/learnpython › converting between pil image and 2d pixel array?
r/learnpython on Reddit: Converting between PIL Image and 2d pixel array?
May 11, 2022 -

I need to do the following:

  1. Import an image.

  2. Convert image to a 2D array of pixel values (rgb tuples, bytes, whatever it doesn't matter).

  3. Manipulate that 2D array (needs to be 2D as I'm using a library that requires a 2D array of data).

  4. Convert the newly changed 2D array back into an image.

  5. Save the image.

Anyone know how I can accomplish this? PIL Image documentation has some functions to get data but it's all 1D arrays, and I'm not sure how to get them into 2D arrays and then re-convert it back into an image again.

🌐
Iditect
iditect.com › faq › python › converting-a-numpy-array-to-a-pil-image.html
Converting a NumPy array to a PIL image
To convert a NumPy array to a PIL (Python Imaging Library) image, you can use the Image module from the PIL package.
🌐
Stack Overflow
stackoverflow.com › questions › 71142238 › how-to-convert-numpy-array-into-image-using-pil
How to convert numpy array into image using PIL? - Stack Overflow
import numpy as np from PIL import Image # Create black 1-bit array arr2 = np.full((200,200), False, dtype=bool) # Set some bits white arr2[80:120,80:120]=True im = Image.fromarray(arr2) im.save('a.png') print(im) <PIL.Image.Image image mode=1 ...
🌐
Codemia
codemia.io › home › knowledge hub › how to convert a numpy array to pil image applying matplotlib colormap
How to convert a NumPy array to PIL image applying matplotlib colormap | Codemia
September 24, 2025 - After conversion, PIL gives you simple save and resize operations, while NumPy remains ideal for numeric transforms. You can convert back with np.array(image) whenever downstream code expects an array.
🌐
Pluralsight
pluralsight.com › blog › tech guides & tutorials
Importing Image Data Into NumPy Arrays | Pluralsight
April 15, 2025 - For example, the code below loads the photograph in JPEG format and saves it in PNG format. import numpy as np from PIL import Image im = np.array(Image.open('kolala.jpeg').convert('L')) #you can pass multiple arguments in single line ...