# 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.

#### Conclusion

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].

Infos

1. Wolfram Alpha: https://www.wolframalpha.com
3. Mathematica documentation: http://reference.wolfram.com/mathematica/guide/Mathematica.html
4. RPi Low-level peripherals: http://elinux.org/RPi_Low-level_peripherals
5. Wolfram Community Raspberry Pi Forum: http://comunity.wolfram.com/content?curTag=raspberry%20pi
6. "Rasp Pi Camera Module" by Aaron Shaw, Raspberry Pi Geek, issue 02, 2013, pg. 8: http://www.raspberry-pi-geek.com/Archive/2013/02/Working-with-the-Raspberry-Pi-camera-module
7. Camera board setup: http://www.raspberrypi.org/camera
8. Raspberry Pi Camera board documentation: http://www.raspberrypi.org/wp-content/uploads/2013/07/RasPiCam-Documentation.pdf
9. Mathematica image processing tools: http://reference.wolfram.com/mathematica/guide/ImageProcessing.html
10. Wolfram language documentation: http://reference.wolfram.com/language/

The Author

Aaron Shaw is a volunteer at The MagPi magazine (http://www.themagpi.com), a magazine dedicated to Raspberry Pi users. He also founded Pi Supply (http://www.pi-supply.com) with a Kickstarter-funded add-on board for the Raspberry Pi (http://kck.st/UVBXTE). 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 mailto:sales@pi-supply.com or via Twitter (@shawaj2).

Express-Checkout as PDF

Pages: 2

Price \$2.95
(incl. VAT)

SINGLE ISSUES

SUBSCRIPTIONS

TABLET & SMARTPHONE APPS

UK / Australia

## Related content

• Exploring the Pixy sensor with Mathematica

We show how to track objects and plot their movement using the Pixy camera and the Mathematica package that's included with Raspbian.

• The Pi Wire

Things move quickly in the Raspberry Pi ecosystem. This regular column rounds up the best Raspberry Pi and open hardware news to keep you up to date on the latest projects, products, and events.

• Math, Music, and Cat Toys

Welcome to Raspberry Pi Geek – the first and only print magazine dedicated to the amazing Raspberry Pi mini-PC and the open hardware revolution. We ring in the new and old in this issue. (Actually, nothing is really very old with the Raspberry Pi, but we follow up on some previous themes, including a report on how it went for the wind-turbine-powered Raspberry Pi we described last time.)

• On the DVD