簡體   English   中英

錯誤:“numpy.ndarray”object 沒有屬性“模式”

[英]Error: 'numpy.ndarray' object has no attribute 'mode'

我在這里看過這個錯誤,但代碼不同,他使用了 PIL.ImageOps

所以基本上我得到了這段代碼的錯誤:

img1 = cv2.imread(r'C:\Users\Yael\Desktop\final project\Image processing\PC3\PC3_Glucose_1.tif', 0)
enhancer = ImageEnhance.Brightness(img1)
enhancer = ImageEnhance.Brightness(img1)
enhanced_im = enhancer.enhance(1.8)
# enhanced_im.save("enhanced.sample5.png")
img = cv2.resize(enhanced_im, (960, 540))
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

回溯是:

 Traceback (most recent call last):
  File "C:/Users/Yael/PycharmProjects/FinalProject/Cell_Detection.py", line 9, in <module>
    enhancer = ImageEnhance.Brightness(img1)
  File "C:\Users\Yael\AppData\Roaming\Python\Python37\site-packages\PIL\ImageEnhance.py", line 84, in __init__
    self.degenerate = Image.new(image.mode, image.size, 0)
AttributeError: 'numpy.ndarray' object has no attribute 'mode'

我試圖拍攝一張非常暗的圖像並使其更亮,以便我可以看到圖像。 當我使用 MATLAB 時,我使用了 imadjust

image = imadjust(dark_image,[0 adjustment],[]);

所以我試圖在 Python 上模仿它

謝謝:)

cv2.imread返回numpy.ndarray object,但是ImageEnhance.Brightness期待PIL.Image.Image object,如文檔中所示。

檢查文檔以從路徑創建PIL.Image.Image object。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM