0

I am trying to run the below code and calling a function from another notebook but i cant seem to figure out to load every image data in my directory.

for index, row in dataset.iterrows():
    x.append(array(ela_form(row[1], 90).resize((128, 128))).flatten() / 255.0)
    y.append(row[0])

The function iam calling is ela_form from another notebook which i imported.

def ela_form(path, quality):

    im_name = path
    rename_image = im_name.split('.')[0] + '.resaved.jpg'
    ELA_filename = im_name.split('.')[0] + '.ela.png'

    im = Image.open(im_name).convert('RGB')
    im.save(rename_image, 'JPEG', quality=quality)
    resaved_im = Image.open(rename_image)

    ela_image = ImageChops.difference(im, resaved_im)

    extrema = ela_image.getextrema()
    max_diff = max([ex[1] for ex in extrema])
    if max_diff == 0:
       max_diff = 1
   scale = 255.0 / max_diff

   ela_image = ImageEnhance.Brightness(ela_image).enhance(scale)

   return ela_image

My images are stored in 'dataset\Training_Data_Preprocessed'

Dataset.csv is stored in 'dataset\Dataset.csv

> Error:FileNotFoundError                         Traceback (most recent
> call last) <ipython-input-16-920134a3a471> in <module>
>       3 for index, row in dataset.iterrows():
>       4 
> ----> 5     x.append(array(ela_form(row[1], 90).resize((128, 128))).flatten() / 255.0)
>       6     y.append(row[0])
> 
> ~\Desktop\Jupyter Notebooks\ELA.ipynb in ela_form(path, quality)
> 
> D:\Anaconda\lib\site-packages\PIL\Image.py in open(fp, mode)    2807  
> 2808     if filename:
> -> 2809         fp = builtins.open(filename, "rb")    2810         exclusive_fp = True    2811 
> 
> FileNotFoundError: [Errno 2] No such file or directory: 'im1_o.bmp'
  • 1
    Does this answer your question? [How do I list all files of a directory?](https://stackoverflow.com/questions/3207219/how-do-i-list-all-files-of-a-directory) – BenedictWilkins Aug 01 '20 at 14:19
  • Actually the dataset.csv file has columns like ImageLabel (0/1) , ImageName and when i call the function ela_form(), it should read the image with respect to the csv list – Zubin Thomas Aug 01 '20 at 14:28
  • In which case, perhaps you need to provide the fully qualified path for each image. – BenedictWilkins Aug 01 '20 at 14:31
  • The dataset file contains a list of all image names and Label. My image directory contains 2 folders named 'Real' and 'Tampered' respectively that contains the images with respect to their label. With respect to the code above, how do i iterate through every file name in the list and from the image directory? – Zubin Thomas Aug 02 '20 at 10:01
  • The error is file not found, so there is something wrong with your file name(s). Try to include the directory of the images in file name for each image. – BenedictWilkins Aug 02 '20 at 11:07

0 Answers0