This is the behavior of matplotlib. It finds the minimum and maximum of your picture, makes those black and white, and scales everything in between.

This is useful for arbitrary data that may have integer or floating point types, and value ranges between 0.0 and 1.0, or 0 .. 255, or anything else.

You can set those limits yourself with vmin and vmax arguments:

plt.imshow(imgGray, cmap='gray', vmin=0, vmax=255) # if your data ranges is uint8

OpenCV does no such auto-scaling. It has fixed rules. If it's floating point, 0.0 is black and 1.0 is white. If it's uint8, the range is 0 .. 255.

To get such auto-ranging in OpenCV, you'll have to scale the data before displaying:

normalized = cv.normalize(
    data, alpha=0.0, beta=1.0, norm_type=cv.NORM_MINMAX, dtype=cv.CV_32F)
Answer from Christoph Rackwitz on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-grayscaling-of-images-using-opencv
Python | Grayscaling of Images using OpenCV - GeeksforGeeks
September 23, 2025 - It produces a more realistic and visually accurate grayscale image. Python Β· import cv2 img_weighted = cv2.imread('C:\\Documents\\full_path\\tomatoes.jpg') rows, cols = img_weighted.shape[:2] for i in range(rows): for j in range(cols): gray ...
Discussions

Cv::imshow displays gray image -opencv 3.4 - C++ - OpenCV
Hi, The following code displays a gray image even though img has the correct pixel values. what is missing in this code cv::Mat img = cv::imread("brain.jpg"); cv::imshow("img", img); cv::waitKey(0); More on forum.opencv.org
🌐 forum.opencv.org
0
October 13, 2022
python - Show grayscale OpenCV image with matplotlib - Stack Overflow
I use opencv3 of python installed it by anaconda using: conda install -c menpo opencv3=3.2.0 But when i use it to convert a picture to grayscale, like: import cv2 import matplotlib.pyplot as pl... More on stackoverflow.com
🌐 stackoverflow.com
April 25, 2017
Noob question. When I load a grayscale image using cv2.imread, the image shape is given as (227,227,3) , why is that happening?
I had this problem too, I think reading image file is always have 3 channel even is grayscale so we should use cv2.cvtcolor to get grayscale again. More on reddit.com
🌐 r/learnmachinelearning
12
3
August 26, 2021
python - How to visualize a 16-bit grayscale image with cv2.imshow()? - Stack Overflow
I have a set of grayscale drone images in tiff format having 16-bit resolution where a person can be seen moving. How can I visualize these images in OpenCV as a normal image, so that I can see the More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com β€Ί opencv β€Ί opencv-python β€Ί issues β€Ί 611
Problem displaying grayscale image overlaid on a blank canvas Β· Issue #611 Β· opencv/opencv-python
January 14, 2022 - This is an issue with imshow because cv2.imwrite() works as expected. ... img1 = np.random.randint(0, 255, (500, 500)).astype("uint8") # Random image img2 = np.ones((1500, 1500)) * 255 # Blank Canvas img2[: img1.shape[0], : img1.shape[1]] = img1 cv2.imshow("Output", img2) cv2.waitKey(0) cv2.destroyAllWindows() plt.imshow(img2, cmap="gray") plt.title("expected output") plt.show()
Author Β  chinge55
🌐
OpenCV
forum.opencv.org β€Ί c++
Cv::imshow displays gray image -opencv 3.4 - C++ - OpenCV
October 13, 2022 - Hi, The following code displays a gray image even though img has the correct pixel values. what is missing in this code cv::Mat img = cv::imread("brain.jpg"); cv::imshow("img", img); cv::waitKey(0);
🌐
Jeremy Morgan
jeremymorgan.com β€Ί tutorials β€Ί opencv β€Ί how-to-grayscale-image
Grayscaling Images Made Simple with OpenCV
Just for fun, let’s display the original and grayscale images side by side: cv2.imshow('Original Image', image) cv2.imshow('Grayscale Image', gray_image) Next we’ll wait for a key press (don’t close the window with the x key, it will lock up your terminal) to close the window.
🌐
techtutorialsx
techtutorialsx.wordpress.com β€Ί 2018 β€Ί 06 β€Ί 02 β€Ί python-opencv-converting-an-image-to-gray-scale
Python OpenCV: Converting an image to gray scale – techtutorialsx
January 25, 2025 - import cv2 image = cv2.imread('C:/Users/N/Desktop/Test.jpg') gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.imshow('Original image',image) cv2.imshow('Gray image', gray) cv2.waitKey(0) cv2.destroyAllWindows()
🌐
Medium
korlakuntasaikamal10.medium.com β€Ί the-difference-in-reading-an-image-using-opencv-and-matplotlib-5529415704e5
The difference in Reading an image using OpenCV and Matplotlib | by kamal_DS | Medium
January 25, 2023 - For Grayscale image, there will be no issues which mean if we read an image using OpenCV using imread and if we show an image using matplotlib imshow then the image will be the same. import cv2 import matplotlib.pyplot as plt image_gray = ...
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com β€Ί python-grayscaling-of-images-using-opencv
Python Grayscaling of Images using OpenCV
November 13, 2024 - import cv2 # Read the image image = cv2.imread('apple.jpg') # Convert the image to grayscale gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Display the grayscale image (optional) cv2.imshow('Grayscale Image', gray_image) cv2.waitKey(0) cv2.destroyAllWindows()
🌐
OpenCV Q&A Forum
answers.opencv.org β€Ί question β€Ί 22102 β€Ί windows-imshow-sometimes-showing-gray-image
Windows imshow sometimes showing gray image - OpenCV Q&A Forum
I found a solution by modifying ... res) cv2.waitKey(0) The problem is indeed that imshow() works badly with files other than CV_8U file and can result in wrong image (like all gray images) when given 32F file, which are produced by some functions like StereoBM or other ...
🌐
Piratefsh
piratefsh.github.io β€Ί image-processing-101
Image Processing 101
# create 100 x 100 pixel array with average color value average_color_img = np.array([[average_color]*100]*100, np.uint8) plt.imshow(average_color_img) ... # threshold for grayscale image _, threshold_img = cv2.threshold(gray_img, 60, 255, cv2.THRESH_BINARY) threshold_img = cv2.cvtColor(threshold_img, cv2.COLOR_GRAY2RGB) plt.figure(figsize=(10,10)) plt.imshow(threshold_img)
🌐
Reddit
reddit.com β€Ί r/learnmachinelearning β€Ί noob question. when i load a grayscale image using cv2.imread, the image shape is given as (227,227,3) , why is that happening?
r/learnmachinelearning on Reddit: Noob question. When I load a grayscale image using cv2.imread, the image shape is given as (227,227,3) , why is that happening?
August 26, 2021 -

I then gave cv2.imread(imgpath, 0) gave me a colorful image with image shape as (227,227) .

But when I changed it to cv2.imread(imgpath,1) gave me the original grayscale image with image shape(227,227,3)

Am I doing this wrong?

Here's a sample I'm working with: The first image is the original image from the dataset .

http://imgur.com/a/RMEWRLO

🌐
Studyopedia
studyopedia.com β€Ί home β€Ί set a grayscale filter with opencv
Set a Grayscale filter with OpenCV - Studyopedia
March 15, 2025 - # Read and display an image with OpenCV and give it a grayscale filter import cv2 # Load an image # The cv2.IMREAD_GRAYSCALE here gives grayscale to the image image = cv2.imread(r'C:\Users\hp\Downloads\Astronaut.png', cv2.IMREAD_GRAYSCALE) # Display the image cv2.imshow("Grayscale Filter", image) # Wait for a key press and close the window cv2.waitKey(0) cv2.destroyAllWindows()
🌐
DataFlair
data-flair.training β€Ί blogs β€Ί image-conversion-using-opencv
Image Conversion using OpenCV - Colored, Grayscale and Binary - DataFlair
March 2, 2024 - 2. Iterate through each pixel of the color image. 3. For each pixel, calculate the grayscale intensity using the weighted average of the RGB values. 4. Set the grayscale intensity value for that pixel in the grayscale image. 5. Display the grayscale image using cv2.imshow() function.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-opencv-cv2-cvtcolor-method
Python OpenCV | cv2.cvtColor() method - GeeksforGeeks
August 11, 2025 - import cv2 src = cv2.imread(r'... cv2.waitKey(0) cv2.destroyAllWindows() Output Β· Explanation: cv2.cvtColor(src, cv2.COLOR_BGR2GRAY): Converts image to grayscale....
🌐
TutorialsPoint
tutorialspoint.com β€Ί show-a-grayscale-open-cv-image-with-matplotlib
Show a grayscale Open CV image with Matplotlib
June 1, 2021 - import cv2 # Read the image image = cv2.imread('apple.jpg') # Convert the image to grayscale gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Display the grayscale image (optional) cv2.imshow('Grayscale Image', gray_image) cv2.waitKey(0) cv2.destroyAllWindows()
🌐
Dev-akash
dev-akash.in β€Ί blogs β€Ί how-to-convert-color-image-to-grayscale-in-opencv
How to convert color image to grayscale in OpenCV
import cv2 # Reading color image as grayscale gray = cv2.imread("color-img.png",0) # Showing grayscale image cv2.imshow("Grayscale Image", gray) # waiting for key event cv2.waitKey(0) # destroying all windows cv2.destroyAllWindows() cvtColor() function in OpenCV is very helpful in converting color channels from one to another such as BRG to HSV or BRG to RGB.
🌐
TutorialsPoint
tutorialspoint.com β€Ί converting-an-image-from-colour-to-grayscale-using-opencv
Converting an image from colour to grayscale using OpenCV
March 17, 2021 - Step 1: Import OpenCV. Step 2: Read the original image using imread(). Step 3: Convert to grayscale using cv2.cvtcolor() function. import cv2 image = cv2.imread('colourful.jpg') cv2.imshow('Original',image) grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.imshow('Grayscale', grayscale)