今回の記事はPythonでopencvを利用して画像を2値化する方法について記載いたします。
opencvで画像を2値化するコード
import cv2
import sys
tes = cv2.imread('[画像パス]')
th = 127
i_max = 255
ret, i_binary = cv2.threshold(tes, th, i_max, cv2.THRESH_BINARY)
cv2.imwrite('[画像出力パス]',i_binary)
i_maxは255が真っ白を表しているので灰色とかも調整すれば出せます。
コメント
[…] pythonのopencvを使って画像を2値化する方法はこちら。 […]