You can use newer OpenCV python interface (if I'm not mistaken it is available since OpenCV 2.2). It natively uses numpy arrays:

import cv2
im = cv2.imread("abc.tiff")
print(type(im))

result:

<type 'numpy.ndarray'>
Answer from Andrey Kamaev on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-images-to-numpy-array
How to Convert images to NumPy array? - GeeksforGeeks
July 15, 2025 - Explanation: It converts a PIL image to a NumPy array using img_to_array() for processing, then back to a PIL image using array_to_img(), confirming smooth transformation with array type float32 and shape (200, 400, 3). For advanced, ...
Discussions

python - Converting Numpy Array to OpenCV Array - Stack Overflow
I'm trying to convert a 2D Numpy array, representing a black-and-white image, into a 3-channel OpenCV array (i.e. an RGB image). Based on code samples and the docs I'm attempting to do this via Py... More on stackoverflow.com
🌐 stackoverflow.com
Python - byte image to NumPy array using OpenCV - Stack Overflow
I have an image in bytes: print(image_bytes) b'\xff\xd8\xff\xfe\x00\x10Lavc57.64.101\x00\xff\xdb\x00C\x00\x08\x04\x04\x04\x04\x04\x05\x05\x05\x05\x05\x05\x06\x06\x06\x06\x06\x06\x06\x06\x06\x06\x... More on stackoverflow.com
🌐 stackoverflow.com
How to convert image file object to numpy array in with openCv python? - Stack Overflow
I am developing API to upload Image using Flask. After uploading i want to modify image using openCV, As openCV requires numpy array object to i have file object, how do i convert to numpy array? H... More on stackoverflow.com
🌐 stackoverflow.com
How can I turn numpy ndarray into an opencv image? Or alternatively, is there a module that can take numpy array screenshots at a high FPS?
Even cv2 creates ndarray! Pretty sure YOLO (or other ML model) uses ndarray. More on reddit.com
🌐 r/learnpython
2
2
August 9, 2022
🌐
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 - It doesn't have its own internal storage format for images, instead, it uses NumPy arrays. The common scenario for using this library is when you need to convert an image from Pillow to NumPy so that you can work with it using OpenCV.
🌐
AskPython
askpython.com › python › examples › convert-images-to-numpy-arrays
How to Convert Images to Numpy Arrays in Python - AskPython
April 21, 2026 - Different Python libraries read images in different ways. Each approach produces a slightly different array shape, dtype, and value range. Here is how the four most common methods compare. Pillow + NumPy – best for general use, no extra dependencies · OpenCV – fastest for bulk processing, returns BGR by default
🌐
Roboflow
roboflow.com › use opencv › convert pil image to numpy array
Convert PIL Image to NumPy array (OpenCV)
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 › blog › tech guides & tutorials
Importing Image Data Into NumPy Arrays | Pluralsight
April 15, 2025 - To work with an OpenCV library, you need to install it in the virtual environment using pip install opencv-contrib-python. The cv2 package provides an imread() function to load the image.
Find elsewhere
🌐
OpenCV Q&A Forum
answers.opencv.org › question › 225478 › convert-a-2d-numpy-array-to-cv_8uc1-type
Convert a 2D Numpy array to CV_8UC1 type - OpenCV Q&A Forum
And then, I convert them into a Numpy array: images_array = sitk.GetArrayFromImage(images) print(np.amin(images_array),np.amax(images_array)) print(images_array[24].shape, images_array[24].dtype) With this output: 0.0 2380.6191 (240, 240) float32 · I have found that I can convert it to CV_8UC1 OpenCV type, but I don't know how.
🌐
OpenCV
docs.opencv.org › 4.13.0 › d3 › df2 › tutorial_py_basic_ops.html
OpenCV: Basic Operations on Images
A good knowledge of Numpy is required to write better optimized code with OpenCV. ( Examples will be shown in a Python terminal, since most of them are just single lines of code ) ... Loads an image from a file. You can access a pixel value by its row and column coordinates. For BGR image, it returns an array ...
🌐
The Neural Base
theneuralbase.com › home › opencv › advanced course › opencv to numpy
OpenCV to NumPy | Opencv Advanced Course | The Neural Base
OpenCV images are NumPy arrays under the hood. When you load an image with cv2.imread(), you get a NumPy ndarray with shape (height, width, channels) and dtype uint8 (for 8-bit images). The pixel data is stored in memory as a C-contiguous array in BGR order by default, not RGB: this is critical ...
🌐
Python Examples
pythonexamples.org › python-opencv-read-image-cv2-imread
OpenCV Read Image - cv2 imread() - 3 Python Examples
You can read image into a numpy array using opencv library. The array contains pixel level data. And as per the requirement, you may modify the data of the image at a pixel level by updating the array values. To read an image in Python using OpenCV, use cv2.imread() function.
🌐
Clementine Blog
clementine.hashnode.dev › how-to-read-image-from-path-and-convert-to-a-numpy-array-in-python
How to read Image from Path and Convert to a NumPy Array in Python.
March 11, 2021 - Three methods to convert an image path to a NumPy array: Use OpenCV # OpenCV import cv2 img = cv2.imread(image_path) # reads an image in the BGR format img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # BGR -> RGB Use Matplotlib # Use Matplotlib from...
🌐
Medium
medium.com › @carlosdnotes › create-numpy-images-with-opencv-4b512d5993e4
Create NumPy Images with OpenCV. Create, display, and save images with… | by CarlosD | Medium
October 27, 2025 - Create NumPy Images with OpenCV Since images in the Python version of OpenCV are NumPy arrays, I will show you how to create, display, and save simple images created with NumPy. I will show you how …
Top answer
1 of 2
47

I created a 2x2 JPEG image to test this. The image has white, red, green and purple pixels. I used cv2.imdecode and numpy.frombuffer

import cv2
import numpy as np

f = open('image.jpg', 'rb')
image_bytes = f.read()  # b'\xff\xd8\xff\xe0\x00\x10...'

decoded = cv2.imdecode(np.frombuffer(image_bytes, np.uint8), -1)

print('OpenCV:\n', decoded)

# your Pillow code
import io
from PIL import Image
image = np.array(Image.open(io.BytesIO(image_bytes))) 
print('PIL:\n', image)

This seems to work, although the channel order is BGR and not RGB as in PIL.Image. There are probably some flags you might use to tune this. Test results:

OpenCV:
 [[[255 254 255]
  [  0   0 254]]

 [[  1 255   0]
  [254   0 255]]]
PIL:
 [[[255 254 255]
  [254   0   0]]

 [[  0 255   1]
  [255   0 254]]]
2 of 2
1

I searched all over the internet finally I solved:

NumPy array (cv2 image) - Convert

NumPy to bytes

and

bytes to NumPy

:.

#data = cv2 image array
def encodeImage(data):
    #resize inserted image
    data= cv2.resize(data, (480,270))
    # run a color convert:
    data= cv2.cvtColor(data, cv2.COLOR_BGR2RGB)
    return bytes(data) #encode Numpay to Bytes string



def decodeImage(data):
    #Gives us 1d array
    decoded = np.fromstring(data, dtype=np.uint8)
    #We have to convert it into (270, 480,3) in order to see as an image
    decoded = decoded.reshape((270, 480,3))
    return decoded;

# Load an color image
image= cv2.imread('messi5.jpg',1)

img_code = encodeImage(image) #Output: b'\xff\xd8\xff\xe0\x00\x10...';
img = decodeImage(img_code) #Output: normal array
cv2.imshow('image_deirvlon',img);
print(decoded.shape)

You can get full code from here

🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
Image processing with Python, NumPy | note.nkmk.me
October 20, 2020 - Convert BGR and RGB with Python, OpenCV (cvtColor) If you convert the image to grayscale with convert('L') and then pass it to np.array(), it returns 2D ndarray whose shape is (row (height), column (width)). im_gray = np.array(Image.open('d...
🌐
Indian AI Production
indianaiproduction.com › home › blog › explained cv2.imshow() function in detail | show image
Explained cv2.imshow() function in Detail | Show image
January 13, 2021 - import cv2 import numpy as np matx = np.zeros((200,200)) # numpy array with width =200, height=200 cv2.imshow("Zeros matx", matx) # show numpy array cv2.waitKey(0) # wait for ay key to exit window cv2.destroyAllWindows() # close all windows ...
🌐
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 - Converting images into NumPy arrays requires a few core libraries. NumPy handles the array operations, while image libraries such as Pillow, OpenCV, Matplotlib, or scikit-image handle reading the image file into memory.
🌐
Medium
manivannan-ai.medium.com › drawing-image-using-numpy-and-opencv-565abdbb3670
Drawing Image using Numpy and Opencv | by Manivannan Murugavel | Medium
December 14, 2017 - Drawing Image using Numpy and Opencv We will create numpy array import cv2 import numpy as np color_image = np.zeros((512,512,3),np.unit8) bw_image = np.zeros((512,512),np.unit8) cv2.imshow("Color …
🌐
GitHub
gist.github.com › b4f7bed3c4c059a765c89315f522db27
Converting and saving images to numpy array. · GitHub
Converting and saving images to numpy array. GitHub Gist: instantly share code, notes, and snippets.