0
我有一組保存在一個文件夾中的RGBA圖像,我的目標是將這些圖像轉換爲另一個pgm格式的文件夾,驗證碼:轉換文件夾中的RGBA圖像並將其保存到'.pgm'格式的另一個文件夾
path1 = file/path/where/image/are/stored
path2 = file/path/where/pgm/images/will/be/saved
list = os.listdir(path1)
for file in listing:
#Transforms an RGBA with channel into an RGB only
image_rgb = Image.open(file).convert('RGB')
#Color separation stains to detect microscopic cells
ihc_hed = rgb2hed(image_rgb)
#Trasnforms the image into a numpy array of the UINT8 Type
cv_img = ihc_hed.astype(np.uint8)
# create color boundaries boundaries detecting black and blue stains
lower = np.array([0,0,0], dtype = "uint8")
upper = np.array([0,0,255], dtype = "uint8")
#calculates the pixel within the specified boundaries and create a mask
mask = cv2.inRange(cv_img, lower, upper)
img = Image.fromarray(mask,'L')
img.save(path2+file,'pgm')
但是我得到一個錯誤,說明KeyError異常:「PGM」,似乎「PGM」形式是不是在模式
謝謝你的建議:)