본문으로 바로가기

Image filtering (Blurring images)

category AI/Computer Vision 2021. 3. 23. 18:41

Blurring image

1) 개요

    - Blur the image by using low-pass filter.

    - Simply this smoothens the image and removes a noises.

 

2) 방법

ref : http://www.cs.cmu.edu/~16385/lectures/lecture2.pdf

    - The (grayscale) image I is convolved with various kinds of filters. (2D convolution)

ref : http://www.cs.cmu.edu/~16385/lectures/lecture2.pdf

    - 2D convolution with separable filter is equivalent to two 1D convolutions.

 

3) Gaussian Filter

$$f(i, j) = \frac{1}{2\pi \sigma^{2}}e^{-\frac{i^{2}+j^{2}}{2\sigma^{2}}}$$

    - Gaussian blurring is used to define an image scale to work in, for interpolation, for computing interest points.

    - It replace current pixel value by weighted average between current pixel and neighbors.

    - Closer neighbor pixel will get higher weights. (weight falls off with distance from center pixel)

    - Cons : Gaussian filter smoothen the edges.

 

4) Bilateral Filter

    - Non-linear filter to remove noise and preserve the edges. (Not dramatically preserved)

    - Not only using Euclidean distance that Gaussian filter uses, also considers intensity difference.

 

5) Median Filter

    - Replace neighbor pixels values by median.

    - Effective for salt-and-pepper noise removal.

 

Example

1) SciPy

from scipy.ndimage import filters
from PIL import Image

im = np.array(Image.open('/Users/sejongpyo/Downloads/building.jpg').convert('L'))
std = [2, 5, 10]

f, ax = subplots(1, 3, figsize = (10, 7))
for i, v in enumerate(std):
    ga =filters.gaussian_filter(im, v)
    ax[i].imshow(ga)

plt.show()

 

2) Opencv

# averaging
dst = cv2.blur(img, (15, 15))

# Gaussian (Positive Odd only for kernel size)
dst = cv2.GaussianBlur(img, (25, 25), sigmaX = 0)

# Median (Positive Odd bigger than 1)
dst = cv2.medianBlur(img, 15)

# Bilateral filtering (src, 고려할 주변 픽셀 지름, sigmaColor, sigmaspace)
dst = cv2.bilateralFilter(img, 9, 75, 75)

참고

bskyvision.com/24

opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_filtering/py_filtering.html#filtering

http://programmingcomputervision.com/

'AI > Computer Vision' 카테고리의 다른 글

SIFT (Scale invariant feature transform)  (0) 2021.03.26
Harris Corner Detector  (0) 2021.03.24
Morphology  (0) 2021.03.24
Image filtering (Detecting edges)  (0) 2021.03.24
Histogram equalization  (0) 2021.03.23