0

I have a CSV containing n records and it is filled with absolute paths to the images. I'd like to import those images into a numpy matrix.

data in csv

blackPanther
  • 181
  • 1
  • 3
  • 14

2 Answers2

1
import pandas as pd
from PIL import Image
import numpy as np

def load_image( infilename ) :
  img = Image.open( infilename )
  img.load()
  data = np.asarray( img, dtype="int32" )
  return data

df = pd.read_csv (r'Path where the CSV file is stored\File name.csv')

for i in range(len(df)) : 
  print(load_image(df.iloc[i, 0]))

You can store the returned values in list if you want else directly use.

SahilDesai
  • 512
  • 3
  • 6
0

You can use the pandas read_csv function.

import pandas as pd

df = pd.read_csv (r'Path where the CSV file is stored\File name.csv')
print (df)

Source: https://datatofish.com/import-csv-file-python-using-pandas/

Andrew Halpern
  • 514
  • 3
  • 6