Python Script: Delete all images in a folder which contains single color i.e. Complete Black/White...
So you need to delete all images that are of single color, i.e. Complete Black/White/Any Other Color. Its quite simple in Python:
import Image, os
import os
path = "C:\\Users\\Ajju\\Desktop\\test_images"
for filename in os.listdir(path):
img = Image.open(path + '\\' + filename)
clrs = img.getcolors()
print filename, len(clrs)
if len(clrs) == 1:
os.remove(path + '\\' + filename)
Notes :
1. Do not put your script in same folder as images, because it will try to open your script as a image, and throw an error.
2. len(clrs) actually shows how many colors are present in an image. If its 1, means image is of one color.
import Image, os
import os
path = "C:\\Users\\Ajju\\Desktop\\test_images"
for filename in os.listdir(path):
img = Image.open(path + '\\' + filename)
clrs = img.getcolors()
print filename, len(clrs)
if len(clrs) == 1:
os.remove(path + '\\' + filename)
Notes :
1. Do not put your script in same folder as images, because it will try to open your script as a image, and throw an error.
2. len(clrs) actually shows how many colors are present in an image. If its 1, means image is of one color.
Comments
Post a Comment