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
๋ฐ์ํ
'AI > Computer Vision' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Computer Vision] ์์์ ๊ธฐํํ์ ๋ณํ (0) | 2024.08.30 |
---|---|
[Computer Vision] Filtering (0) | 2024.08.30 |
[Computer Vision] ํ ์คํธ ์ฝ์ ๋ฐ ์ ์ฉํ ๊ธฐ๋ฅ (0) | 2024.08.28 |
[Computer Vision] ๊ทธ๋ฆฌ๊ธฐ ํจ์ (0) | 2024.08.27 |
[Computer Vision] ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ (0) | 2024.08.27 |