简体   繁体   中英

Convert an array into image

I have a 2Darray named C containing pixels in its indexes. How to view the image that is formed by that pixels value, A image can be represented by array. No wi am trying the reverse process, I wanna see only grayscale image since array named C has only one value per index. Doing programming in python

Here goes my code http://pastebin.com/qmnKrtzu

getting error in this line

ime = Image.fromarray(c)
ime.save("your_file.jpeg")

ime = Image.fromarray(c_array) arr = obj.__array_interface__ AttributeError: 'list' object has no attribute '__array_interface__'

That's much better with the code; thanks. In the future, please remember to cut down the code to the minimal level and post it in the original question. An external link doesn't get nearly as much attention.

Your problem is that Image.fromarray requires an array as input; you gave it a list. You did originally convert your list, c , to an array, but you didn't keep the array. I think you need this at lines 18 and 41 from your pastebin code, where I've added references to c_array:

c = [[0]*k*im.width for i in range(k*im.height)]
c_array = np.asarray(c)
...
ime = Image.fromarray(c_array)
ime.save("your_file.jpeg")

You can simply use c. values to convert dataframe into an array

 ime = Image.fromarray(c.values) ime.save("your_file.jpeg") 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM