This demo shows how to use the V4L2 Video Capture and the SDL Display blocks from the BeagleBoard™ block library to implement a black and white image inversion algorithm with a Simulink® model, and to run the model on BeagleBoard hardware.
Black and white image inversion refers to an image processing technique where light areas are mapped to dark, and dark areas are mapped to light. In other words, after image inversion black becomes white and white becomes black. An inverted black and white image can be thought of as a digital negative of the original image.
In this demo, the inversion algorithm will be applied to the Y component of the YCbCr 4:2:2 image captured from a USB camera. In this format, luminance information is stored as a single component Y, and chrominance information is stored as two color-difference components Cb and Cr. Cb represents the difference between the blue component and a reference value. Cr represents the difference between the red component and a reference value. The Y component of the image, for all practical purposes, when viewed represents a black and white rendition of the original color image. The Y, Cb and Cr components of the image are represented as uint8 values. That is the range of the values that Y component can take is from 0 to 255, with 0 representing black and 255 representing white.
Assuming that the intensity value at position of the image is , the inversion mapping is defined by . In this mapping a white pixel with intensity 255 is mapped to a black pixel with intensity 0 and vice versa.
- We recommend completing Getting Started with BeagleBoard Hardware demo.
To run this demo you will need the following hardware:
- BeagleBoard xM or BeagleBoard Cx hardware
- A compatible USB camera
(Optional) To display the output video on an external monitor you will need the following:
- A monitor with DVI-D connector
- HDMI/A male to DVI-D cable
- USB mouse and keyboard
In this task, you will connect a USB camera to your BeagleBoard hardware, and run the image inversion model on BeagleBoard hardware in External mode. When you run the model in External mode, the image is captured from the USB camera connected to the BeagleBoard hardware and the results of the image inversion is sent back to the host computer to be displayed by the on SDL Video Display block.
1. Connect a USB camera to a USB port of your BeagleBoard hardware.
2. Open the Image Inversion model.
3. In the Simulink model, double-click on the Inversion Algorithm subsystem and examine how the inversion algorithm is implemented.
4. Select Tools > Run on Target Hardware > Options.... Review the parameters on the page that opens. If you performed a Firmware Update, Board information will be automatically populated with the host name, user name and password of your BeagleBoard hardware. If you have not performed a Firmware Update or you want to change the board parameters, enter the IP address, user name and password of your BeagleBoard hardware.
5. Check on the Enable External mode option.
6. Select Tools > Run on Target Hardware > Run to run the model on BeagleBoard hardware.
7. Observe the display of inverted images on the host computer with the SDL Video Display block.
8. Press the Stop button on the model to stop model execution.
In this task, you will connect a monitor to BeagleBoard hardware. The video captured from the USB camera will be inverted by the model running on BeagleBoard hardware and displayed on the monitor connected to BeagleBoard hardware.
1. Using an HDMI to DVI-D cable, connect a monitor to the BeagleBoard hardware. The monitor, once connected, will display the Ubuntu Xfce desktop.
2. Connect a USB mouse and a keyboard to the BeagleBoard hardware's USB ports. Once connected, login to Ubuntu Xfce graphical desktop as you would to any Linux® computer. The default user name is 'ubuntu' and the default password is 'temppwd'.
You will now configure and run the image inversion model on BeagleBoard hardware as a standalone application. When you run the model, the image is captured from the USB camera connected to the BeagleBoard hardware and the results of the image inversion is displayed on the monitor connected to the BeagleBoard hardware.
3. Open the Image Inversion model.
4. Select Tools > Run on Target Hardware > Options.... Review the parameters on the page that opens. Uncheck the Enable External mode option.
5. Select Tools > Run on Target Hardware > Run to run the model on BeagleBoard hardware. On the monitor connected to BeagleBoard hardware, you will see black and white inverted images.
6. Stop the model running on the BeagleBoard hardware by executing the following on the MATLAB® command line
h = beagle; h.stop('beagleboard_communication');
- Change the value of the Constant block in the Inversion Algorithm subsystem while the Simulink model is running in External mode.
- Apply the inversion algorithm to Cb and Cr components in addition to the Y component to create a color negative.
- Implement image inversion in RGB color space.
This demo showed a Simulink model implementing an image inversion algorithm. V4L2 Video Capture and the SDL Video Display blocks from the BeagleBoard library were used to capture and display video data. The demo showed how the model may be run in External mod, and as a standalone application on BeagleBoard hardware.