# Splitting a rasterized image into its squares

I have rasterized an image using the following code:

i = Import["ExampleData/lena.tif"]
Rasterize[ColorConvert[i, "Grayscale"], RasterSize -> 45]


This produces the following result:

Now, how can I get a list of all the "squares" in the image? I've tried a lot of things but with no success.

• Try ImageData – bill s Jan 19 '16 at 2:12
• Could you be a little more specific, do you need a list of the of the gray scale numbers for each pixel? – Bob Brooks Jan 19 '16 at 3:19
• you may also check 'ImagePartition'. i = Import["ExampleData/lena.tif"] ImagePartition[i, {45}] // Grid – s.s.o Jan 19 '16 at 9:53

Do not use Rasterize for this! By default Rasterize will create a Graphics object that shows how some notebook element would display on-screen. This means that precision is bad and you risk introducing artefacts due to rounding errors (such as a one pixel margin, etc.) The result may depend on your operating system, on screen DPI settings and other things that influence how Mathematica draws things on-screen.
What you need here is ImageResize, which gives you control over the resampling method used and gives an Image object as the result. Use ImageData to extract the pixel values from the Image.