How to apply image effects to pictures on Raspberry Pi

Like a common pocket camera which has a built-in function to add various effects on captured photos, Raspberry Pi camera board ("raspi cam") can actually do the same. With the help of raspistill camera control options, we can add the image effects function like we have in a pocket camera.

There are three comman-line applications which can be utilized for taking videos or pictures with raspi cam, and one of them is the raspistill application. The raspistill tool offers various camera control options such as sharpness, contrast, brightness, saturation, ISO, exposure, automatic white balance (AWB), image effects.

In this article I will show how to apply exposure, AWB, and other image effects with raspistill while capturing pictures using raspi cam. To automate the process, I wrote a simple Python script which takes pictures and automatically applies a series of image effects to the pictures. The raspi cam documentation describes available types of the exposure, AWB, and image effects. In total, the raspi cam offers 16 types of image effects, 12 types of exposure, and 10 types of AWB values.

The simple Python script looks like the following.

import os
import time
import subprocess
for ex in list_ex:
    for awb in list_awb:
        for ifx in list_ifx:
            cmd='raspistill -o '+filename+' -n -t 1000 -ex '+ex+' -awb '+awb+' -ifx '+ifx+' -w 640 -h 480'
            print "["+str(x)+"]-"+ex+"_"+awb+"_"+ifx+".jpg"
print "End of image capture"

The Python script operates as follows. First, create three array/list variable for the exposure, AWB and image effects. In the example, we use 2 types of exposure, 3 types of AWB, and 13 types of image effects values. Then make nested loops for applying the value of the three variables that we have. Inside the nested loop, execute the raspistill application. We specify (1) the output filename; (2) exposure value; (3) AWB value; (4) image effect value; (5) the time to take a photo, which is set to 1 second; and (6) the size of the photo, which is set to 640x480px. This Python script will create 78 different versions of a captured photo with a combination of 2 types of exposure, 3 types of AWB, and 13 types of image effects.

To execute the Python script, simply type:

$ python

Here is the first round of the sample result.


For those who are more interested, there is another way to access and control the raspi cam besides raspistill. Picamera a pure Python interface which provides APIs for accessing and controlling raspi cam, so that one can build a complex program for utilizing raspi cam according to their needs. If you are skilled at Python, picamera is a good feature-complete interface for implementing your raspi cam project. The picamera interface is included by default in the recent image of Raspbian. If your Raspberry Pi operating system is not new or not Raspbian, you can install it on your system as follows.

First, install pip on your system by following this guideline.

Then, install picamera as follows.

$ sudo pip install picamera

Refer to the official documentation on how to use picamera.

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Kristophorus Hadiono is a Linux enthusiast and a teacher in private higher educations in Indonesia. He uses Linux for his daily computing, also when he teaches his students. He is currently continuing his education with government scholarship at a private university in Bangkok, Thailand.

Latest posts by Kristophorus Hadiono (see all)

Leave a comment

Your email address will not be published. Required fields are marked *