OpenCV Gaussian filtering
blur_img_cv = cv2.GaussianBlur(ba_img, (ksize, ksize), sigma)
Gaussian filtering in PIL.ImageFilter
from PIL import ImageFilter
pil_blur = ba_img.filter(ImageFilter.GaussianBlur(sigma))
Conversion between PIL filtering and OpenCV filtering
-
OpenCV filter is converted to PIL filter.
According to cv2.GaussianBlur(ba_img, (ksize, ksize), sigma) and ba_img.filter(ImageFilter.GaussianBlur(sigma)), the OpenCV filter function parameter is one more ksize parameter than PIL, and the sigma parameter is the same. Just convert directly. -
PIL filter is converted to OpenCV filter
OpenCV filter function has one more ksize filter parameter than PIL. It needs to calculate ksize according to sigma, which can be calculated according to the parameter of filter function in OpenCV, and it is guaranteed to be an odd number.
ksize = 2 × (sigma − 0.8 0.3 + 1) + 1 ksize=2 \times(\frac{sigma-0.8}{0.3}+1)+1k s i z e=2×(0.3sigma−0.8+1)+1ksize = int(2*((sigma-0.8)/0.3+1)+1) if ksize % 2.0 == 0: ksize = ksize + 1 blur_img_cv = cv2.GaussianBlur(ba_img, (ksize, ksize), sigma)
参考资料
OpenCV高斯滤波GaussianBlur
Why is Gaussian Filter different between cv2 and skimage?
For PIL.ImageFilter.GaussianBlur how what kernel is used and does the radius parameter relate to standard deviation?