We used some colorful props to make the color inversion noticeable. Figures 3 and 4 below show a snapshot of the video feed before and after the color inversion.
Snapshot before color inversion.
Snapshot after color inversion.
As an extension of this project, you can vary the constant value of 255 added to the individual RGB components. This simply shifts the RGB components of the image, giving interesting visual effects on the same image. You can be more interactive by setting the constant block to a value of 1 and adding a slider gain block. Now when you run this on the Raspberry Pi, you can adjust the slider gain and see the color inversion update instantly on the video display.
This project can be used to demonstrate how easy it is for young makers to get up and running with their first Raspberry Pi project in a few hours.
In this example, we'll walk through the implementation of an algorithm that can detect the edges on an input image from a webcam. You can use the same hardware as the previous example, where you have a USB webcam connected to the Raspberry Pi.
Edge detection is a fundamental tool in image processing. It aims at identifying points in a digital image where the brightness changes sharply. These points are typically organized into a set of curved line segments termed edges. Given that the image intensity may be regarded as a two-variable function, edges may be detected by computing its slope's local maxima.
The slope of a two-variable function may be easily determined by computing the gradient magnitude of that function. The slope's local maxima coordinates correspond to the local peaks of the gradient magnitude. An approximate and deterministic way to find such local maxima is to find where the slope function exceeds a given threshold.
Let's look at the top-level model shown in Figure 5. The Video Capture library block from Simulink generates three signals to represent color image data for each pixel. Y is the luma component (essentially a grayscale signal). Cb is the blue-difference chroma component, and Cr is the red-difference chroma component.
Simulink model with edge detection algorithm.
The grayscale image data is used as an input to the edge detection algorithm. The threshold block has a slider interface that allows you to tune the threshold while the algorithm is running on your Raspberry Pi.
Image processing projects are an attractive way of introducing hardware programming to young makers, especially because you can see the results immediately. The potentially steep learning curve associated with new programming languages is considerably reduced with graphical modeling tools such as Simulink. Not only does the combination of Raspberry Pi and Simulink enable users to get up and running quickly, but it also provides an easy way to interact and explore the image processing algorithm in Simulink while it's running on the Pi. Additionally, this combination is a great example of project-based learning, a current trend in using hands-on projects to reinforce conceptual learning.
Websites such as MakerZone, element14, Adafruit, and others are helping aspiring makers bring their projects to life, encouraging them to continue investing time, effort, and energy in engineering and science.