Python Forum
convert images into pixel dataframe into csv file using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert images into pixel dataframe into csv file using python
#1
i want convert images to pixels

i do so

from PIL import Image
im = Image.open('image.jpg')

pixels = list(im.getdata())


result = []
counter = 0
for pixel in pixels:
counter += 1
result.append(['pixel'+ str(counter), pixel[1]])
return (result)
and get the result
['pixel1', 72], ['pixel2', 50], ['pixel3', 0], ['pixel4', 11], ['pixel5', 30], ['pixel6', 42], ['pixel7', 107], ['pixel8', 123]
here one picture

but there are many pictures, i want covert it all to pixels

the path
so i want take all picture from here
im = Image.open('C:\Users\Admin\Downloads\mypicture)
output in csv file?
each row it is one picture

Output:
pixel1 pixel. pixel158 pixel159 pixel160 pixel161 pixel162 pixel163 pixel164 pixel165 pixel166 pixel167 pixel168 pixel169 pixel170 pixel171 pixel172 1 0 … 0 191 250 253 93 0 0 0 0 0 0 0 0 0 0 2 0 … 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 pixel173 pixel174 pixel175 pixel176 1 0 0 0 0 2 0 0 16 179
how to do it correct?
Reply


Messages In This Thread
convert images into pixel dataframe into csv file using python - by synthex - Feb-14-2019, 11:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  export dataframe to file.txt dramauh 5 1,941 Apr-21-2022, 01:23 AM
Last Post: sarahroxon7
  Convert several columns to int in dataframe Krayna 2 2,426 May-21-2021, 08:55 AM
Last Post: Krayna
  Export dataframe to xlsx - Error "zipfile.BadZipFile: File is not a zip file" Baggio 10 62,399 Mar-12-2021, 01:02 PM
Last Post: buran
  How to form a dataframe reading separate dictionaries from .txt file? Doug 1 4,263 Nov-09-2020, 09:24 AM
Last Post: PsyPy
  Indirectlty convert string to float in JSON file WBPYTHON 6 5,957 May-06-2020, 12:09 PM
Last Post: WBPYTHON
  Convert dataframe string column to numeric in Python darpInd 1 2,311 Mar-14-2020, 10:07 AM
Last Post: ndc85430
  How to add a dataframe to an existing excel file wendysling 2 28,190 May-09-2019, 07:00 PM
Last Post: wendysling
  Insert images in a folder into dataframe tofi 0 5,413 Dec-14-2018, 08:05 PM
Last Post: tofi
  Write specific rows from pandas dataframe to csv file pradeepkumarbe 3 5,530 Oct-18-2018, 09:33 PM
Last Post: volcano63
  Python read Password protected excel and convert to Pandas DataFrame FORTITUDE 2 17,129 Aug-30-2018, 01:08 PM
Last Post: FORTITUDE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020