Ask Your Question
1

Read bitmap into 2D array?

asked 10 years ago

v_2e gravatar image

How can I read the bitmap image file into a two-dimensional list of numbers?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 10 years ago

tmonteil gravatar image

updated 10 years ago

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)
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 10 years ago

Seen: 3,794 times

Last updated: Jun 12 '14