Ask Your Question
1

Read bitmap into 2D array?

asked 2014-06-12 03:48:23 +0100

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 07:57:24 +0100

tmonteil gravatar image

updated 2014-06-12 07:57:54 +0100

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-12 03:48:23 +0100

Seen: 3,747 times

Last updated: Jun 12 '14