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.
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.
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.
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.
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
- Wolfram Alpha: https://www.wolframalpha.com
- Raspbian and NOOBS: http://www.raspberrypi.org/downloads/
- Mathematica documentation: http://reference.wolfram.com/mathematica/guide/Mathematica.html
- RPi Low-level peripherals: http://elinux.org/RPi_Low-level_peripherals
- Wolfram Community Raspberry Pi Forum: http://comunity.wolfram.com/content?curTag=raspberry%20pi
- "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
- Camera board setup: http://www.raspberrypi.org/camera
- Raspberry Pi Camera board documentation: http://www.raspberrypi.org/wp-content/uploads/2013/07/RasPiCam-Documentation.pdf
- Mathematica image processing tools: http://reference.wolfram.com/mathematica/guide/ImageProcessing.html
- Wolfram language documentation: http://reference.wolfram.com/language/
- Raspberry Pi Geek Facebook page: https://www.facebook.com/RasPiGeek
Buy this article as PDF
Pages: 2
(incl. VAT)