def main(): filename = sys.argv[-1] try: im = Image.load(filename) im.verify( ) #I perform also verify, don't know if he sees other types o defects im.close() #reload is necessary in my case im = Image.load(filename) im.transpose(PIL.Image.FLIP_LEFT_RIGHT) im.close() except: #manage excetions here sys.exit(0) f = imageio.imread(filename, as_gray=True) try: imageio.verify(f) # do stuff except IOError: # filename not an image file sys.exit(0) def img_estim(img, thrshld): is_light = np.mean(img) > thrshld #print(np.mean(img)) #return 'light' if is_light else os.remove(filename) if is_light == 0: os.remove(filename) img_estim(f, 40)
def main(): filename = sys.argv[-1] try: im = Image.load(filename) im.verify() #Need to find defects im.close() #reload is needes to continue im = Image.load(filename) #im.transpose(PIL.Image.FLIP_LEFT_RIGHT) im.transpose(Image.FLIP_LEFT_RIGHT) im.close() except: #If Error -> Exit program sys.exit(0) f = imageio.imread(filename, as_gray=True) try: imageio.verify(f) # Verify more except IOError: # ERROR -> filename not an image file sys.exit(0) def img_estim(img, thrshld): is_light = np.mean(img) > thrshld #print(np.mean(img)) #return 'light' if is_light else os.remove(filename) # if is_light == 0: # os.remove(filename) img_estim(f, 40) print(img_estim(f, 40)) # if black is more that 255/100*40 (i think) print("") #new line
def main(): #filename = "./test_files/Clouds_test.jpg" filename = sys.argv[-1] print(filename) try: im = Image.load(filename) print("im loaded") im.verify( ) #I perform also verify, don't know if he sees other types o defects print("im verify") im.close() #reload is necessary in my case print("im close") im = Image.load(filename) print("load im again") im.transpose(PIL.Image.FLIP_LEFT_RIGHT) print("flip im") im.close() print("close im") except: #manage excetions here print("File load Failed") sys.exit(0) f = imageio.imread(filename, as_gray=True) try: imageio.verify(f) print("try verify file") # do stuff except IOError: # filename not an image file print("file is no image") sys.exit(0) def img_estim(img, thrshld): is_light = np.mean(img) > thrshld print(np.mean(img)) #return 'light' if is_light else os.remove(filename) if is_light == 0: # os.remove(filename) print("Delete this file") img_estim(f, 40) print(img_estim(f, 40))