AI/Computer Vision
[Computer Vision] μμμ λͺ μ μ μ΄
Pupbani
2024. 8. 28. 22:59
728x90
λ°μν
π λ³Έ μμ λ Window10μ VSCode, Python3.11.0λ‘ μμ±λμμ΅λλ€.
OpenCVμμ μ»¬λ¬ μμμ΄ μλ GrayScaleλ‘ μ΄λ―Έμ§λ₯Ό μ΄κ±°λ λ³ννκ² λλ©΄ κ° μ’νμ κ°μ μμ λνλ΄λ κ°μ΄ μλλΌ μ΄λ―Έμ§μ λͺ μμ λνλΈλ€.
import numpy as np
import cv2
white = np.ones(shape=(480,480),dtype=np.uint8) * 255
cv2.imshow("white",white)
black = np.zeros(shape=(480,480),dtype=np.uint8)
cv2.imshow("black",black)
cv2.waitKey(0)
cv2.destroyAllWindows()
λ°κΈ°κ° 0μΈ μμ(κ²μμ)

λ°κΈ°κ° 255μΈ μμ(ν°μ)

Gray Scale μμμ ν½μ μ κ°μ΄ 0μΌλ‘ κ°μλ‘ ν΄λΉ ν½μ μ κ²μμμ κ°κΉμμ§κ³ 255λ‘ κ°μλ‘ ν°μμ κ°κΉμμ§λ€.
import cv2
import numpy as np
img = np.zeros((480,480),np.uint8)
now = 0
def lighting(brightness: int) -> None:
global img, now
delta = brightness - now
# λ°κΈ° μ‘°μ
if delta > 0:
img = cv2.add(img, delta)
elif delta < 0:
img = cv2.subtract(img, -delta)
now = brightness
cv2.imshow("lighting_bar", img)
if __name__ == "__main__":
cv2.imshow("lighting_bar",img)
cv2.createTrackbar("Control","lighting_bar",now,255,lighting)
cv2.waitKey(0)
cv2.destroyAllWindows()

νμ€ν κ·Έλ¨μ ν΅ν΄ μμμ λ°κΈ° λΆν¬λ₯Ό λ³Ό μ μλ€.
import cv2
import matplotlib.pyplot as plt
if __name__ == "__main__":
image = cv2.imread("test.png",cv2.IMREAD_GRAYSCALE)
plt.hist(image.ravel(),256,[0,256])
plt.show()

μ»¬λ¬ λΆν¬λ λ³Ό μ μλ€.
import cv2
import matplotlib.pyplot as plt
if __name__ == "__main__":
image = cv2.imread("test.png")
color = ('b','g','r')
for i,col in enumerate(color):
histr = cv2.calcHist([image],[i],None,[256],[0,256])
plt.plot(histr,color=col)
plt.xlim([0,256])
plt.show()

728x90
λ°μν