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 OverflowGeeksforGeeks
geeksforgeeks.org › python › python-grayscaling-of-images-using-opencv
Python | Grayscaling of Images using OpenCV - GeeksforGeeks
September 23, 2025 - Let's learn the different image processing methods to convert a colored image into a grayscale image. Python · import cv2 image = cv2.imread('C:\\Documents\\full_path\\tomatoes.jpg') gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.imshow('Grayscale', gray_image) cv2.waitKey(0) cv2.destroyAllWindows() Input: Input Image ·
Videos
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
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)
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 4, 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.
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 › 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.github.io › posts › how-to-convert-color-image-to-grayscale-in-opencv-with-python.html
How to convert Color image to Grayscale in OpenCV with Python - Akash Srivastava
May 13, 2020 - This page has been moved. If you are not redirected within 3 seconds, click here
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)
GeeksforGeeks
geeksforgeeks.org › python › python-opencv-cv2-imshow-method
Python OpenCV | cv2.imshow() method - GeeksforGeeks
Example 1: In this example, an ... cv2.imshow("Gray Image", img) cv2.waitKey(0) cv2.destroyAllWindows() Output: The grayscale image is displayed in a window....
Published February 23, 2026



