小工具_批量转换为单深度图像

bit8_dir = 'path to pic'
png_names = os.listdir(bit8_dir)
for i in png_names:
    img = cv2.imread(bit8_dir+'/'+i)
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    ret, thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    cv2.imwrite( bit8_dir+'/new/'+i, thresh, [cv2.IMWRITE_PNG_BILEVEL])
posted @ 2022-01-08 16:27  Nonmy  阅读(96)  评论(0)    收藏  举报