You're not saying how exactly putdata() is not behaving. I'm assuming you're doing

>>> pic.putdata(a)
Traceback (most recent call last):
  File "...blablabla.../PIL/Image.py", line 1185, in putdata
    self.im.putdata(data, scale, offset)
SystemError: new style getargs format but argument is not a tuple

This is because putdata expects a sequence of tuples and you're giving it a numpy array. This

>>> data = list(tuple(pixel) for pixel in pix)
>>> pic.putdata(data)

will work but it is very slow.

As of PIL 1.1.6, the "proper" way to convert between images and numpy arrays is simply

>>> pix = numpy.array(pic)

although the resulting array is in a different format than yours (3-d array or rows/columns/rgb in this case).

Then, after you make your changes to the array, you should be able to do either pic.putdata(pix) or create a new image with Image.fromarray(pix).

Answer from dF. on Stack Overflow
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › Image.html
Image module - Pillow (PIL Fork) 12.2.0 documentation
As with array support, when converting Pillow images to arrays, only pixel values are transferred.
Discussions

PIL image to array (numpy array to array) - Python - Stack Overflow
I have a .jpg image that I would like to convert to Python array, because I implemented treatment routines handling plain Python arrays. It seems that PIL images support conversion to numpy array... More on stackoverflow.com
🌐 stackoverflow.com
April 2, 2017
python - How to convert a NumPy array to PIL image applying matplotlib colormap - Stack Overflow
I want to take a NumPy 2D array which represents a grayscale image, and convert it to an RGB PIL image while applying some of the matplotlib colormaps. I can get a reasonable PNG output by using the More on stackoverflow.com
🌐 stackoverflow.com
python - PIL image to array and back - Stack Overflow
EDIT: Sorry, the first version of the code was bullshit, I tried to remove useless information and made a mistake. Problem stays the same, but now it's the code I actually used I think my problem is More on stackoverflow.com
🌐 stackoverflow.com
Converting between PIL Image and 2d pixel array?
functions to get data but it's all 1D arrays, You might mean the getdata() method which returns a sequence object which contains the image data. You can use that to create 2D data. You get the image row length from the Image.size attribute , read one row length of pixel data from the sequence and store it as one row in your 2D data. More on reddit.com
🌐 r/learnpython
5
3
May 11, 2022
🌐
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.

🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-images-to-numpy-array
How to Convert images to NumPy array? - GeeksforGeeks
July 15, 2025 - Explanation: It loads 'Sample.png' using Image.open() and converts it to a NumPy array using np.array(). The resulting array has a shape of (200, 400, 3), indicating a color image with height 200, width 400 and 3 color channels (RGB). Example 3: Here we display the actual pixel data from the image in NumPy array format. ... from PIL import Image from numpy import asarray img = Image.open('Sample.png') res = asarray(img) print(res)
🌐
Educative
educative.io › answers › convert-a-pil-image-to-numpy-array
Convert a PIL image to NumPy array
Line 1: We import Image module from the PIL library. Line 3: We open the image using the Image.open() function and pass the file name of the image as a parameter. Line 5: We print the image, which shows that the image is a JPEG image.
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-108.php
Python NumPy: Convert a PIL Image into a NumPy array - w3resource
August 29, 2025 - Create a function that transforms a PIL image into grayscale and returns the corresponding NumPy array. Test the conversion with images of different modes (RGB, L, RGBA) and compare the array dimensions.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-convert-rgb-pil-image-to-numpy-array-with-3-channels-a-comprehensive-guide
How to Convert RGB PIL Image to Numpy Array with 3 Channels: A Guide | Saturn Cloud Blog
February 8, 2024 - The resulting img_array is a 3D NumPy array, where the first dimension represents the height, the second dimension represents the width, and the third dimension represents the RGB channels. To verify that our conversion was successful, we can print the data types. ... Versatility: The combination of PIL and NumPy provides a versatile solution for handling and manipulating images, catering to a wide range of image processing tasks.
Find elsewhere
🌐
Delft Stack
delftstack.com › home › howto › numpy › pil image to numpy array
How to Convert PIL Image to NumPy Array | Delft Stack
March 11, 2025 - This function creates a new array from the given image, which is particularly useful when you want to ensure that the data is independent of the original image object. Here’s how you can do it: from PIL import Image import numpy as np # Open ...
🌐
Python Pool
pythonpool.com › home › blog › how to convert pil images to numpy array
How To Convert PIL Images to Numpy Array - Python Pool
September 10, 2022 - Note that both functions .array() and .asarray() produce similar outputs. Using the Numpy ndarray and the Pillow module, we can transform a 2D matrix from Numpy to an Image file.
🌐
Pythoninformer
pythoninformer.com › python-libraries › numpy › numpy-and-images
PythonInformer - Image processing with pillow and NumPy
October 2, 2022 - We then create a 1-dimensional array of length 200 with values that gradually change from 0 to 255. We fill channel 3 of each line of the image with these values. This means that the pixels on the left side of the image will be transparent, and the pixels on the right will be almost fully opaque.
🌐
Linux Hint
linuxhint.com › pil-image-to-numpy-array
PIL Image to NumPy Array
November 9, 2022 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
Edureka Community
edureka.co › home › community › categories › python › how to convert a pil image into a numpy array
How to convert a PIL Image into a numpy array | Edureka Community
June 22, 2020 - I'm trying around with converting a PIL image object back and forth to a numpy array so I can do some ... , but can't quite seem to get it to behave.
🌐
Roboflow
roboflow.com › use opencv › convert pil image to numpy array
Convert PIL Image to NumPy array (OpenCV)
HOW TO GUIDE · You can convert a PIL Image object into a NumPy array using the np.asarray() function: import numpy as np from PIL import Image pil_image = Image.open("image.jpeg") image = np.asarray(pil_image) OpenCV can be used with the open source supervision Python package.
🌐
Pluralsight
pluralsight.com › what makes pluralsight different | pluralsight › tech guides & tutorials
Importing Image Data Into NumPy Arrays | Pluralsight
April 15, 2025 - You can also resize the array of the pixel image and trim it. After performing the manipulations, it is important to save the image before performing further steps. The format argument saves the file in different formats, such as PNG, GIF, or PEG. 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 print(type(im)) gr_im= Image.fromarray(im).save('gr_kolala.png')
🌐
Matias Codesal
matiascodesal.com › posts › how-convert-pillow-pil-image-numpy-array-fast
How to Convert a Pillow (PIL) Image to a Numpy Array FAST!
December 22, 2020 - You want to use numpy.asarray and just pass your image object right into it. Avoid anything that involves lists or Image.getdata. Here’s an example: ... import numpy as np from PIL import Image img = Image.open(filepath) # datatype is optional, ...
🌐
Uploadcare
uploadcare.com › processing & transformations category › fast pillow image import to numpy and opencv arrays
Fast Pillow image import to NumPy and OpenCV arrays | Uploadcare
September 7, 2021 - Here are the two most common ways to convert a Pillow image to NumPy. If you Google it, you’ll probably find one of them: numpy.array(im) — makes a copy from an image to a NumPy array.
🌐
GeeksforGeeks
geeksforgeeks.org › convert-a-numpy-array-to-an-image
Convert a NumPy array to an image - GeeksforGeeks
April 1, 2025 - import numpy as np from PIL import Image a = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8) # Convert `a` to a PIL Image img = Image.fromarray(a) img.show() ... Explanation: np.random.randint() generates random integers (0-255) for ...