










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Diwakar Panchamgam, TAMU Course Instructor: Professor Deepa Kundur
To introduce video compression using Discrete Cosine Transform (DCT) and encryption. To implement video compression and encryption in Simulink and in Real-time on the hardware. To provide exposure to the optimizations needed for the Real-time implementation on the board.
Prior to beginning, you must carefully read over this lab in order to plan how to implement the tasks assigned. Please highlight all the parts you need to show or answer for the TA, so that you do not miss any graded points during the in-lab component or for the report. For simulation: Please download the vipmem_Y.avi.file available on the course webpage. For Real-time implementation: A CMOS camera. An analog TV to view the output from the board. Cables to connect camera, board and TV.
In this age of dramatic technology shifts, one of the most significant has been the emergence of digital video as an important aspect of daily life [ 1 ]. Digital cameras and camera-equipped cell phones are enabling easy capturing, storing, and sharing valuable moments through digital images and video. Set-top boxes are being used to pause, record, and stream live television signal over broadband networks to different locations, while smart camera systems are providing peace of mind through intelligent scene surveillance. Of course, all of these innovative multimedia products would not have materialized without efficient, optimized implementations of practical signal and image processing algorithms on embedded platforms, where constraints are placed not only on system size, cost, and power consumption, but also on the interval of time in which processed information must be made available[ 2 ]. A common theme in real-time image/video processing systems is how to deal with their vast amounts of data and computations [ 2 ]. For example, a typical digital video camera capturing VGA- resolution quality, color video (640 × 480) at 30fps outputs 27 million pixels per second. If we consider a gray scale image, each pixel is represented by 8bits and so we need a bandwidth of 216 Mbps to transmit VGA-resolution video. Therefore, video compression is frequently used to decrease the amount of data transmitted over a channel. Discrete Cosine Transform (DCT) is one of the techniques used in compressing video.
In this lab we use the DCT block from the Video Processing Library in Simulink. Still, it is useful to understand the various steps in computing a DCT on an image as given below.
Figure 5(a) : Original Image [3]. Figure 5(b): R=3 (86% compression) [3]. Figure 5(c): R=2 (93% compression) [3]. Figure 5(d): R=1 ( 98 % compression) [3].
For encrypting the video we perform additional actions after Step 3 (discussed on Page 3). Just for recap, in Step 3 we select an RxR matrix from the computed 8x8 block of DCT coefficients. To add encryption to the block of RxR DCT co-efficients, we multiply it with a scrambling matrix as shown in Figure 6 below. Please note that this is element-wise matrix multiplication and not the usual matrix multiplication. Figure 6: Scrambling process.
For decrypting the video we perform additional actions before Step 4 (discussed on Page 3). Just for recap, in Step 4 we apply IDCT on the RxR block of DCT co-efficients. Before computing IDCT we multiply the scrambled RxR block of DCT co-efficients with the de-scrambling matrix as shown in Figure
First we implement video compression and encryption in Simulation and then in Real-time on the C6437 board.
The goal of this lab is to, in part, build and test the following Simulink model shown in Figure 8.
Figure 9: Compression and Encryption Simulink Model to be implemented. a) Add the 2-D DCT block from Video and Image Processing Blockset → Transforms. Do not change any of the parameters in this block and leave them at their default values. Now we have computed the DCT on an 8x8 block of pixels. b) Next we have to select a RxR block from the 8x8 block of DCT co-efficients. In this lab we set R=4 i.e. 50% compression. We use the Selector block from Simulink → Signal Routing. Set the Number of input dimensions to “2” and Index mode to “Zero-based.” Also set the Index option to “Starting index (dialog) and Index to “0.” Finally set the Output Size to “4.” c) In this step we multiply the 4x4 block of DCT co-efficients with the Scrambling matrix. This could be done using Matrix Multiply block, but instead we use Embedded MATLAB Function block from Simulink → User-Defined Functions. This is to introduce the concept of embedding MATLAB code in a Simulink model. In the Embedded MATLAB function block we can write normal MATLAB function with an input variable and an output variable. The input variable ‘u’ in our case would be the block of 4x4 DCT co-efficients. The output variable ‘y’ in our case would be the product of input variable with our scrambling matrix. The code for the function is given in Figure 10. function y = fcn(u) MASK= [ 1 - 1 1 - 1;
Figure 1 1 : Decompression and Decryption Simulink Model to be implemented. a) First we add the Embedded MATLAB function block where we write MATLAB code to descramble. The input variable ‘u’ in our case would be the block of 4x4 scrambled DCT co- efficients. The output variable ‘y’ in our case would be the product of input variable with our descrambling matrix. The code for the function is given below in Figure 1 1. function y = fcn(u) MASK= [ 1 - 1 1 - 1;
Here we implement video compression and encryption in real-time on the C6437 board. The real- time implementation would be conceptually similar to the simulation, but would have significant changes to make it run in real-time on the board. To understand the limitations of the board, let us compare the processing capabilities: In simulation we are running it on a personal computer having a quad-core processor running at 2GHz whereas the DM6437 has a single core processor running at 500MHz. One naïve solution would be to go for a board with higher processing capabilities say with a processor running at 2GHz. Then not only have we increased the cost of the board due to the upgrade but also it increases the power consumption drastically. In case of mobile devices it would be a fatal flaw. For example, how would like if you have to charge your cell phone every 4 hours to use it? Thus we have an engineering problem at hand: coming up with a solution within the given constraints. The solution would be to optimize our original simulation to make it run in real-time on the board. In some cases where our best optimization is not sufficient to make it run in real-time, then we have to make some judicious trade-off decisions. These two principles would be further explained in the steps below where we create the Simulink model given in Figure 14. Please note that when your project is not working it would appear that getting a powerful board is the obvious solution , but it is not the right solution for reasons mentioned above. The current processor DM6437 is powerful enough and is being used in many real-time applications such as rear-view camera assisted parking in current cars. Figure 1 4: Real-time implementation of Video Compression and Encryption. Input blocks:
Add the Selector block from Simulink → Signal Routing. Set the Number of input dimensions to “2” and Index mode to “Zero-based.” Also set the Index option to “Starting index (dialog) and Index to “0.” Finally set the Output Size to “3.” Thus, we are going to choose a 3x3 block to transmit from the 4x4 block of DCT co-efficients computed, giving us a compression of 25%. Next we have to create a scrambling matrix to multiply the selected block of 3x3 DCT co- efficients as shown in Figure 1 8. Add two Constant blocks from Simulink → Commonly used blocks and set their values to “1” and “-1.” Make sure to set the Output data type to “Single.” Add Create 3x3 matrix block from Aerospace Blockset → Utilities → Math operations. Add Matrix Multiply block from Signal Processing Blockset → Math Functions → Matrices and Linear Algebra → Matrix Operations. Set Number of inputs to “2” and Multiplication to “Element wise.” Set the Output data type to “Single.” Optimization tip: Instead of writing our code in an Embedded MATLAB function block as we did in Simulation, we directly multiplied the 3x3 block with a Scrambling matrix. The reason is this would easier for the Simulink compiler to optimize as we are using predefined blocks. Optimization tip: We could greatly optimize the matrix multiplication if we use the Matrix Multiply blocks given in Target Support Package → Supported Processors → Texas Instruments C6000 → Optimized Blocks → C64X DSP Library. Please note that the matrix dimensions should be a multiple of 32 to take advantage of the 32bit internal memory bus. This optimization is left to the student to be implemented. Figure 1 8 : Scrambling matrix subsystem d) Next we create the IDCT_and_Unscrambling subsystem as shown in Figure 19. To create a place holder for this subsystem in the main Simulink file, we add a Block Processing block from Video and Image Processing Blockset → Utilities. In the parameters for the Block Processing block, set the Number of inputs to “1” and the Number of outputs to “1.” Set the Block size to “{[ 3 3 ]}” and Overlap to “{[0 0]}.” Set the Traverse order to “Row-wise.” Now click on the Open subsystem button and then add the blocks as shown in Figure 19.
Figure 1 9 : IDCT and Unscrambling subsystem. Add DIP block from Target Support Package → Supported Processors → Texas Instruments C6000 → Board Support. Set DIP switch to “SW4 (0)”. We use the DIP switch to switch our output display between CompressedVideo and ScrambledVideo. As shown in Figure 1 8 , we create a Descrambling Matrix block. Please note that both Scrambling Matrix block discussed in Figure 17 and this block are the same. Add two “Constant” blocks from Simulink → Commonly used blocks and set their values to “1” and “-1.” Make sure to set the Output data type to “Single.” Add Create 3x3 matrix block from Aerospace Blockset → Utilities → Math operations. Repeat the above step to create an Identity Matrix block. Here we use only one constant with value set to “1”. Add a Multiport Switch block from Simulink → Commonly used blocks. Set Number of Inputs to “2” and Output data type to “Single.” Add Matrix Multiply block from Signal Processing Blockset → Math Functions → Matrices and Linear Algebra → Matrix Operations. Set Number of inputs to “2” and Multiplication to “Element wise.” Set the Output data type to “Single.” Add the Image Pad block from Video and Image Processing Blockset → Utilities. Set the Method to “Constant” and Pad value source to “Specify via dialog”. Set the Pad value to “0” and Specify to “Pad size”. As we would be padding the 3x3 block to the right and bottom we set Pad rows at to “Right” and Pad columns at to “Bottom”. We set the Pad size along rows and Pad size along columns to “1”. Add the 2-D IDCT block from Video and Image Processing Blockset → Transforms. Do not change any of the parameters in this block and leave them at their default values. Now we have computed the IDCT on a 4 x 4 block of pixels At the end after all processing has been done, we need to convert the data type back to uint as it takes less memory space than single. Add Image Data Type Conversion block from Video and Image Processing Blockset → Conversions. Set the Output data type to “uint.
Figure 20: Inefficient implementation of Text Subsystem. Figure 21 : Optimized implementation of Text Subsystem.