[英]Error: 'numpy.ndarray' object has no attribute 'mode'
I have looked this error here but the code was different, he used PIL.ImageOps我在这里看过这个错误,但代码不同,他使用了 PIL.ImageOps
So basically I got an error with this code:所以基本上我得到了这段代码的错误:
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()
The traceback is:回溯是:
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'
I was trying to take a very dark image and make it brighter so i can see the image.我试图拍摄一张非常暗的图像并使其更亮,以便我可以看到图像。 when I was using MATLAB I used imadjust当我使用 MATLAB 时,我使用了 imadjust
image = imadjust(dark_image,[0 adjustment],[]);
So I'm trying to imitate that on Python所以我试图在 Python 上模仿它
Thank you:)谢谢:)
cv2.imread
returns a numpy.ndarray
object, however ImageEnhance.Brightness
is expecting a PIL.Image.Image
object, as can be seen in the documentation . cv2.imread
返回numpy.ndarray
object,但是ImageEnhance.Brightness
期待PIL.Image.Image
object,如文档中所示。
Check the docs for creating a PIL.Image.Image
object from a path.检查文档以从路径创建PIL.Image.Image
object。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.