LAPLACIAN FILTER

ChangSeong Yooยท2023๋…„ 7์›” 16์ผ
0

Vision

๋ชฉ๋ก ๋ณด๊ธฐ
3/5
post-thumbnail

๐Ÿ“์ด ํฌ์ŠคํŠธ์—์„œ Laplacian Filter์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.




์ •์˜

Laplacian Filter๋Š” ์—ฃ์ง€ ๊ฒ€์ถœ์— ์ด์šฉ๋˜๋Š” ํ•„ํ„ฐ ์ค‘ ํ•˜๋‚˜์ž…๋‹ˆ๋‹ค.

Laplacian Filter์˜ ํŠน์ง•

  • ์ด ํ•„ํ„ฐ๋Š” ์ด๋ฏธ์ง€ ๋ฐ๊ธฐ์˜ ๊ธ‰๊ฒฉํ•œ ๋ณ€ํ™”๋ฅผ ์ธ์‹ํ•˜์—ฌ ์˜ˆ๋ฅผ๋“ค์–ด ํฐ์ƒ‰์—์„œ ๊ฒ€์€์ƒ‰์œผ๋กœ ํ”ฝ์…€๊ฐ’์ด ๊ธ‰๊ฒฉํ•˜๊ฒŒ ๋ณ€ํ•˜๋Š” ๊ฒƒ์„ ๊ฒ€์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฒฝ๊ณ„๋ฅผ ๊ฒ€์ถœํ•˜๋Š”๋ฐ๋Š” ๋ฏธ๋ถ„์ด ๊ณ ๋ ค๋ฉ๋‹ˆ๋‹ค.

โˆ‡fx=limโกhโ†’0f(x+h,y)โˆ’f(x,y)h\nabla f_x = \lim_{h \to 0}\frac{f(x+h, y) - f(x,y)}{h}
โˆ‡fy=limโกhโ†’0f(x,y+h)โˆ’f(x,y)h\nabla f_y = \lim_{h \to 0}\frac{f(x, y+h) - f(x,y)}{h}

๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.
๋Œ€๋ถ€๋ถ„์˜ ์—ฃ์ง€ ๊ฒ€์ถœ ํ•„ํ„ฐ๋“ค์ด ์ด ๊ณต์‹์„ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.

ํ”ฝ์…€์—์„œ ๋Œ€ํ•ด์„œ hh๊ฐ€ 0์œผ๋กœ ์ˆ˜๋ ด์ด ์•ˆ๋˜๊ณ  ์ตœ๋Œ€ํ•œ ์ˆ˜๋ ดํ•œ๋‹คํ–ˆ์„ ๋•Œ ์ธ์ ‘ ํ”ฝ์…€์ธ ๋ฐ”๋กœ ์˜† ํ”ฝ์…€๊ณผ์˜ ๊ฑฐ๋ฆฌ์ธ h=1h=1 ์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋Ÿฐ๋ฐ ๋ผํ”Œ๋ผ์‹œ์•ˆ ํ•„ํ„ฐ๋Š” 2์ฐจ ๋ฏธ๋ถ„์„ ๊ณ ๋ คํ•œ ํ•„ํ„ฐ์ž…๋‹ˆ๋‹ค.
1์ฐจ ๋ฏธ๋ถ„์€ ํ•จ์ˆ˜์˜ ๊ธฐ์šธ๊ธฐ๋ฅผ, 2์ฐจ ๋ฏธ๋ถ„์€ ํ•จ์ˆ˜์˜ ๊ณก๋ฅ ์„ ๊ณ ๋ คํ•œ ๊ฒƒ์œผ๋กœ ๋ผํ”Œ๋ผ์‹œ์•ˆ ํ•„ํ„ฐ๋Š” ์ด๋ฏธ์ง€์˜ ๋ฐ๊ธฐ ๊ฐ’์˜ ๋ณ€ํ™”์œจ์ด ํฐ ์ง€์ ์„ ๊ฐ์ง€ํ•˜๊ธฐ ์œ„ํ•ด 2์ฐจ ๋ฏธ๋ถ„์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

โˆ‡2f=โˆ‚2fโˆ‚x2+โˆ‚2fโˆ‚y2\nabla^2f = \frac{\partial^2f}{\partial x^2} + \frac{\partial^2f}{\partial y^2}

์˜ ์ˆ˜์‹์œผ๋กœ ํ‘œํ˜„๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.




์ฝ”๋“œ ์ดํ•ด

์ฝ”๋“œ๋กœ ์‰ฝ๊ฒŒ ์ดํ•ดํ•˜์‹ค ์ˆ˜ ์žˆ์„ ๊ฒ๋‹ˆ๋‹ค.

Laplacian_filter3x3 = np.array([[ 0,-1, 0],
                                [-1, 4,-1],
                                [ 0,-1, 0]])
0โˆ’10โˆ’14โˆ’10โˆ’10\begin{matrix} 0 & -1 & 0 \\ -1 & 4 & -1 \\ 0 & -1 & 0 \end{matrix}
Laplacian_filter3x3_2 = np.array([[-1,-1,-1],
                                [-1, 8,-1],
                                [-1,-1,-1]])
โˆ’1โˆ’1โˆ’1โˆ’18โˆ’1โˆ’1โˆ’1โˆ’1\begin{matrix} -1 & -1 & -1 \\ -1 & 8 & -1 \\ -1 & -1 & -1 \end{matrix}

์ด๋Ÿฐ ํ˜•ํƒœ๋กœ ๊ฐ ์ธ๋ฑ์Šค๋“ค์˜ ํ•ฉ์ด 0์ด ๋˜๊ฒŒ ์œ ์ง€ํ•˜๋ฉด์„œ ์ค‘์•™์— ์œ„์น˜ํ•œ ์ธ๋ฑ์Šค๊ฐ€ ์ฃผํŒŒ์ˆ˜๊ฐ€ ํ™• ํŠ€์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

result_Laplacian = Convolution2D(Laplacian_filter3x3, image_moon)

result_Laplacian_2 = Convolution2D(Laplacian_filter3x3_2, image_moon)

cv2_imshow(result_Laplacian)

cv2_imshow(result_Laplacian_2)

๊ฒฐ๊ณผ๐Ÿ–จ๏ธ


๋กœ ์ฃผํŒŒ์ˆ˜ ์ฐจ์ด๋ฅผ ๊ทน๋ช…ํ•˜๊ฒŒ ์ค„์ˆ˜๋ก ๋” ์ฐจ์ด๋‚˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ

Laplacian Filter์˜ ๋‹จ์ 

  • ๊ทธ๋Ÿฌ๋‚˜ ๋…ธ์ด์ฆˆ์— ๋ฏผ๊ฐํ•˜๊ฒŒ ๋ฐ˜์‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    ๋†’์€ ์ฃผํŒŒ์ˆ˜์˜ ๋…ธ์ด์ฆˆ๊ฐ€ ์ถœํ˜„ํ•œ๋‹ค๋ฉด ๋ฏธ๋ถ„๊ฐ’์˜ ๊ธฐ์šธ๊ธฐ๊ฐ€ ๊ธ‰๊ฒฉํžˆ ์ฆ๊ฐ€ํ•ด์„œ ๋…ธ์ด์ฆˆ์— ๋ฏผ๊ฐํ•˜๊ฒŒ ๋ฐ˜์‘ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋…ธ์ด์ฆˆ๋ฅผ ์ค„์ด๋Š”๋ฐ์— ๊ฐ€์šฐ์‹œ์•ˆ ํ•„ํ„ฐ๊ฐ€ ์‚ฌ์šฉ๋ฌ์—ˆ์ฃ ๐Ÿ˜€
๊ฐ€์šฐ์‹œ์•ˆ ํ•„ํ„ฐ๋ฅผ ์ ์šฉํ•˜์—ฌ ๋ณด์™„ํ•œ ๊ฒƒ์ด

Laplacian of Gaussian Filter

์ž…๋‹ˆ๋‹ค.

LoG(x,y)=โˆ’1ฯ€ฯƒ4[1โˆ’x2+y22ฯƒ2]eโˆ’x2+y22ฯƒ2LoG(x,y) = -\frac{1}{\pi\sigma^4}[1-\frac{x^2 + y^2}{2\sigma^2}]e^{-\frac{x^2 + y^2}{2\sigma^2}}

ํ•„ํ„ฐ์˜ ์˜ˆ๋ฅผ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

LoG_filter = np.array([[ 0, 0,-1, 0, 0],
                       [ 0,-1,-2,-1, 0],
                       [-1,-2,16,-2,-1],
                       [ 0,-1,-2,-1, 0],
                       [ 0, 0,-1, 0, 0]])
00โˆ’1000โˆ’1โˆ’2โˆ’10โˆ’1โˆ’216โˆ’2โˆ’10โˆ’1โˆ’2โˆ’1000โˆ’1.00\begin{matrix} 0 & 0 & -1 & 0 & 0 \\ 0 & -1 & -2 & -1 & 0 \\ -1 & -2 & 16 & -2 & -1 \\ 0 & -1 & -2 & -1 & 0 \\ 0 & 0 & -1 &. 0 & 0 \\ \end{matrix}

Laplacian of Gaussian Filter๋Š” ํ˜•ํƒœ์˜ ํ•„ํ„ฐ์ž…๋‹ˆ๋‹ค.
ํ•„ํ„ฐ์˜ ์ค‘์‹ฌ์—๋Š” ์ฃผํŒŒ์ˆ˜๊ฐ€ ๋†’๊ณ  ๊ธฐ์šธ๊ธฐ๊ฐ€ ๊ฐ€ํŒ”๋ž๋‹ค๊ฐ€ ์™„๋งŒํ•ด์ง€๋Š” ๋ชจ์–‘์œผ๋กœ ํ•„ํ„ฐ๊ฐ€ ๊ทน์†Ÿ๊ฐ’ or ๊ทน๋Œ“๊ฐ’์„ ๊ฐ–์Šต๋‹ˆ๋‹ค.
2์ฐจ ๋ฏธ๋ถ„์„ ๊ณ ๋ คํ•˜์˜€์œผ๋ฏ€๋กœ ๊ฐ€๋Šฅํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋‹ฌ ์‚ฌ์ง„์— ํ•œ๋ฒˆ ํ•„ํ„ฐ๋ฅผ ์ ์šฉํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

result_LoG = Convolution2D(LoG_filter, image_moon)

cv2_imshow(result_LoG)

์Œ... ๋” ์…˜๋ฉํ•ด์ง„ ๊ฒƒ ๊ฐ™๋‹ค๋งŒ ํ•„ํ„ฐ ํฌ๊ธฐ๊ฐ€ 5X5์—ฌ์„œ ๊ทธ๋Ÿฐ์ง€ ๋ถˆ์•ˆ์ •ํ•ด ๋ณด์ž…๋‹ˆ๋‹ค๐Ÿ˜…

profile
๐’ฅ๐“Š๐“ƒ๐’พโ„ด๐“‡ ๐’Ÿ๐’ถ๐“‰๐’ถ ๐’ฎ๐’ธ๐’พโ„ฏ๐“ƒ๐“‰๐’พ๐“ˆ๐“‰

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 7์›” 17์ผ

์ €๋„ ๊ฐœ๋ฐœ์ž์ธ๋ฐ ๊ฐ™์ด ๊ต๋ฅ˜ ๋งŽ์ด ํ•ด๋ด์š” ใ…Žใ…Ž! ์„œ๋กœ ํ™”์ดํŒ…ํ•ฉ์‹œ๋‹ค!

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ