์ฌ์ง์ RGB๋ก nois๊ฐ ์กด์ฌํ๋ค. ์ด๋ ๋ฐฐ๊ฒฝ๊ณผ ๊ธ์จ๋ฅผ ๋ถ๋ฆฌํ๊ธฐ ์ํด ํํฐ๋ง ์์ ์ ๊ฑฐ์น๋ค.
width: 523 pixels height: 184 pixels channels: 3
1. hsv(hue, saturation, value): value๋ฅผ ํ์ธํด ๋ณด์๋ค.
- hsv transform - value = gray image
- hue: ์์, saturation: ์ฑ๋, value: ๋ช ๋
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
hue, saturation, value = cv2.split(hsv)
plt.imshow(value)
2. kernel to use for morphological operations
# filter: boundary๋ฅผ ์ฐพ์๋ด๋ ๊ฒ
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
CV2.MORPH_TOPHAT, CV2.MORPH_BLACKHAT: ์ธ๊ฐ์
# applying topHat operations / image์ ์ธ๊ฐ์ ์ ์ฐพ์๋ธ๋ค.
topHat = cv2.morphologyEx(value, cv2.MORPH_TOPHAT, kernel)
plt.imshow(topHat)
# applying blackHat operations
blackHat = cv2.morphologyEx(value, cv2.MORPH_BLACKHAT, kernel)
plt.imshow(blackHat)
- ์ฒ๋ฆฌ ๋ฐฉ๋ฒ
- blur
- GaussianBulr
- medianBlur
- bilateralFilter
3. ์ซ์ ์ธ์
# ์ซ์๊ฐ 2๊ฐ, 3๊ฐ,,
img_digits = []
img_origin = img.copy()
margin = 10
epochs= 10
# loop to check if any (possible) contour is found
# contours: ์ค๊ณฝ์ ์ ๊ฐ์ ธ์จ๋ค.
for contour in contours:
x, y, w, h = cv2.boundingRect(contour)
# Ignore if image is too small
if w * h < 100: continue
#Y and X [y-margin:y+h+margin, x-margin:x+w+margin]
img_digits.append(img_origin[y-margin:y+h+margin, x-margin:x+w+margin])
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2) #(0, 255, 0): rgb, 2: ๋๊ป
print(x, x+w, y, y+h)
plt.imshow(img)
๋ชจ๋ธ์ ๋ค์ด๊ฐ๋ size๋ฅผ 28 by 28๋ก ๋ง์ถ๋ค
SZ = 28
for i in range(0, len(img_digits)):
plt.subplot(1, len(img_digits), i+1)
plt.imshow(cv2.resize(img_digits[i], (SZ, SZ)), cmap='Greys', interpolation='nearest')
plt.tight_layout()
plt.show()
์ฒซ ๋ฒ์งธ๊ฐ 7์ด ์๋๋ผ 3์ผ๋ก ์์ธก์ด ๋์๋ค.
์ด ๊ฒฝ์ฐ ๋์ค์ ๋ค์ ์ดํด๋ด์ผ ๊ฒ ๋ค
728x90