马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from skimage import data_dir, io, transform, color, filters
import cv2 as cv
import numpy as np
import os
def convert_gray(f):
rgb = io.imread(f)
gray = cv.cvtColor(rgb, cv.COLOR_RGB2GRAY)
ret, binary = cv.threshold(gray, 0, 255, cv.THRESH_BINARY|cv.THRESH_OTSU)
# 大津法
# binary = cv.adaptiveThreshold(gray, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY_INV, 131, 0)
# 自适应阈值
return binary
str = r'F:\Study\ground fissure experiment\7.29\X5S\input\*.jpg' # 源文件目录
path = r'F:\ground fissure experiment\7.28\XT2\Input' # 源文件目录
# file_list = os.listdir(path)
path1 = r'F:\Study\ground fissure experiment\7.29\X5S\ostu' # 输出文件目录
coll = io.ImageCollection(str, load_func=convert_gray)
print(len(coll))
# for i in range(len(coll)):
# #io.imsave(r'F:\Study\ground fissure experiment\7.29\X5S\ostu\ostu_' + np.str(i) + '.jpg', coll[i])
本来是批量生成大津法后的图片,Input文件里只有10张图像,coll里有20张不知道为啥,有一张是重复的,是代码哪里出问题了吗 |