You want to use the mode 'L' instead of 'LA' as the parameter to the convert() method. 'LA' leaves an alpha channel and then the numpy.asarray doesn't work as you intended. If you need the alpha channel, then you will need a different method to convert to a numpy array. Otherwise, use mode 'L'.

Answer from Justin Peel on Stack Overflow
Discussions

Applying grayscale conversion to list of numpy array of images using Python
Find answers to Applying grayscale conversion to list of numpy array of images using Python from the expert community at Experts Exchange More on experts-exchange.com
🌐 experts-exchange.com
July 3, 2021
python - Converting 2D Numpy array of grayscale values to a PIL image - Stack Overflow
Say I have a 2D Numpy array of values on the range 0 to 1, which represents a grayscale image. How do I then convert this into a PIL Image object? All attempts so far have yielded extremely strange More on stackoverflow.com
🌐 stackoverflow.com
Converting grayscale images to binary and storing in a numpy array in python - Stack Overflow
I am working on a binary image segmentation problem using Tensorflow Keras. The masks are in grayscale and images are in RGB. I need to convert the grayscale masks to binary and store them in a Numpy More on stackoverflow.com
🌐 stackoverflow.com
Convert colour to grey scale numpy array - Part 1 (2018) - fast.ai Course Forums
How do I convert an array of two colour images to an array of two gray scale images using the to_grayscale (from this site) function below. Important: I don’t want image files, I want the array image_g defined below. First create the function and sample images: import numpy as np import ... More on forums.fast.ai
🌐 forums.fast.ai
0
October 13, 2018
🌐
Stack Overflow
stackoverflow.com › questions › 55290010 › convert-grayscale-image-to-numpy-array
python - Convert grayscale image to numpy array - Stack Overflow
March 21, 2019 - photo = filedialog.askopenfilename(initialdir="/", title="Select file", filetypes=(("png files", "*.png"), ("all files", "*.*"))) img = PIL.Image.open(photo).convert('L') ... [[0 0 0 ... 0 0 0] [0 0 0 ... 0 0 0] [0 0 0 ... 0 0 0] ... [0 0 0 ... 0 0 0] [0 0 0 ... 0 0 0] [0 0 0 ... 0 0 0]] At this stage I'm afraid I am stuck on what to do next, so any help would be much appreciated. Thanks! ... Try saving the data you get with np.asarray into a text file numpy.savetxt so that you can take a look at the entire data in that array.
🌐
Experts Exchange
experts-exchange.com › questions › 29219599 › Applying-grayscale-conversion-to-list-of-numpy-array-of-images-using-Python.html
Solved: Applying grayscale conversion to list of numpy array of images using Python | Experts Exchange
July 3, 2021 - Hi, I have .npy file which is numpy version of the images. The shape of numpy image data set is images_all.shape (4750, 128, 128, 3) I need help to convert the images_all numpy array which is having colored images into grayscale images using Python?
🌐
Brandonrohrer
brandonrohrer.com › convert_rgb_to_grayscale.html
How to Convert an RGB Image to Grayscale
For grayscale images, the result is a two-dimensional array with the number of rows and columns equal to the number of pixel rows and columns in the image. Low numeric values indicate darker shades and higher values lighter shades. The range of pixel values is often 0 to 255.
🌐
Towards Data Science
towardsdatascience.com › home › artificial intelligence › deep learning › how rgb and grayscale images are represented in numpy arrays?
How RGB and Grayscale Images Are Represented in NumPy Arrays? | Towards Data Science
December 4, 2021 - Image size - Two dimensions are always needed to represent the height and width of the image. ... A single grayscale image can be represented using a two-dimensional (2D) NumPy array or a tensor.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 74375192 › converting-grayscale-images-to-binary-and-storing-in-a-numpy-array-in-python
Converting grayscale images to binary and storing in a numpy array in python - Stack Overflow
from tensorflow.keras.preprocessing.image import load_img,ImageDataGenerator from skimage.transform import resize import os from tqdm import tqdm im_height,im_width = 256,256 threshold = 150 ids_test = next(os.walk("data/test/image"))[2] # list of names all images in the given path print("No. of images = ", len(ids_test)) X_ts = np.zeros((len(ids_test), im_height, im_width, 3), dtype=np.float32) Y_ts = np.zeros((len(ids_test), im_height, im_width, 1), dtype=np.float32) for n, id_ in tqdm(enumerate(ids_test), total=len(ids_test)): img = load_img("data/test/image/"+id_, color_mode = "rgb") x_img
🌐
Quora
quora.com › How-do-I-turn-NumPY-arrays-into-grayscale-images
How to turn NumPY arrays into grayscale images - Quora
Answer (1 of 3): There are several available libraries and examples of using them. They are easily found. Seek and ye shall find. [code]from PIL import Image import matplotlib.pyplot as plt import imageio [/code]You don’t use all three, but you can choose among them.
🌐
Saskeli
saskeli.github.io › data-analysis-with-python-summer-2019 › image_processing.html
Image processing — Data analysis with Python - Summer 2019 documentation
For example, if the array contains value 255 at coordinates (0,0), then in the image the pixel at top left is white. In color images there is third axis is for the red, green, and blue components of each pixel. For each of these color components there is a value between 0.1 and 1.0 (or between 0 and 255). The combinations of different values for the three components red, green, and blue can result in at least 16.7 million colors. Since images can be represented as multidimensional arrays, we can easily process images using NumPy functions.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-convert-an-image-to-grayscale-using-numpy-arrays-a-comprehensive-guide
How to Convert an Image to Grayscale Using NumPy Arrays: A Guide | Saturn Cloud Blog
May 1, 2026 - Color images are often represented as three-dimensional NumPy arrays, with dimensions corresponding to the height, width, and color channels of the image. Converting these to grayscale can reduce computational complexity and noise, making subsequent image processing tasks more manageable.
🌐
Codepointtech
codepointtech.com › home › grayscale image processing with numpy: a python guide
Grayscale Image Processing with NumPy: A Python Guide - codepointtech.com
July 4, 2026 - Standardization: For certain machine learning models, input images need to be standardized, and grayscale conversion is often part of that process. Before we start, ensure you have the necessary libraries installed. We”ll be using NumPy for numerical operations and Pillow (PIL Fork) for loading and saving images. ... First, we need to load an image and convert it into a NumPy array.
🌐
Brohrer
brohrer.github.io › convert_rgb_to_grayscale.html
How to Convert an RGB Image to Grayscale - Brandon Rohrer
For grayscale images, the result is a two-dimensional array with the number of rows and columns equal to the number of pixel rows and columns in the image. Low numeric values indicate darker shades and higher values lighter shades. The range of pixel values is often 0 to 255.
🌐
Fast.ai
forums.fast.ai › part 1 (2018)
Convert colour to grey scale numpy array - Part 1 (2018) - fast.ai Course Forums
October 13, 2018 - How do I convert an array of two colour images to an array of two gray scale images using the to_grayscale (from this site) function below. Important: I don’t want image files, I want the array image_g defined below.
🌐
scikit-image
scikit-image.org › skimage-tutorials › lectures › 00_images_are_arrays.html
Images are numpy arrays — Image analysis in Python
Images are represented in scikit-image using standard numpy arrays. This allows maximum inter-operability with other libraries in the scientific Python ecosystem, such as matplotlib and scipy. Let’s see how to build a grayscale image as a 2D array:
🌐
DataCamp
datacamp.com › doc › numpy › converting-images-to-numpy
Converting Images to NumPy
Always check the shape of the resulting array to ensure it matches expectations (e.g., color images should have three dimensions: height, width, and channels). Handle large files. For large images, consider optimizing loading times and memory usage by resizing or converting to grayscale. Use libraries. Leverage libraries like Pillow (`PIL`) for versatile image file handling and conversion to NumPy arrays.
🌐
Cloudinary
cloudinary.com › home › convert image to numpy array: methods, tips, and examples
Convert Image to NumPy Array: Methods, Tips, and Examples | Cloudinary
January 24, 2026 - These arrays represent the image as a matrix of pixel values, where each number corresponds to a specific brightness or color level. The array structure depends on the image format: grayscale images use two dimensions (height × width), while color ...
🌐
Stack Overflow
stackoverflow.com › questions › 71566658 › how-to-make-grayscale-image-using-numpy-and-matplotlib › 71567012
python - How to make grayscale image using numpy and matplotlib - Stack Overflow
If the end goal is just to save the image out as a grayscale version then Pillow will do the job. If the goal is to send the grayscale version to some other part of the script where numpy/matplotlib is required you can either use the second part of the answer at the above link or convert the Pillow object to a numpy array as shown here.