とか、など

プログラミングとか、画像処理とか、機械学習を勉強しようとして挫折中

python3 opencv3入門-2値化してみよう

画像処理といえば2値化から、というわけでやってみます

とはいえ、コードはこれだけです。thresholdの値を変えると処理結果が変わると思います。

 

%matplotlib inline
import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('./images/lenna.jpg', 0) #グレーで読み出し
#retはとりあえず無視してくれていいです
threshold = 127
ret, binImage = cv2.threshold(img, threshold, 255, cv2.THRESH_BINARY)#二値化

plt.subplot(121), plt.imshow(img, 'gray')
plt.subplot(122), plt.imshow(binImage, 'gray')
plt.show()

f:id:hikuIchi:20160206173143p:plain