12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import numpy as np
- import cv2
- import os
- from .get_image_info import main
- rate = 0.5
- def predict(path, model):
- ''' predict
- Args: path - image path
- Returns: image path, image info
- '''
- global img_y
- file_name = os.path.split(path)[1].split('.')[0]
-
- x = path.replace('\\', '/')
- file_name = file_name
- print(x)
- print(file_name)
- img_y = model.predict(x)['label_map']
- img_y = img_y * 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)
- return file_name + '.png', image_info
- def data_in_one(inputdata):
- if not inputdata.any():
- return inputdata
- 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)
- cv2.imwrite('./tmp/draw/{}.png'.format(file_name), image)
|