The correct parameter in your cv2.imread
should be:
img = cv2.imread('path/to/your/image', cv2.IMREAD_UNCHANGED)
Let's have a look at your images now. I use ImageJ's Show Info...
command as well as the following Python code with OpenCV and Pillow:
import cv2
from PIL import Image
img_pil = Image.open('path/to/your/image')
print('Pillow: ', img_pil.mode, img_pil.size)
img = cv2.imread('path/to/your/image', cv2.IMREAD_UNCHANGED)
print('OpenCV: ', img.shape)
First image (depth map)
Pillow: RGB (640, 512)
OpenCV: (512, 640, 3)
ImageJ also says, that's a RGB image. So, most likely, your depth map was just saved as a RGB png
.
Second image (dog)
Pillow: RGB (332, 300)
OpenCV: (300, 332, 3)
Interestingly, ImageJ says, that's an grayscale jpg
! I assume, OpenCV and Pillow just don't support grayscale jpg
, although there seems to be a grayscale jpg
format.
Third image (sign)
Pillow: 1 (200, 140)
OpenCV: (140, 200)
Both, Pillow and OpenCV say, that's a grayscale image, which is also supported by ImageJ. Furthermore, Pillow uses mode '1'
here, which is reflected by the dithered look of the image.
Fourth image (colours)
Pillow: RGB (500, 333)
OpenCV: (333, 500, 3)
That's just some RGB image; ImageJ also says this.
Conclusion
Yes, most likely, most of your images may just be RGB images. Nevertheless, using cv2.IMREAD_UNCHANGED
at least will properly identify grayscale png
files. It's questionable, if grayscale jpg
files are properly supported.
Hope that helps!
----------------------------------------
System information
----------------------------------------
Platform: Windows-10-10.0.16299-SP0
Python: 3.8.1
OpenCV: 4.2.0
Pillow: 7.0.0
----------------------------------------