Mathematica and the Wolfram language on Raspberry Pi

Image Processing

Mathematica has a large number of built-in functions for image processing. I'll start with an image that has just been imported into Mathematica using the DeviceRead["RaspiCam"] function. Figure 12 shows my fluffy little dog Juno, who is very annoyed and wants her walk.

Figure 12: Juno, in this original image, will demonstrate some Mathematica image processing features.

Following are some examples of image processing functions (remember to press Shift+Enter to execute the commands). The function

ImageAdjust[image, {0.6, 0.2, 1.5}]

adjusts the contrast of the image by 0.6, adjusts the brightness by 0.2. and performs a gamma correction by raising the values to the power 1.5. The result of this command appears in Figure 13.

Figure 13: You can use Mathematica to adjust the contrast, brightness, and gamma correction.

Now I will process the original image again, this time using an image effect:

ImageEffect[image, {"SaltPepperNoise" , 0.1}]

This function adds salt and pepper noise to 0.1 (10%) of the image. The result of this processing effect is shown in Figure 14.

Figure 14: Adding salt and pepper noise to an image.

Other functions can help you analyze an image, rather than processing it, such a ImageHistogram[image]. This function plots a histogram of the pixel levels for each of the color channels in an image. The result of this histogram analysis is shown in Figure 15.

Figure 15: A histogram of pixel levels for each color channel.

These are just a few examples of some of the more basic image processing features of Mathematica. You will discover a large number of really powerful image processing tools at your disposal. Look for a full list at the Wolfram website [9]. I would highly recommend visiting that page and having a go with some of the functions yourself.

If you want to preserve the output of any of your processed images to the Raspberry Pi filesystem, save the command output to a variable:

processedimage = ImageAdjust[image, {0.6, 0.2, 1.5}]

The following command then exports the image and saves it to a file:

Export["/home/pi/ProcessedImage.jpg", processedimage]

This function saves your processed image with the file name ProcessedImage.jpg in the /home/pi folder.


I hope this introduction to Mathematica and the Wolfram language has been useful and inspires you at least to have a go with the software and programming in this impressively intuitive language. It is really difficult to do justice to a programming language like Wolfram and a software package like Mathematica in a single magazine article, so I would highly recommend visiting the documentation center for both the Wolfram language [10] and Mathematica [3]. Almost everyone reading this article will find something useful that could potentially make a job they are trying to achieve a whole lot easier.

Before the free release on Raspberry Pi, this software would have cost a fair bit, so it is definitely worth having a go with a piece of software that a lot of people would pay good money for – if for no other reason than to see what you have been missing out on.

Don't forget to keep us updated on your progress on the Raspberry Pi Geek Facebook page [11].


  1. Wolfram Alpha:
  2. Raspbian and NOOBS:
  3. Mathematica documentation:
  4. RPi Low-level peripherals:
  5. Wolfram Community Raspberry Pi Forum:
  6. "Rasp Pi Camera Module" by Aaron Shaw, Raspberry Pi Geek, issue 02, 2013, pg. 8:
  7. Camera board setup:
  8. Raspberry Pi Camera board documentation:
  9. Mathematica image processing tools:
  10. Wolfram language documentation:
  11. Raspberry Pi Geek Facebook page:

The Author

Aaron Shaw is a volunteer at The MagPi magazine (, a magazine dedicated to Raspberry Pi users. He also founded Pi Supply ( with a Kickstarter-funded add-on board for the Raspberry Pi ( Aaron is a final-year Automotive Engineering MEng student at the University of Leeds, currently spending a lot of time working on a Formula Student car. For help relating to this article, you can contact him through or via Twitter (@shawaj2).

Buy this article as PDF

Express-Checkout as PDF

Pages: 2

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content