Programming P1 Filtering the Images

Back to Programming page

Goal: Learn image filters

    • Remove noise by blurring filters: Gaussian, mean and median filters.
    • Detect edges by directional filters: Sobel and Laplacian files.

Readings and sample codes

    • OpenCV 3 computer vision application programming cookbook. R. Laganière, Packt Publishing, 2017. [Book URL]
      • Chapter 6 Filtering the images ( PDF, code )
      • Please see the README.txt for more details of sample codes.
    • You can use the provided sample codes to practice image filters.


    • Write two program codes by yourself: denoise.cpp and edge_detection.cpp by the instruction in PDF.
    • All the test images in your program should not be the book's example images. You should use your own images.
    • denoise.cpp: write a program code to run Gaussian, Mean, and Median filters for one image.
      • You have to change kernel size and compare the blurring results among filters and among kernel sizes.
      • Then you have to add salt-and-pepper noise and run the three filters again. You have to change kernel size and compare the denoise results among filters and among kernel sizes.
    • edge_detection.cpp: write a program code to run Sobel and Laplacian filters
      • You have to use your images to run both Sobel and Laplacian filters. Compare the results of edge images.
    • Option: Edge detection can be used to sharpen images. Add the original image with its edge image. The result image will become a sharp image. An example is shown in the bottom of this web page.


    • Create a "single" and "separate" report page with description texts and a lot of pictures for your programs.
    • Requirements of the report page:
      • For each program code, you have to write 4 parts: (1) goal of this code, (2) theory and principle of the filter, (3) code segment explanation, and (4) result comparison.
      • Use "your image" to run your programs.
      • Change parameters of algorithm's functions to get different result images.
      • Compare and discuss the result images, and explain why the change of parameters can produce different results.

Original image

Filtered image

Sharpened image