Issue
I want to load and display a .tif image in OpenCV Python. I load the image using cv2.imread('1_00001.tif') and then I display it using plt.imshow(img), but the image displayed is all black instead of what it was originally.
I can load and display the image correctly using PIL's Image.open() and matplotlib's mpimg.imread() so I think it is a cv2 specific problem. However, I have also successfully displayed .jpg and .tiff images using the same cv2.imread() function so it may also be a problem with specifically that .tif image.
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('1_00001.tif')
plt.imshow(img)
I expect an image of a circle with a few blurry lines inside, but the actual output is just a black image.
Solution
Check your image pixel values. plt.imshow
clips pixel values from 0-255, so I would guess that you're feeding in a PNG image with values greater than 255, and they're all getting clipped to 255 (black). Usually you'll want to normalize a TIFF or PNG image before feeding them to plt.imshow
, so it's interesting that you're not seeing this problem on some tiff images.
Answered By - skeller88
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.