|
@@ -4,41 +4,37 @@ from .get_feature import main
|
|
|
import os
|
|
|
|
|
|
rate = 0.5
|
|
|
-
|
|
|
-def predict(path, model):
|
|
|
+def predict(path, model) -> tuple:
|
|
|
''' predict
|
|
|
Args:
|
|
|
- path - image path
|
|
|
- Returns: image path, image info
|
|
|
+ path - 图像路径
|
|
|
+ Returns: 图像路径,图像信息
|
|
|
'''
|
|
|
global img_y
|
|
|
- file_name = os.path.split(path)[1].split('.')[0]
|
|
|
-
|
|
|
- x = path.replace('\\', '/')
|
|
|
- img_y = model.predict(x)['label_map']
|
|
|
- img_y = img_y * 255
|
|
|
- img_y = img_y.astype(np.int)
|
|
|
+ file_name = os.path.split(path)[1].split('.')[0] # 获取文件名,不包括扩展名
|
|
|
+
|
|
|
+ x = path.replace('\\', '/') # 将路径中的反斜杠替换为正斜杠
|
|
|
+ img_y = model.predict(x)['label_map'] # 使用模型预测图片得到标签映射
|
|
|
+ img_y = img_y * 255 # 将标签映射乘以255,转为灰度值
|
|
|
+ img_y = img_y.astype(np.int) # 转换为整数类型
|
|
|
cv2.imwrite(f'./tmp/mask/{file_name}_mask.png', img_y,
|
|
|
- (cv2.IMWRITE_PNG_COMPRESSION, 0))
|
|
|
- last_process(file_name)
|
|
|
- image_info = main(file_name)
|
|
|
+ (cv2.IMWRITE_PNG_COMPRESSION, 0)) # 将图像保存为PNG格式
|
|
|
+ last_process(file_name) # 调用最后处理函数
|
|
|
+ image_info = main(file_name) # 调用主函数获取图像信息
|
|
|
|
|
|
return file_name + '.png', image_info
|
|
|
|
|
|
+
|
|
|
def data_in_one(inputdata):
|
|
|
- if not inputdata.any():
|
|
|
+ if not inputdata.any(): # 如果输入数据为空则直接返回
|
|
|
return inputdata
|
|
|
- inputdata = (inputdata - inputdata.min()) / (inputdata.max() - inputdata.min())
|
|
|
+ inputdata = (inputdata - inputdata.min()) / (inputdata.max() - inputdata.min()) # 数据归一化处理
|
|
|
return inputdata
|
|
|
|
|
|
-def pre_process(data_path):
|
|
|
- file_name = os.path.split(data_path)[1].split('.')[0]
|
|
|
- return data_path, file_name
|
|
|
-
|
|
|
def last_process(file_name):
|
|
|
- ''' last process'''
|
|
|
- image = cv2.imread(f'./tmp/ct/{file_name}.png')
|
|
|
- mask = cv2.imread(f'./tmp/mask/{file_name}_mask.png', 0)
|
|
|
- contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
|
|
|
- cv2.drawContours(image, contours, -1, (0, 255, 0), 2)
|
|
|
+ '''最后的处理'''
|
|
|
+ image = cv2.imread(f'./tmp/ct/{file_name}.png') # 读取目录下的图片
|
|
|
+ mask = cv2.imread(f'./tmp/mask/{file_name}_mask.png', 0) # 以灰度图像方式读取目录下的掩膜图片
|
|
|
+ contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # 使用findContours函数找到掩膜中的轮廓
|
|
|
+ cv2.drawContours(image, contours, -1, (0, 255, 0), 2) # 在原始图片上绘制轮廓
|
|
|
cv2.imwrite('./tmp/draw/{}.png'.format(file_name), image)
|