Ask Your Question
1

Read bitmap into 2D array?

asked 2014-06-11 20:48:23 -0600

v_2e gravatar image

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

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-06-12 00:57:24 -0600

tmonteil gravatar image

updated 2014-06-12 00:57:54 -0600

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)
edit flag offensive delete link more

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: 2014-06-11 20:48:23 -0600

Seen: 707 times

Last updated: Jun 12 '14