def image_blurrer(): for f in os.listdir(BASE_DIR): # check if the files are image if f.endswith('.png' or '.jpg' or '.jpeg'): print("Working on : " + f) # Make the image object i = Image.open(BASE_DIR + f) # split the image name fname, fext = os.path.splitext(f) i.filter(ImageFilter.BLUR()) i.save('{}image_blur/{}_blur_30{}'.format(BASE_DIR, fname, fext)) else: print("cant work on : " + f)
def calculate_fitness_blur_mean_difference(original_image, generated_image): if original_image.width != generated_image.width: print('FITNESS ERROR! Images are different.') # Calculate difference between two images original_image = ImageEnhance.Contrast(original_image).enhance(1.5) generated_image = ImageEnhance.Contrast(generated_image).enhance(1.5) difference = ImageChops.difference(original_image, generated_image) # Blur image difference = difference.filter(ImageFilter.BLUR()) # Calculate average brightness of differential image, this tells us how similar those images are stats = ImageStat.Stat(difference) average_brightness = (stats.rms[0] + stats.rms[1] + stats.rms[2]) / 3 # Return fitness value return (255 - average_brightness) / 255
def blur(image: Image.Image) -> Image.Image: return _apply_filter(image, ImageFilter.BLUR())
def blur_affine(img): img = img.filter(ImageFilter.BLUR(1)) shear = transforms.RandomAffine(shear=0.2) return (sheat(img))