π 곡λΆνλ μ§μ§μνμΉ΄λ μ²μμ΄μ§?
[Python μΌλ‘ μμμ²λ¦¬ (4)] λλλ§(Dithering): μ νλ μμ μ΄μ©νμ¬ μμμ΄λ μμ λνλ΄λ κ² λ³Έλ¬Έ
π©π» IoT (Embedded)/Image Processing
[Python μΌλ‘ μμμ²λ¦¬ (4)] λλλ§(Dithering): μ νλ μμ μ΄μ©νμ¬ μμμ΄λ μμ λνλ΄λ κ²
μ§μ§μνμΉ΄ 2023. 12. 28. 10:58728x90
λ°μν
π 0κ³Ό 1λ‘ λͺ μ ννν΄λ³΄κΈ°
λλλ§(Dithering)μ μ νλ μμ μ΄μ©νμ¬ μμμ΄λ μμ λνλ΄λ κ²μ΄λ©°, μ¬λ¬ 컬λ¬μ μμ μ΅λν λ§μΆλ κ³Όμ μ΄λ€.κ·Έλν½ λμμ΄λμ μμ±κ³΅κ° μμμ νλμ μΈκΈ°κ° μλ λ€λ₯Έ ν½μ μΈκΈ°λ‘ ꡬμ±λκΈ° λλ¬Έμ λμμ΄ λ§μ κ²μ²λΌ λ€μ κ±°μΉ κ² λ³΄μΌ μ μλ€
μμ¦ μ μμ°μ ^_^
def minmax(pixel):
if pixel > 255:
pixel = 255
if pixel < 0:
pixel = 0
return pixel
import numpy as np
def dithering(img):
height, width = img.shape
for y in range(0, height-1):
for x in range(1, width-1):
p = img[y, x]
new_p = np.round(p/255) * 255
img[y, x] = new_p
error = p - new_p
img[y , x+1] = minmax(img[y , x+1] + error*7/16)
img[y+1, x-1] = minmax(img[y+1, x-1] + error*3/16)
img[y+1, x ] = minmax(img[y+1, x ] + error*5/16)
img[y+1, x+1] = minmax(img[y+1, x+1] + error*1/16)
return img
import cv2
lena = cv2.imread('images/lena.jpg', cv2.IMREAD_GRAYSCALE)
lena_dithering = dithering(lena.copy())
# cv2.imwrite('lena_dithering.jpg', lena_gray_dithering)
cv2.imshow('Lena grayscale', lena)
cv2.imshow('Lena dithering', lena_dithering)
cv2.waitKey(0)
cv2.destroyAllWindows()
728x90
λ°μν
'π©βπ» IoT (Embedded) > Image Processing' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Python μΌλ‘ μμμ²λ¦¬ (6)] μ΄λ―Έμ§ λ³ν (κΈ°ν, ν¬κΈ° λ³ν) & 보κ°λ² (1) | 2023.12.28 |
---|---|
[Python μΌλ‘ μμμ²λ¦¬ (5)] νμ€ν κ·Έλ¨ (0) | 2023.12.28 |
[Python μΌλ‘ μμμ²λ¦¬ (3)] cv2.threshold() (0) | 2023.12.28 |
[Python μΌλ‘ μμμ²λ¦¬ (2)] μ΄μ§ν (0) | 2023.12.28 |
[Python μΌλ‘ μμμ²λ¦¬ (1)] cv2.seamlessClone() μμμ μ‘°νλ‘μ!! (1) | 2023.12.28 |
Comments