[청년취업사관학교 새싹]핀테커스 수업 14주차(11/22)

장민정·2023년 11월 22일
0
post-thumbnail

<수업 내용>

  • uint8 : 이미지의 detpye

Sobel Filtering

  • edge detection이 중요하다
white_patch =255*np.ones(shape=(10,10))
black_patch = 0*np.ones(shape=(10,10))

img1 = np.hstack([white_patch, black_patch])
img2 = np.hstack([black_patch, white_patch])
img = np.vstack([img1, img2])

fig, ax = plt.subplots(figsize=(8,8))
ax.imshow(img, cmap='gray')
ax.tick_params(left=False, labelleft = False, bottom =False, labelbottom =False)

#repeat : 원소 별로 반복
#tile : 전체를 반복
data = np.arange(5)
print('repeat:',np.repeat(data, repeats=3))
print('tile:', np.tile(data, reps=3))

>>

repeat: [0 0 0 1 1 1 2 2 2 3 3 3 4 4 4]
tile: [0 1 2 3 4 0 1 2 3 4 0 1 2 3 4]
data = np.arange(6).reshape(2,3)
print(np.repeat(data, repeats=3, axis=0))
print(np.repeat(data, repeats=3, axis=1))
print(np.repeat(np.repeat(data, repeats=3, axis=0),repeats=3 , axis=1))

>>
[[0 1 2]
 [0 1 2]
 [0 1 2]
 [3 4 5]
 [3 4 5]
 [3 4 5]]
 
[[0 0 0 1 1 1 2 2 2]
 [3 3 3 4 4 4 5 5 5]]
 
[[0 0 0 1 1 1 2 2 2]
 [0 0 0 1 1 1 2 2 2]
 [0 0 0 1 1 1 2 2 2]
 [3 3 3 4 4 4 5 5 5]
 [3 3 3 4 4 4 5 5 5]
 [3 3 3 4 4 4 5 5 5]]
 
print(np.tile(data, reps=[3,1]))
print(np.tile(data, reps=[1,3]))
print(np.tile(data, reps=[3,3]))
>>

[[0 1 2]
 [3 4 5]
 [0 1 2]
 [3 4 5]
 [0 1 2]
 [3 4 5]]
 
[[0 1 2 0 1 2 0 1 2]
 [3 4 5 3 4 5 3 4 5]]
 
[[0 1 2 0 1 2 0 1 2]
 [3 4 5 3 4 5 3 4 5]
 [0 1 2 0 1 2 0 1 2]
 [3 4 5 3 4 5 3 4 5]
 [0 1 2 0 1 2 0 1 2]
 [3 4 5 3 4 5 3 4 5]]
white_patch =255*np.ones(shape=(10,10))
black_patch = 0*np.ones(shape=(10,10))

img1 = np.hstack([white_patch, black_patch])
img2 = np.hstack([black_patch, white_patch])
img = np.vstack([img1, img2])
img = np.tile(img, reps=[4,4])

fig, ax = plt.subplots(figsize=(8,8))
ax.imshow(img, cmap='gray')
ax.tick_params(left=False, labelleft = False, bottom =False, labelbottom =False)

white_patch =255*np.ones(shape=(10,10))
black_patch = 0*np.ones(shape=(10,10))
gray_patch = 127*np.ones(shape=(10,10))
img1 = np.hstack([white_patch, gray_patch])
img2 = np.hstack([gray_patch, black_patch])
img = np.vstack([img1, img2])

img = np.tile(img, reps=[4,4])

fig, ax = plt.subplots(figsize=(8,8))
ax.imshow(img, cmap='gray')
ax.tick_params(left=False, labelleft = False, bottom =False, labelbottom =False)

mg = np.arange(0,256,50).reshape(1,-1)
img = img.repeat(100, axis=0).repeat(30,axis=1)
fig, ax = plt.subplots(figsize=(8,4))
ax.imshow(img, cmap ='gray')
ax.tick_params(left=False, labelleft = False, bottom =False, labelbottom =False)

업로드중..

img = np.arange(0,256,70).reshape(1,-1)
img = img.repeat(150, axis=0).repeat(50,axis=1)
fig, ax = plt.subplots(figsize=(8,4))
ax.imshow(img, cmap ='gray')
ax.tick_params(left=False, labelleft = False, bottom =False, labelbottom =False)

업로드중..

img = np.arange(255,-1,-50).reshape(-1,1)
img =  img.repeat(100, axis=0).repeat(300,axis=1)
fig, ax = plt.subplots(figsize=(4,8))
ax.imshow(img, cmap ='gray')
ax.tick_params(left=False, labelleft = False, bottom =False, labelbottom =False)

업로드중..

img1 = np.arange(0,256).reshape(1,-1)
img1 = img1.repeat(700, axis=0).repeat(5,axis=1)
img2 = np.arange(0,256)[::-1].reshape(1,-1)
img2 = img2.repeat(700, axis=0).repeat(5,axis=1)
img = np.vstack([img1, img2])
fig, ax = plt.subplots(figsize=(8,4))
ax.imshow(img, cmap ='gray')
ax.tick_params(left=False, labelleft = False, bottom =False, labelbottom =False)

업로드중..

  • window : 10개의 원소를 가진 1차원 벡터가 주어졌을 때, 3칸 (홀수개)의 window가 차례대로 지나가면서 데이터를 3개씩 뽑는 과정
    window개수 = L(데이터의 길이) - W(window의 길이) + 1
data = 10* np.arange(1,11)
window_list=[]
for idx in range(len(data)):
  window = data[idx: idx+3]
  window_list.append(window)
  if idx == len(data)-3:
    break
print(window_list)   
>>
[array([10, 20, 30]), 
array([20, 30, 40]), 
array([30, 40, 50]), 
array([40, 50, 60]), 
array([50, 60, 70]), 
array([60, 70, 80]), 
array([70, 80, 90]), 
array([ 80,  90, 100])]

업로드중..

data = 10* np.arange(0,7) 
data_= 10 * np.arange(1,6)
real_data = data + data_.reshape(-1,1)
>>

array([[ 10,  20,  30,  40,  50,  60,  70],
       [ 20,  30,  40,  50,  60,  70,  80],
       [ 30,  40,  50,  60,  70,  80,  90],
       [ 40,  50,  60,  70,  80,  90, 100],
       [ 50,  60,  70,  80,  90, 100, 110]])
       
-------------------------------------------------------
high = 5-3+1
width = 7-3+1
windows = high*width

for idx in range(high):
  for idx_ in range(width):
    print(real_data[idx:idx+3,idx_:idx_+3])
    
>>
[[10 20 30]
 [20 30 40]
 [30 40 50]]
[[20 30 40]
 [30 40 50]
 [40 50 60]]
[[30 40 50]
 [40 50 60]
 [50 60 70]]
[[40 50 60]
 [50 60 70]
 [60 70 80]]
[[50 60 70]
 [60 70 80]
 [70 80 90]]
[[20 30 40]
 [30 40 50]
 [40 50 60]]
[[30 40 50]
 [40 50 60]
 [50 60 70]]
[[40 50 60]
 [50 60 70]
 [60 70 80]]
[[50 60 70]
 [60 70 80]
 [70 80 90]]
[[ 60  70  80]
 [ 70  80  90]
 [ 80  90 100]]
[[30 40 50]
 [40 50 60]
 [50 60 70]]
[[40 50 60]
 [50 60 70]
 [60 70 80]]
[[50 60 70]
 [60 70 80]
 [70 80 90]]
[[ 60  70  80]
 [ 70  80  90]
 [ 80  90 100]]
[[ 70  80  90]
 [ 80  90 100]
 [ 90 100 110]]   

0개의 댓글