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.

  • 4
    $\begingroup$ Try ImageData $\endgroup$
    – bill s
    Jan 19 '16 at 2:12
  • $\begingroup$ Could you be a little more specific, do you need a list of the of the gray scale numbers for each pixel? $\endgroup$
    – Bob Brooks
    Jan 19 '16 at 3:19
  • 1
    $\begingroup$ you may also check 'ImagePartition'. i = Import["ExampleData/lena.tif"] ImagePartition[i, {45}] // Grid $\endgroup$
    – 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.