아린// 2021. 3. 1. 21:19

1. 곡선의 접선 

  - 미분계수란 y=f(x)의 접선의 기울기 

 

2. 윤곽 추출하기 

  - 명암차가 급격한 곳을 보고 영영과 영역의 관계를 파악 = 윤곽을 파악 

  - 값의 변화를 보는 방법 = 뺄셈 

%matplotlib inline
import matplotlib.pyplot as plt
from PIL import Image

src_img = Image.open('sample.png') #이미지를 읽어들인다
plt.imshow(src_img)
plt.show()

width, height = src_img.size #이미지의 크기를 조정한다 

dst_img = Image.new('RGB', (width, height)) #출력을 위해 영역 할당

src_img = src_img.convert("L") #컬러에서 흑백으로 전환해라 

#윤곽을 추출하는 방법
for y in range(0, height-1):
    for x in range(0, width-1):
        diff_x = src_img.getpixel((x+1, y)) - src_img.getpixel((x, y))
        diff_y = src_img.getpixel((x, y+1)) - src_img.getpixel((x, y))
        diff = diff_x + diff_y
            
        #출력 
        if diff >=20:
            dst_img.putpixel((x, y), (255, 255, 255))
        else:
            dst_img.putpixel((x, y), (0, 0, 0))
            
plt.imshow(dst_img)
plt.show()