liuyuqi-dellpc 1 year ago
parent
commit
51dccf9506
2 changed files with 20 additions and 41 deletions
  1. 0 17
      README.md
  2. 20 24
      medical_assist/assist.py

+ 0 - 17
README.md

@@ -2,8 +2,6 @@
 
 基于Paddle+Flask的眼部医疗辅助系统, 本项目基于PaddleX提供的FastSCNN语义分割模型,在眼部图像视盘分割数据集上进行训练,并开发了前后端分离项目。
 
-后端代码基于Flask开发,前端WEB界面基于VUE开发。
-
 ![](https://ai-studio-static-online.cdn.bcebos.com/936a7f88ceac4085924961e023e0b974e38138def41444dfaf6a58cec091ec4d)
 
 ## Develop
@@ -29,21 +27,6 @@ python app.py
 
 ### 模型预测
 
-使用模型进行预测,同时使用`pdx.seg.visualize`将结果可视化,可视化结果将保存到`./output/deeplab`下,其中`weight`代表原图的权重,即mask可视化结果与原图权重因子。
-
-
-
-
-```python
-!zip -r inference_model/ weights.zip
-```
-
-    	zip warning: name not matched: weights.zip
-    
-    zip error: Nothing to do! (try: zip -r inference_model/ . -i weights.zip)
-
-
-
 ## Reference
 
 

+ 20 - 24
medical_assist/assist.py

@@ -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)