Keywords: front-page

## Lab: Convolution Principles

[Exercises] [Workspace]

Purpose: The purpose of this lab exercise is to experiment with the concepts of linear and circular convolution, and to compare the two methods.

At the time this lesson was prepared, the linear operator does not output a larger image as explained. In the implementation, the output size is the same as the input size image.

In this experiment the image $DIP/data/draw-small.kdf is used. It is a small 32 x 32 image with floating point pixels with values 0.0 and 1.0.

Activities:

1. Since the images used in this experiment are small (32x32) and (64x64), create an image zoomed by a factor of 4, using the operators Expand and Display Image. Read and display the image zoomed $DIP/data/draw-small.kdf. Remember that the expanded version is for display purpose only, not to be processed.

   1. Glyphs:Input/Output:Data Files:User defined
   2. Glyphs:Data Manip:Size & Region Operators:Expand
   3. Glyphs:Visualization:Non-Interactive Display:Display Image

2. Convolution kernels

   1. Build a shifted h(2,2) = 1 kernel: This kernel is a 3x3 image, where all values are zero, except for the position (2,2), which is:

      1. Use the operator Impulse to create the kernel, and verify it using Print Data and File Viewer.
      2. Glyphs:Input/Output:Generate Data:Impulse
      3. Glyphs:Input/Output:Information:Print Data
      4. Glyphs:Input/Output:Information:File Viewer

   2. Build a 3x3 average kernel using the operator Constant. The sum of all pixels in the kernel should add up to 1. Use Print Data and File Viewer to verify the kernel.

      1. Glyphs:Input/Output:Generate Data:Constant
      2. Glyphs:Input/Output:Information:Print Data
      3. Glyphs:Input/Output:Information:File Viewer

   3. Sobel X kernel

      1. Read and print the contents of the ASCII file $DIP/data/sobel_x.ascii using the User defined and File Viewer operators.
      2. Glyphs:Input/Output:Data Files:User defined
      3. Glyphs:Input/Output:Information:File Viewer

3. For all three kernels, perform boths linear and circular convolutions using the $DIP/data/draw-small.kdf image. Use LinearOp (Linear Operator) to perform the convolution. Expand all by a factor of 4 with Expand operator and display it with Display Image operator.

   1. Glyphs:Arithmetic:Linear Transforms:LinearOp (Linear Operator)
   2. Glyphs:Data Manip:Size & Region Operators:Expand
   3. Glyphs:Visualization:Non-Interactive Display:Display Image
   4. The LinearOp (Linear Operator) parameter "Kernel hotspot" determines the kernel origin. If it is not selected, by defaul the kernel origin it at position (0,0). In the case of the average and Sobel kernels, the kernel origin must be set at (1,1). In those cases, set the "Kernel hotspot" parameter to Width=1 and Height=1.

Exercises

1. Explain how the position of the extracted image is dependent on the kernel origin.

Khoros Workspace
Execute the visual program c6s1convolution.wk