I am trying to compare the first image in a folder to all other images in the same folder, to check for identical images. Simple idea - load the filenames of the folder in question to a list f, make a nested for loop to compare f[0] to f[1], f[2]...and so on. This works for f[0], f[1], f[2], but then gives IOError No such file or directory: '1_slice_0003.tif'. The file is in the folder, and it is written to f correctly (I can print f[3] without error). Length of f also matches the number of files in the image directory. What am I missing here?
from PIL import Image
import math, operator
import os
f = os.listdir("E:/JAWS/Converted_tiff/1")
count = 0
for filename in f:
h1 = Image.open(filename).histogram()
for filename in f:
filename = f[count]
h2 = Image.open(filename).histogram()
rms = math.sqrt(reduce(operator.add,
map(lambda a,b: (a-b)**2, h1, h2))/len(h1))
print str(f[count])
print rms
count += 1