# Load image bitmap into array

**URL:** <https://www.ruby-forum.com/t/load-image-bitmap-into-array/155516>\
**Category:** Ruby\
**Created:** [December 12, 2008, 8:36pm UTC](https://www.ruby-forum.com/t/load-image-bitmap-into-array/155516 "2008-12-12T20:36:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snaggy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@snaggy](https://www.ruby-forum.com/u/snaggy)\
**Post date:** [December 12, 2008, 8:36pm UTC](https://www.ruby-forum.com/t/load-image-bitmap-into-array/155516/1 "2008-12-12T20:36:04Z")

</div>

I’m trying to load a grayscale image (some standard format will do,  
jpeg, png, bmp etc…) into an array, where I can access every pixel by  
its coohrdinates and where every pixel is described by a single number  
(0…255 8bit) from white to black.

How can I do that? I only need to read, not write images. It’s for  
analysing them…

thanks  
Luca

---

<div class="post-metadata">

**Author:** ![snaggy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@snaggy](https://www.ruby-forum.com/u/snaggy)\
**Post date:** [December 12, 2008, 8:55pm UTC](https://www.ruby-forum.com/t/load-image-bitmap-into-array/155516/2 "2008-12-12T20:55:23Z")

</div>

16 bit is fine as well.  
I’ll try it out as soon as I can  
thanks

---

<div class="post-metadata">

**Author:** ![snaggy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/cdc98d/32.png) [@snaggy](https://www.ruby-forum.com/u/snaggy)\
**Post date:** [December 12, 2008, 8:48pm UTC](https://www.ruby-forum.com/t/load-image-bitmap-into-array/155516/3 "2008-12-12T20:48:31Z")

</div>

Snaggy wrote:

> I’m trying to load a grayscale image (some standard format will do,  
> jpeg, png, bmp etc…) into an array, where I can access every pixel by  
> its coohrdinates and where every pixel is described by a single number  
> (0…255 8bit) from white to black.
> 
> How can I do that? I only need to read, not write images. It’s for  
> analysing them…

You can do that with RMagick’s Image#view.

However, the quantum range will depend on how ImageMagick is configured.  
If you require 0-255 then you’ll need to make sure to install  
ImageMagick configured with --quantum-depth=8. Most of the pre-built  
ImageMagick packages that you get with Ubuntu or RedHat are built with  
–quantum-depth=16 so the quantum range is 0-65535.

Image#view doc here:  
[http://studio.imagemagick.org/RMagick/doc/image3.html#view](http://studio.imagemagick.org/RMagick/doc/image3.html#view)  
–with-quantum-depth info here:  
[http://www.imagemagick.org/script/advanced-unix-installation.php#linux](http://www.imagemagick.org/script/advanced-unix-installation.php#linux)
