The blur effect is an effect that results in a blurred image, out of focus, blur, and things like that.
But with OpenCV, we can recognize the code structure to make the image blur, and there are several techniques to blur an image that we will discuss in this part include:
The first technique is called averaging because the process of blurring the image is done by taking the average of the entire image and changing it to a new value.
To get a blur effect with this technique, we can use the function blur()
Create new Python file on your PYCharm with name averaging.
Copy an image to folder project.
Write the source code below.
import numpy as np
import cv2 as cv
img = cv.imread('test.jpg',1)
blur = cv.blur(img, (10,10))
cv.imshow('Old Image', img)
cv.imshow('Image After Blur', blur)
cv.waitKey(0)
cv.destroyAllWindows()
4 . Run it, and see output.
blur = cv.blur(img, (10,10))
In the above code, two arguments are (10,10) where the intent of 2 argument that is to regulate how high rate of bleeding to be obtained. The high value will result in the higher blur effect.
Another blur effect that can be used is Gaussian Blur which in OpenCV can be present through the GaussianBlur () function. The most basic Gaussian Blur structure is as follows:
cv.GaussianBlur (src (sigmaX, sigmaY), border)
Create new Python file on your PYCharm with name gaussian-blur.
Copy an image to folder project.
Write the source code below.
import numpy as np
import cv2 as cv
img = cv.imread('test.jpg',1)
blur = cv.GaussianBlur(img, (5,5),0)
cv.imshow('Old Image', img)
cv.imshow('Image After Gaussian Blur', blur)
cv.waitKey(0)
cv.destroyAllWindows()
4 . Run it, and see output.
blur = cv.GaussianBlur(img, (5,5),0)
the same explanation as above just this function add border function which set default 0
Median Blur can be used to minimize noise effects on the image. This blur technique can be used using the medianBlur () function.
Create new Python file on your PYCharm with name median-blur.
Copy an image to folder project. Attention! use noise-effect images for this technique.
Write the source code below.
import numpy as np
import cv2 as cv
img = cv.imread('noise.jpg',1)
blur = cv.medianBlur(img,5)
cv.imshow('Old Image', img)
cv.imshow('Image After Gaussian Blur', blur)
cv.waitKey(0)
cv.destroyAllWindows()
4 . Run it, and see output.
blur = cv.medianBlur(img,5)
Just use the two arguments src as img and its value is 5 to set the strength of the resulting blur.
Edge Detection is an algorithm that serves to detect the object line. One of the functions that can be used for Edge Detection is Canny ().
The structure for this Edge Detection function itself as follows:
cv.Canny (src, minVal, maxVal)
If you enter a low number in minVal or maxVal, the edge that will be in shape is much more detailed in than with the high inserted value.
Create new Python file on your PYCharm with name edge-detection.
Copy an image to folder project. Attention! use noise-effect images for this technique.
Write the source code below.
import numpy as np
import cv2 as cv
img = cv.imread('test.jpg',1)
blur = cv.Canny(img,50,60)
cv.imshow('Old Image', img)
cv.imshow('Image After Edge Detection', blur)
cv.waitKey(0)
cv.destroyAllWindows()
4 . Run it, and see output.
blur = cv.Canny(img,50,60)
Value 50 as minVal.
Value 60 as maxVal.
If the value in fox becomes smaller, then the edge will be much more detail.
Okay until here first learning about Python Digital Imaging with OpenCV [Blur Effect - Part 2]. For the third part will discuss how to draw with python language using OpenCV package.