1. CNN



2. DNN

3. 이미지 좌표계

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('../images/justice.jpg')
print(type(img))
plt.imshow(img)
plt.show()

4. Pillow를 이용한 이미지 처리
1. Cropping (이미지 잘라내기)
crop(좌상,우하)
crop_img = img.crop((30,110,140,330))
plt.imshow(crop_img)
plt.show()

2. Image Resize
print(img.size)
int(img.size[0] / 8)
resize_img = img.resize((int(img.size[0] / 8), int(img.size[1] / 8)))
plt.imshow(resize_img)
plt.show()
crop_img = img.crop((30,110,140,330))
plt.imshow(crop_img)
plt.show()

3. Image Rotate
rotate_img = img.rotate(180)
plt.imshow(rotate_img)
plt.show()
rotate_img.save('../images/rotate_justice.jpg')

5. Digital Image 형태

import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
color_img = Image.open('../images/fruits.jpg')
plt.imshow(color_img)
plt.show()

color_pixel = np.array(color_img)
print(color_pixel.shape)
1. gray-scaled image로 변환
color image의 pixel값을 조절해서 변환
가장 쉬운 방법 : color image의 각 pixel을 구성하고 있는 RGB 값들의 평균값으로
이미지의 각 pixel의 RGB값을 다시 설정
ex) (0,0) 픽셀의 RGB 값이 [100,200,60] 일 때 RGB 평균 : 120
(0,0) 픽셀의 값을 [120,120,120]으로 변경하면 흑백처리
gray_pixel = color_pixel.copy()
print(gray_pixel.shape)
for y in range(gray_pixel.shape[0]):
for x in range(gray_pixel.shape[1]):
gray_pixel[y,x] = int(np.mean(gray_pixel[y,x]))
plt.imshow(gray_pixel)
plt.show()
print(gray_pixel.shape)

2. 흑백이미지를 2차원으로 표현
gray_2d_pixel = gray_pixel[:,:,0]
print(gray_2d_pixel.shape)
plt.imshow(gray_2d_pixel, cmap='Greys_r')
plt.show()

6. 합성곱 연산





zero padding

padding : 'VALID'(no padding) or "SAVE"
(convolution 결과가 원본 이미지의 크기와 같다)
import numpy as np
import tensorflow as tf
image = np.array([[[[9],[8],[7]],
[[6],[5],[4]],
[[3],[2],[1]]]], dtype=np.float64)
print(image.shape)
weight = np.array([[[[2]],[[2]]],
[[[2]],[[2]]]])
print(weight.shape)
con2d = tf.nn.conv2d(image,
weight,
strides=[1,1,1,1],
padding='VALID')
sess = tf.Session()
result = sess.run(con2d)
print(result)
