here A Format conversion B Format .
Why can't you use PIL Read tiff What about the image .
PIL Support single channel and multi-channel Uint8 TIFF Image reading , Read single channel Uint16 TIFF The image changes to Uint8 Handle , Direct reading Uint16 TIFF The image will report an error .
Use here python Version of opencv Read images , And keep .
Code up tif--- turn ---》bmp. You can briefly modify the format according to your own needs
# With tiff turn jpg For example , Other formats are the same ,
# Change the path in the code to your own image storage path
import os
import cv2 as cv2
imagesDirectory = r"C:\Users\***\voc_make\test" # tiff The path of the folder where the picture is located
distDirectory = os.path.dirname(imagesDirectory)#
distDirectory = os.path.join(distDirectory, "bmpImages")# To store bmp Format folder path
print(distDirectory)
for imageName in os.listdir(imagesDirectory):
print("imageName", imageName)
imagePath = os.path.join(imagesDirectory, imageName)
print("imagePath", imagePath)
img = cv2.imread(imagePath)
try:
img.shape
except:
print(' Failed to read picture ')
break
print("imageName.split('.')[0]", imageName.split('.')[0])
distImagePath = os.path.join(distDirectory, imageName.split('.')[0]+'.bmp')# Change the image suffix to .jpg, And ensure the same name as the original image
print("distImagePath", distImagePath)
cv2.imwrite(distImagePath, img)
Remember to be in tif File in the same path bmp Folder
Make the path correct .
Here's the picture