png dataset to csv

38 views
Skip to first unread message

Rajenki Das

unread,
Jun 22, 2018, 1:38:04 AM6/22/18
to Keras-users
Hi 
There are around 150 png images, I am trying to make a csv file where each row will represent the array of pixels of each corresponding picture.

In the following code (blue text), I am repeatedly getting that NoneType object is not iterable. Can anyone identify the problem?
---------------------------------------------------------------------------------------------------------
from PIL import Image
import numpy as np
import sys
import os
import csv


format='.png'
myDir = "TL_Dataset/Hats and Caps (Processed)"

#Useful function
def createFileList(myDir, format='.png'):
    fileList = []
    print(myDir)
    for root, dirs, files in os.walk(myDir, topdown=False):
        for name in files:
            fullName = os.path.join(root, name)
            fileList.append(fullName)
    return fileList

# load the original image
myFileList = createFileList('TL_Dataset/Hats and Caps (Processed)')

for file in fileList:
    print(file)
    img_file = Image.open(file)
    # img_file.show()

    # get original image parameters...
    width, height = img_file.size
    format = img_file.format
    mode = img_file.mode


    # Save Greyscale values
    value = np.asarray(img_file.getdata(), dtype=np.int).reshape((img_file.size[1], img_file.size[0]))
    value = value.flatten()
    print(value)
    with open("img_pixels.csv", 'a') as f:
        writer = csv.writer(f)
        writer.writerow(value)
--------------------------------------------------------------------------------------------------------

Regards

--
Rajenki 


“But in my opinion, all things in nature occur mathematically.” 
― 
René Descartes

Rajenki Das

unread,
Jun 22, 2018, 10:23:02 AM6/22/18
to Keras-users
The problem is solved.
Reply all
Reply to author
Forward
0 new messages