Professional Documents
Culture Documents
딥러닝과 컴퓨터비전 - 03
딥러닝과 컴퓨터비전 - 03
▪
1
2
3
1
2
3
・
(이미지 확대 시 주의 필요)
(카메라 취득 영상 등)
Format:
2
5 3
1
(3, 3)
100
image = np.array(
[ [ [255,255,255], [ 0, 0, 0], [128,128,128]], # white, black, gray
[ [255, 0, 0], [ 0,255, 0], [ 0, 0,255]], # r, g, b
[ [255,255, 0], [255, 0,255], [ 0,255,255] ] ] # yellow, magenta, cyan
)
print(image.shape) # 이미지 shape 확인 (row, column)
print(image[1][2]) # 이미지 값 확인 row = 1, col = 2
print(image[1][2][2]) # 이미지 값 확인 (blue channel)
(3, 3, 3)
[ 0 0 255]
255
# pillow
from PIL import Image
img = Image.open(img_path) # use Image.open(image_location)
image = np.array(img.convert('RGB')) # to convert img object to array value use np.array
# opencv
import cv2
image = cv2.imread(img_path)
# convert opencv RGB for opencv
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# matplotlib
from matplotlib import image as mp_image
img = mp_image.imread(image_path)
from tensorflow import keras
import matplotlib.pyplot as plt
fashion_mnist = keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
plt.imshow(train_images[0], cmap=plt.cm.binary)
MNIST 데이터셋이란?
# PIL
from PIL import Image
import numpy as np
PIL_image = Image.fromarray(np.uint8(image)).convert('RGB')
PIL_image.save(image_path)
# opencv
import cv2
# convert opencv RGB for opencv
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
cv2.imwrite(image_path, image)
# matplotlib
from matplotlib import pyplot as plt
img = plt.imsave(image_path, image)
𝑦1 𝑤11 𝑤12 ⋯ 𝑤1𝑛 𝑥1
𝑦2 𝑤21 𝑤22 ⋯ 𝑤2𝑛 𝑥2
⋮ = ⋮ ⋮ ⋱ ⋮ ⋮
𝑦𝑚 𝑤𝑚1 𝑤𝑚2 ⋯ 𝑤𝑚𝑛 𝑥𝑛
𝒚 = 𝒘𝒙
𝑦1 = 𝑤11 𝑥1 + 𝑤12 𝑥2 + ⋯ + 𝑤1𝑛 𝑥𝑛
𝑦2 = 𝑤21 𝑥1 + 𝑤22 𝑥2 + ⋯ + 𝑤2𝑛 𝑥𝑛
…
𝑦𝑚 = 𝑤𝑚1 𝑥1 + 𝑤𝑚2 𝑥2 + ⋯ + 𝑤𝑚𝑛 𝑥𝑛
𝒚 = 𝒘𝒙
[10 4]
𝑥2 𝑥2′
𝑥1 𝑥1′
2 0
1 0 0 2
0 1
0.5 0 2 0
0 0.5 0 1
cos 𝜃 −sin 𝜃
sin 𝜃 cos 𝜃
1 0.5
0 1
𝝅
𝜽 = = 30
𝟔
−1 0
0 1
𝑨𝒇𝒍𝒊𝒑 ∙ 𝑨𝒓𝒐𝒕𝒂𝒕𝒊𝒐𝒏
𝑝3 𝑝3′
𝑣 = 𝑝3 − 𝑝1 𝑣 ′ = 𝑝2′ − 𝑝1′
𝑢′ = 𝑝2′ − 𝑝1′
𝑢 = 𝑝2 − 𝑝1
𝑝2′
𝑝1 𝑝2 𝑝1′
𝑤
𝑏 = 𝑝1′ − 𝑝1
𝑢′ = 𝑤𝑢
𝑣 ′ = 𝑤𝑣
𝑤
# 점3개를 변환 전과 변환 후로 나누어 지정
pts1 = np.float32([[200,100],[400,100],[200,200]])
pts2 = np.float32([[200,300],[400,200],[200,400]])
# Affine 변환 텐서 얻기
M = cv2.getAffineTransform(pts1, pts2)
# Affine 변환하기
dst = cv2.warpAffine(img, M, (cols,rows))
# 사이즈 변환
img = cv2.resize(img, dsize=(100,100), interpolation=cv2.INTER_AREA)
# 회전 변환
M = cv2.getRotationMatrix2D(center, angle, scale)
입력 이미지의 사이즈
입력 이미지의 픽셀값의 범위
blur filter (or kernel)
𝟏
[ 1, 1, 1 ]
𝟑
f(t) = [ 0, 0, 0, 1, 1, 1, 0, 0, 0 ]
conv(t) = [ 0, 1/3, 2/3, 1, 2/3, 1/3, 0 ]
f(t) f(t+1) f(t+2) f(t)+f(t+1)+f(t+2)
conv(t) = + + =
3 3 3 3
계동캠퍼스(03051)서울특별시 종로구 북촌로 106 안암캠퍼스(02841)서울특별시 성북구 안암로 145 고려대학교 안암캠퍼스내
www.cuk.edu T.02-6361-2000 F.02-6361-1800