컴퓨터 비전 Ch.1

송종빈·2023년 4월 25일
0

23-1

목록 보기
18/31

Ch.1 Filtering

Types of Image Transformation

What is an image?

(컬러) 이미지는 3D텐서: weight, height, color

R:8bit / G:8bit / B:8bit (→24bit)
min: 0 (black) / max: 255 (white)

(흑백; grayscale) 이미지는 2D 함수

  • 색깔 intensity 정규화 (0~255 → 0~1)

What types of image transformations can we do?

What types of image filtering can we do?

Point Image Processing

Linear Shift-Invariant Image Filtering

Replace each pixel by a linear combination of its neighbors (and possibly itself)

linear combination (선형결합)
여러개의 벡터에 스칼라 곱을 한 뒤, 그 결과들을 더하는 것
결합 방식은 필터의 커널에 의해 결정됨
동일한 커널이 모든 픽셀위치로 이동 → 모든 픽셀이 이웃 픽셀과 동일한 선형 결합 사용

Box Filter

2D rect filter / square mean filter 라고도 불림

blurring effect box filter

= local 평균값으로 각 픽셀 교체

kkk * k 커널일때,
k//2=k//2 = 중심 픽셀로부터 이웃 픽셀까지 거리
ex) 333*3 커널일때, k//2=1k//2 = 1, 즉 주변 1개씩

Convolution

커널을 뒤집어서 선형결합 진행

  • 커널이 대칭이면, filtering = convolution

Convolution for 1D continuous signals

(fg)(x)=f(y)g(xy)dy(f*g)(x) = \int_{-\infty}^{\infty} f(y) g(x-y) dy
  • (fg)(x)(f*g)(x) : filtered signal
  • f(y)f(y) : filter
  • g(xy)g(x-y) : input signal
    • flip 확인

Convolution for 2D discrete signals

(fg)(x,y)=i,j=f(i,j)I(xi,yj)(f*g)(x,y) = \sum_{i,j = -\infty}^{\infty} f(i,j) I(x-i, y-j)
  • (fg)(x,y)(f*g)(x,y) : filtered image
  • f(i,j)f(i,j) : filter
  • I(xi,yj)I(x-i, y-j) : input image
    • flip 확인

Convolution vs Correlation

Definition of discrete 2D Convolution:

(fg)(x,y)=i,j=f(i,j)I(xi,yj)(f*g)(x,y) = \sum_{i,j = -\infty}^{\infty} f(i,j) I(x-i, y-j)

Definition of discrete 2D Convolution:

(fg)(x,y)=i,j=f(i,j)I(x+i,y+j)(f*g)(x,y) = \sum_{i,j = -\infty}^{\infty} f(i,j) I(x+i, y+j)
  • 차이점은 커널의 flip 여부
  • 대부분 커널은 대칭이라 별 차이 없음
  • convolution: 신호처리에 많이 쓰임 (ex. filtering, blurring, edge detection 등)
  • correlation: 두 신호 or 함수의 유사도 측정에 많이 쓰임 (ex. template matching)

Seperable Filters

원래 이미지 M x M, 필터 커널 N x N 일때,

기존 시간 복잡도: (MM)(NN)=O(M2N2)(M * M) * (N * N) = O(M^2N^2)

Seperable Filter 시간 복잡도: 2(MM)N=O(2M2N)2 * {(M * M) * N} = O(2M^2N)

▶ 훨씬 빠름

Gaussian Filter

f(i,j)=12πσ2ei2+j22σ2f(i,j) = \frac {1} {2 \pi \sigma^2} e^{- \frac {i^2 + j^2} {2 \sigma^2}}

Soft Shadow Effect

Other filters

  • sharpening 너무 많이 하면 노이즈 ↑

Image Gradients

What are image edges?

very sharp discontinuities in intensity

  • 미분 = 기울기

=x2+y2\nabla = \sqrt {{\nabla x}^2 + {\nabla y}^2}
→ 총 기울기 = |(x기울기) + (y기울기)|

Detecting edges

미분값은 불연속성이 있는 부분(=edge)에서 큼

미분 값을 구하기 위해 finite differences 활용

Finite Differences

1. 우극한

f(x)=limh0f(x+h)f(x)hf'(x) = \lim_{h \to 0} \frac {f(x+h) - f(x)} {h}

2. 좌극한

=limh0f(x)f(xh)h= \lim_{h \to 0} \frac {f(x) - f(x-h)} {h}

3. 중앙차분

f(x)=limh0f(x+0.5h)f(x0.5h)hf'(x) = \lim_{h \to 0} \frac {f(x+0.5h) - f(x-0.5h)} {h}

4. For discrete signals

극한이 아니라, h=2로 둠

f(x)=f(x+1)f(x1)2f'(x) = \frac {f(x+1) - f(x-1)} {2}

1D derivative filter

  • if convolution:

The Sobel Filter

위 필터는 미분만 수행 → noise↑

horizontal sobel filter

가우시안 필터 (blur) * 1차원 미분 필터 (horizontal)

  • horizontal 필터 → vertical edge 찾아냄

vertical sobel filter

examples

Several Derivative Filters

  • Sobel 필터(2:1)가 Scharr 필터(10:3)보다 blur ↑
  • Roberts Filter: 대각선으로 검출

Computing Image gradients

  1. 미분 필터 선택 (sobel, scharr, ...)
  2. convolution 진행
  3. 이미지 gradient 구성 + 방향 & 크기 계산

Gradient
기울기를 vector로 나타냄

f=[fx,fy]\nabla f = \begin{bmatrix} \frac {\partial f} {\partial x}, \frac {\partial f} {\partial y} \end{bmatrix}

Direction
기울기 방향 확인

θ=tan1(fy/fx)\theta = tan^{-1} \begin{pmatrix} \frac {\partial f} {\partial y} / \frac {\partial f} {\partial x}\end{pmatrix}

Amplitude
기울기 크기 절대값으로 변환

f=(fx)2+(fy)2||\nabla f|| = \sqrt {(\frac {\partial f} {\partial x})^2 + (\frac {\partial f} {\partial y})^2}

How do you find the edge of this signal?

노이즈가 많으면 제대로 edge를 검출할 수 없음

  • 비어있는 부분은 이웃(neighbor) 없는 애들
  • 얼마만큼을 blur할지 적정점 찾는 것이 중요

DoG Filter

Derivative of Gaussian Filter

x(hf)=(xh)f\frac {\partial} {\partial x} (h*f) = (\frac {\partial} {\partial x} h) * f

ff : 기존 이미지
hh : 가우시안 필터

(기존 이미지 x 가우시안 필터)를 미분 → 기존이미지 x (가우시안 필터를 미분한 것)

원래 방식: O(2n2m2)O(2n^2m^2)
개선된 방식: O(n2m2)O(n^2m^2)

▶ 더 효율적 + 더 빠름

Laplace Filter

2차 미분 필터

1차 미분

f(x)=limh0f(x+0.5h)f(x0.5h)hf'(x) = \lim_{h \to 0} \frac {f(x + 0.5h) - f(x - 0.5h)}{h}

2차 미분

g(x)=f(x)g(x) = f'(x)라고 볼때,

g(x)=limh0g(x+0.5h)g(x0.5h)h2g'(x) = \lim_{h \to 0} \frac {g(x+0.5h) - g(x-0.5h)} {h^2}
g(x)=limh0f(x+0.5h)f(x0.5h)h2g'(x) = \lim_{h \to 0} \frac {f'(x+0.5h) - f'(x-0.5h)} {h^2}

여기서, f(x+0.5h)f'(x+0.5h)는,

f(x+0.5h)=limh0f(x+0.5h+0.5h)f(x+0.5h0.5h)hf'(x+0.5h) = \lim_{h \to 0} \frac {f(x + 0.5h + 0.5h) - f(x + 0.5h - 0.5h)}{h}
f(x+0.5h)=limh0f(x+h)f(x)hf'(x+0.5h) = \lim_{h \to 0} \frac {f(x + h) - f(x)}{h}

f(x0.5h)f'(x-0.5h)도 마찬가지로,

f(x0.5h)=limh0f(x)f(xh)hf'(x-0.5h) = \lim_{h \to 0} \frac {f(x) - f(x - h)}{h}

따라서,

f(x)=g(x)=limh0f(x+h)2f(x)+f(xh)h2f''(x) = g'(x) = \lim_{h \to 0} \frac {f(x+h) -2f(x) + f(x-h)} {h^2}

LoG Filter

Laplacian of Gaussian Filter

LoG vs DoG

2D 가우시안 필터

profile
Student Dev - Language Tech & Machine Learning

0개의 댓글