Read bitmap into 2D array?
How can I read the bitmap image file into a two-dimensional list of numbers?
How can I read the bitmap image file into a two-dimensional list of numbers?
Since PIL is included within Sage, you can do:
from PIL import Image
img = Image.open("your_file.png")
Then, you can do:
list(img.getdata())
See img.<TAB>
to see avbailable commands. If you prefer to deal with numpy arrays:
from numpy import array
arr = array(img)
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2014-06-12 03:48:23 +0100
Seen: 3,746 times
Last updated: Jun 12 '14