My python code does not iterate as many as it should. There are six image files in the working directory and len(f) also gives six. But the actual iteration of for loop stops after performing two loops.
import os import cv2 import numpy as np from matplotlib import pyplot as plt path = "D:\\_my_python\\Image_histogram_equalization\\source_imgs" os.chdir(path) print("Current Working Directory: " , os.getcwd()) files =  for r, d, f in os.walk(path): for file in f: if '.jpg' in file: files.append(os.path.join(r, file)) print("Processing %d files.." %len(f)) count = 0 for f in files: g = f[:f.find(".jpg")] + "_CLAHE20.jpg" print("Converting %s to %s..." % (f, g)) img = cv2.imread(f) img_yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV) clahe = cv2.createCLAHE(clipLimit=2, tileGridSize=(8,8)) img_yuv[:,:,0] = clahe.apply(img_yuv[:,:,0]) img_output = cv2.cvtColor(img_yuv, cv2.COLOR_YUV2BGR) cv2.imwrite(g, img_output) count = count + 1 else: print("Process completed for %d files out of %d files. " % (count, len(f)))
It should run six loops because there are six images in the folder and len(f) also gives six.