Image effects with Python

Standard

Image effects are created by applying a convolution matrix (also known as kernel) to the image. This is a small matrix that slides through the original image and does a mathematical operation on the pixels for each position of the sliding window. Depending on the convolution matrix you get a different image effect. OpenCV has many of these effects integrated including guassian blur, laplacian and sobel.

Python code to do image effects: gaussian blur, laplacian, sobel:

Output:

Image effects

Object detection using Template Matching

Standard

We can use a technique called template matching to find a template  of size w \times h in an input image.  We use the function cv2.matchTemplate() which slides through the image and compares the overlapped patches of size w \times h against the input image using a statistical comparison method.

The template image can be anywhere inside the input image but it cannot be rotated, this is a limitation of template matching.  A full description of the function and formulas can be found here: http://docs.opencv.org/modules/imgproc/doc/object_detection.html?highlight=matchtemplate#matchtemplate

Output:
In this example I searched for the template image in the red box;

Image source: http://filmfabrikasi.com/wp-content/uploads/2012/08/x-men_3.jpg

Template matching in Python:

Object detection with template matching in C++

 

Uncategorized