I'm getting an error for a program that used to work without any problem. The folder xxx_xxx_xxx contains a lot of image files in jpeg format.
I'm trying to run through each image and retrieve hue values for each pixel on each image.
I've tried the solutions proposed here: Python - AttributeError: 'tuple' object has no attribute 'read' and here: AttributeError: 'tuple' object has no attribute 'read' with no success.
Code:
from PIL import Image
import colorsys
import os
numberofPix = 0
list = []
hueValues = 361
hueRange = range(hueValues)
for file in os.walk("c:/users/xxxx/xxx_xxx_xxx"):
im = Image.open(file)
width, height = im.size
rgb_im = im.convert('RGB')
widthRange = range(width)
heightRange = range(height)
for i in widthRange:
for j in heightRange:
r, g, b = rgb_im.getpixel((i, j))
if r == g == b:
continue
h, s, v = colorsys.rgb_to_hsv(r/255.0, g/255.0, b/255.0)
h = h * 360
h = int(round(h))
list.append(h)
numberofPix = numberofPix + 1
for x in hueRange:
print "Number of hues with value " + str(x) + ":" + str(list.count(x))
print str(numberofPix)
Here's the error I'm getting:
AttributeError: 'tuple' object has no attribute 'read'