1

I have looked this error here but the code was different , he used 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

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

So I'm trying to imitate that on Python

Thank you :)

  • Can you please share a minimal, reproducible example? please see https://stackoverflow.com/help/minimal-reproducible-example – Alonme Jun 21 '20 at 21:42

1 Answers1

0

cv2.imread returns a numpy.ndarray object, however ImageEnhance.Brightness is expecting a PIL.Image.Image object, as can be seen in the documentation.

Check the docs for creating a PIL.Image.Image object from a path.

Alonme
  • 1,364
  • 15
  • 28