Products & Services Solutions Academia Support User Community Company

Learn more about Video and Image Processing Blockset   

Image Compression

Overview of Image Compression

The following sections use a two-part example to show how to build a Simulink model that is capable of image compression. In the first part of the example, the input image is divided into blocks and the two-dimensional DCT is computed for each block. The DCT coefficients are then quantized, coded, and transmitted. The receiver in the second part of the example decodes the quantized DCT coefficients, computes the inverse two-dimensional DCT of each block, and then puts the blocks back together into a single image. Although there is some loss of quality in the reconstructed image, it is recognizable as an approximation of the original image.

Compressing an Image

You can use image compression to reduce the size of an image before you transmit it. The compressed image retains many of the original image's features but requires less bandwidth. In this topic, you use the 2-D DCT and Selector blocks to compress an intensity image:

  1. Create a new Simulink model, and add to it the blocks shown in the following table.

    Block

    Library

    Quantity

    Image From File

    Video and Image Processing Blockset > Sources

    1

    Block Processing

    Video and Image Processing Blockset > Utilities

    2

    Video Viewer

    Video and Image Processing Blockset > Sinks

    2

  2. Position the blocks as shown in the following figure.

    You are now ready to set your block parameters by double-clicking the blocks, modifying the block parameter values, and clicking OK.

  3. Use the Image From File block to import the intensity image into your model. Set the block parameters as follows:

    • Main pane, File name = cameraman.tif

    • Data Types pane, Output data type = double

  4. Use the Video Viewer block to view the original intensity image. This image is a 256-by-256 matrix of 8-bit unsigned integer values. Accept the default parameters.

  5. The first Block Processing block represents the transmission portion of the block diagram. This block sends 8-by-8 submatrices of the original matrix to the block's subsystem for processing. Use this block when you want to perform block-based processing on large input images. To view the subsystem, double-click the block and click Open Subsystem.

    The Block Processing block's subsystem opens.

    You can drag blocks into this subsystem to process the submatrices.

  6. Add the following blocks to your subsystem.

    Block

    Library

    Quantity

    2-D DCT

    Video and Image Processing Blockset > Transforms

    1

    Selector

    Simulink > Signal Routing

    1

  7. Connect the blocks as shown in the following figure.

  8. The 2-D DCT block takes the two-dimensional DCT of each submatrix. This process puts most of the energy in the image into the upper left corner of the resulting matrix. Use the default parameters.

  9. Use the Selector block to extract the upper left corner of the submatrix. Set the block parameters as follows:

    • Number of input dimensions = 2

    • Index mode = Zero-based

    • 1

      • Index Option = Starting index (dialog)

      • Index = 0

      • Output Size = 4

    • 2

      • Index Option = Starting index (dialog)

      • Index = 0

      • Output Size = 4

    You are using the Selector block to compress the image by extracting the upper left corner of the submatrix, which contains the high energy image coefficients. You want to transmit only this portion of the submatrix because it requires less bandwidth than transmitting the entire submatrix.

  10. Close the subsystem and the Block Processing dialog box.

You have now configured the Block Processing and 2-D DCT blocks to compress an image for transmission. In Viewing the Compressed Image, you use the 2-D IDCT block to transform the image back to the time domain. Then, you view the compressed image.

Viewing the Compressed Image

In Compressing an Image, you compressed an image using the 2-D DCT and Selector blocks. Now, you can use the 2-D IDCT block to transform the image back to the time domain and view the result:

  1. If you have not already done so, set the Image From File block to import the intensity image into your model. Set the block parameters as follows:

    • Main pane, File name = cameraman.tif

    • Data Types pane, Output data type = double

  2. If the model you created in Compressing an Image is not open on your desktop, you can open an equivalent model by typing

    doc_compressing_an_image

    at the MATLAB command prompt.

  3. Use the Block Processing1 block to set the size of the submatrices that the block passes to the subsystem. Set the Block size parameter to {[4 4]}.

  4. Open the block's subsystem by clicking Open Subsystem, and add the following blocks to it.

    Block

    Library

    Quantity

    Image Pad

    Video and Image Processing Blockset > Utilities

    1

    2-D IDCT

    Video and Image Processing Blockset > Transforms

    1

  5. Connect the blocks as shown in the following figure.

  6. Use the Image Pad block to zero pad the 4-by-4 submatrix back to its original 8-by-8 size. Set the block parameters as follows:

    • Pad rows at = Right

    • Pad size along rows = 4

    • Pad columns at = Bottom

    • Pad size along columns = 4

    Because zeros are replacing the low energy transform coefficients, the output image is an approximation of the original image.

  7. The 2-D IDCT block takes the inverse two-dimensional DCT of the submatrices. Accept the default parameters.

  8. Close the subsystem and the Block Processing1 dialog box.

  9. Use the Video Viewer1 block to view the compressed image. Accept the default parameters.

  10. Connect the blocks as shown in the following figure.

  11. Set the configuration parameters. Open the Configuration dialog box by selecting Configuration Parameters from the Simulation menu. Set the parameters as follows:

    • Solver pane, Stop time = 0

    • Solver pane, Type = Fixed-step

    • Solver pane, Solver = Discrete (no continuous states)

  12. Run the model.

    The original image is displayed in the Video Viewer window.

    The compressed image is displayed in the Video Viewer1 window. The compressed image is not as clear as the original image. However, it still contains many of its features.

In this example, you used the 2-D DCT, Image Pad 2-D IDCT, and Block Processing blocks to compress an image. For more information on these blocks, see the 2-D DCT, Image Pad, 2-D IDCT, and Block Processing block reference pages in the Video and Image Processing Blockset Reference. For information on the Selector block, see the Simulink documentation. For more information on sharpening an image, see .

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS