As the assertion states, adaptiveThreshold() requires a single-channeled 8-bit image.

Assuming your floating-point image ranges from 0 to 1, which appears to be the case, you can convert the image by multiplying by 255 and casting to np.uint8:

float_img = np.random.random((4,4))
im = np.array(float_img * 255, dtype = np.uint8)
threshed = cv2.adaptiveThreshold(im, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 3, 0)
Answer from Aurelius on Stack Overflow
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to convert a python numpy array to a grayscale image
5 Best Ways to Convert a Python NumPy Array to a Grayscale Image - Be on the Right Side of Change
February 20, 2024 - In this code example, a 2D NumPy array with random values is first created, then Pillow’s Image.fromarray() function is used to transform this array into an image. The mode ‘L’ stands for luminance, which is used to create grayscale images.
Discussions

Building a gray scale image via a numpy array from ultrasonic sensor values - programming - OpenCV
Hi all, I have an ultrasonic sensor. I want to convert its distance readings to an image. I have the readings stored in a numpy array but how do I construct the array so that it is a valid gray scale image? Here is the code I have so far. import maxSonarTTY import numpy as np import cv2 def ... More on forum.opencv.org
🌐 forum.opencv.org
0
December 15, 2022
Grayscale image using opencv from numpy array failed - Stack Overflow
I use the following numpy array that hold an image which is black and white image with the following shape print(img.shape) (28, 112) when I try to grayscale the image, to use it to get contours ... More on stackoverflow.com
🌐 stackoverflow.com
June 3, 2018
python - cv2 - Load grayscale Image as Numpy Array from Variable - Stack Overflow
I have a 2D numpy array that contains my grayscale image (8bit per pixel). I now want to load it into cv2 and resize it to a fixed width and height. But when I load the numpy array I get the follow... More on stackoverflow.com
🌐 stackoverflow.com
Cannot process high bit-depth grayscale numpy array
Where you convert from a grayscale numpy array to a cv2 image EasyOCR/easyocr/utils.py Line 709 in b7ddee3 img = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR) cv2 gives an error for high bit-depth images > Unsupported depth of input image: > '... More on github.com
🌐 github.com
0
July 29, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-grayscaling-of-images-using-opencv
Python | Grayscaling of Images using OpenCV - GeeksforGeeks
September 23, 2025 - cv2.cvtColor(): Converts color spaces; cv2.COLOR_BGR2GRAY produces a single-channel grayscale image.
🌐
OpenCV
forum.opencv.org › t › building-a-gray-scale-image-via-a-numpy-array-from-ultrasonic-sensor-values › 11324
Building a gray scale image via a numpy array from ultrasonic sensor values - programming - OpenCV
December 15, 2022 - Hi all, I have an ultrasonic sensor. I want to convert its distance readings to an image. I have the readings stored in a numpy array but how do I construct the array so that it is a valid gray scale image? Here is the code I have so far. import maxSonarTTY import numpy as np import cv2 def scale_list(l, to_min, to_max): return [scale_number(i, to_min, to_max, min(l), max(l)) for i in l] m=0 raw_sonar_readings=[] while True: m=maxSonarTTY.measure("/dev/ttyUSB0") raw_sonar_r...
🌐
CSDN
devpress.csdn.net › python › 63045d887e6682346619a944.html
How to change numpy array into grayscale opencv image_python_Mangs-Python
August 23, 2022 - How can I change numpy array into grayscale opencv image in python? After some processing I got an array with following atributes: max value is: 0.99999999988, min value is 8.269656407e-08 and type is: <type 'numpy.ndarray'>. I can show it as an image using cv2.imshow() function, but I can't pass it into cv2.AdaptiveTreshold() function because it has wrong type:
🌐
Note.nkmk.me
note.nkmk.me › home › python › opencv
Reading and saving image files with Python, OpenCV (imread, imwrite) | note.nkmk.me
October 15, 2022 - If you want to save a color image (3D ndarray) as a grayscale image file, convert it to grayscale with cv2.cvtColor() and cv2.COLOR_BGR2GRAY. If you save 2D ndarray to a file and read it again with cv2.imread(), it will be read as 3D ndarray ...
🌐
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.
Find elsewhere
🌐
GitHub
gist.github.com › panzi › 1ceac1cb30bb6b3450aa5227c02eedd3
Python: Convert PIL.Image to OpenCV BGR(A)/grayscale image (NumPy array). This supports the most common image modes, but there are more! Patches for those are welcome. · GitHub
Python: Convert PIL.Image to OpenCV BGR(A)/grayscale image (NumPy array). This supports the most common image modes, but there are more! Patches for those are welcome. - pil2cv.py
🌐
OpenCV
docs.opencv.org › 3.4.20 › d3 › df2 › tutorial_py_basic_ops.html
OpenCV: Basic Operations on Images
>>> import numpy as np · >>> import ... coordinates. For BGR image, it returns an array of Blue, Green, Red values. For grayscale image, just corresponding intensity is returned....
🌐
Stack Overflow
stackoverflow.com › questions › 68186862 › cv2-load-grayscale-image-as-numpy-array-from-variable
python - cv2 - Load grayscale Image as Numpy Array from Variable - Stack Overflow
np_img = np.fromfile(path, dtype='uint8') np_img = np_img.reshape(height,width) img = cv2.imdecode(np_img,cv2.IMREAD_GRAYSCALE) ... No need for cv2.imdecode here. If you already have an uint8 NumPy array, you can use it directly in any OpenCV ...
🌐
GitHub
github.com › JaidedAI › EasyOCR › issues › 804
Cannot process high bit-depth grayscale numpy array · Issue #804 · JaidedAI/EasyOCR
July 29, 2022 - Where you convert from a grayscale numpy array to a cv2 image EasyOCR/easyocr/utils.py Line 709 in b7ddee3 img = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR) cv2 gives an error for high bit-depth images > Unsupported depth of input image: > '...
Author: JaidedAI
🌐
Medium
medium.com › @rndayala › getting-started-with-opencv-2a2bc80ba2d6
Getting started with OpenCV. OpenCV-Python is a great tool for fast… | by Raghunath D | Medium
January 28, 2019 - cv2.IMREAD_GRAYSCALE : Loads image in gray-scale mode (0) cv2.IMREAD_UNCHANGED : Loads image as such including alpha channel (-1) Instead of these three flags, you can simply pass integers 1, 0 or -1 respectively.
🌐
Stack Overflow
stackoverflow.com › questions › 55864705 › displaying-a-numpy-array-as-a-grayscale-image-using-opencv
python - Displaying a numpy array as a grayscale image using OpenCV - Stack Overflow
April 26, 2019 - You can do: cv2.imshow("Window", np.uint8(img)) api55 – api55 · 2019-04-26 09:39:25 +00:00 Commented Apr 26, 2019 at 9:39 · That was it! thanks mate :) KillyGourou – KillyGourou · 2019-04-26 09:41:57 +00:00 Commented Apr 26, 2019 at 9:41 · Add a comment | Related questions · 3 · Convert a 2D numpy array into a 3d numpy array representing a grayscaled image ·
🌐
TutorialsPoint
tutorialspoint.com › how-to-show-numpy-2d-array-as-grayscale-image-in-jupyter-notebook
How to show numpy 2D array as grayscale image in Jupyter Notebook?
from matplotlib import pyplot as plt import numpy as np # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Random data points data = np.random.rand(5, 5) # Plot the data using imshow with gray colormap plt.imshow(data, cmap='gray') # Display the plot plt.show()
🌐
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.
🌐
Note.nkmk.me
note.nkmk.me › home › python › opencv
Binarize image with Python, NumPy, OpenCV | note.nkmk.me
October 9, 2020 - This article describes how to binarize an image into black and white with a threshold. There are two ways: one is to use OpenCV function cv2.threshold(), and the other is to process ndarray with a bas ...
🌐
YouTube
youtube.com › watch
OpenCV Numpy Basics - Image Data Structure - Raspberry Pi - YouTube
Learn how images are structured for processing in OpenCV and learn the very basics of Numpy for use in Open CV. After this video, you will understand how Num...
Published: October 2, 2024