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 OverflowCv::imshow displays gray image -opencv 3.4 - C++ - OpenCV
python - Show grayscale OpenCV image with matplotlib - Stack Overflow
Noob question. When I load a grayscale image using cv2.imread, the image shape is given as (227,227,3) , why is that happening?
python - How to visualize a 16-bit grayscale image with cv2.imshow()? - Stack Overflow
Videos
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



