Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Try/Except Issue and Image Corruption

I’m try to test images to see if any are corrupt. They all come back false, corrupted, but I know most or all are fine. What am I doing wrong?

Thanks.

import glob
from PIL import Image
import os

directory = r'C:\Users\Jim Schmitz\Documents\Pyro\dogs-vs-cats\train\dogs'
os.chdir(directory)

images=glob.glob("*.jpg")

def verify_image(img_file):
    try:
        img = Image.open(img_file)
    except:
        return False
    return True
    
for image in images:
    bool = verify_image('image')

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’re passing the string 'image' as opposed to the filename image, your call should be verify_image(image). Also, bool is a built-in python object, try to refrain from using them as variable names.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading