I have a dataset of images. I have successfully iterated through my directories and subdirectories to store the images into numpy array.
I have used the following statement:
Image_array = np.array(Image_array) My array size is: 100x224x224
This works fine and the images get stored properly. However, I am now trying to save this numpy array into a CSV file. I have flattened the numpy array and have saved it in an array.csv file as shown below:
array = array.flatten('F') np.savetxt('array.csv', array, delimiter=',', fmt='%d') The above code just creates 1 CSV file, with one column with the pixel values.
I then attempted to read the CSV data back into a numpy array but the data is heavily messed up when loading as the image is just blurred. The array also displays with '.' after each number which it was not doing prior.
filename = "array.csv" data = np.loadtxt(filename, delimiter=',') new= np.array((data).reshape(100,224,224),order='F') Am I missing something? please assist?
np.save/loadwill easily save and reload the array, but the file isn't text. To usecsvyou have to make your array 2d, and apply a reshape after loading.arr.reshape(100,224*224)is a possible reshape. Or if you want more rows than columns(100*224, 224).