149 lines
8.9 KiB
Python
149 lines
8.9 KiB
Python
import numpy as np
|
||
import pandas as pd
|
||
|
||
from MIC2 import search_medicine_name, search_MIC_position, search_MIC, show_MIC, explain_MIC, \
|
||
translation_medicine_name, search_interpretation_criteria, update_location
|
||
|
||
|
||
def main_function(excel_drag, excel_standard, excel_ecv, input_image_path, output_image_path, fungus, bacteria,
|
||
crop_x=200, crop_y=240, crop_width=500, crop_height=330, draw_width=260, draw_height=260):
|
||
"""
|
||
:param excel_drag: 路径,药敏板分布的 excel表格
|
||
:param excel_standard: 路径,判断标准的 excel表格
|
||
:param excel_ecv: 路径,折点信息的 excel表格
|
||
:param input_image_path: 路径,待检验的药敏板图片
|
||
:param output_image_path: 路径,初次标注后的药敏板图片
|
||
:param fungus: string,菌属:珠菌属,隐球菌属,表示曲霉属
|
||
:param bacteria: string,菌种,中文名
|
||
:param crop_x: int,裁剪图片的 x值
|
||
:param crop_y: int,裁剪图片的 y值
|
||
:param crop_width: int,裁剪图片的宽度为 (图片的宽度 - crop_width)
|
||
:param crop_height: int,裁剪图片的高度为 (图片的高度 - crop_height)
|
||
:param draw_width: int,画框的宽度
|
||
:param draw_height: int,画框的高度
|
||
:return: medicine_name_list_chinese 药物的中文名字 [str, str, ..., str]
|
||
medicine_name_list_english 药物的英文名字 [str, str, ..., str]
|
||
show_MIC_list 展示的MIC信息 [str, str, ..., str]
|
||
final_explain MIC对应的解释信息 [str, str, ..., str]
|
||
MIC_position_list 初次拍照画框的位置 [(int, int), (int, int), ..., (int, int)]
|
||
"""
|
||
# --读取药敏板药品信息--
|
||
drug_sensitivity_plate = pd.read_excel(excel_drag)
|
||
drug_sensitivity_plate.drop(drug_sensitivity_plate.index[0], axis=0, inplace=True) # 删除第一行标题
|
||
drug_sensitivity_plate.drop(drug_sensitivity_plate.columns[0], axis=1, inplace=True) # 删除第一列序号
|
||
|
||
medicine_concentration = drug_sensitivity_plate.iloc[0:8, 0:12] # 得到 药品信息 + 浓度对应表
|
||
medicine_information = drug_sensitivity_plate.iloc[:, 13:16] # 得到 药品名称 缩写 + 英文 + 中文 对应表
|
||
|
||
# --找到药敏板中每一种药的名字(缩写)--
|
||
medicine_name_list = search_medicine_name(medicine_concentration)
|
||
# --找到药敏板药品对应的中文名字、英文名字--
|
||
medicine_name_list_chinese, medicine_name_list_english = translation_medicine_name(medicine_information,
|
||
medicine_name_list)
|
||
# --找到菌属 + 药品对应的判读方法--
|
||
interpretation_criteria = pd.read_excel(excel_standard)
|
||
judge_standard = search_interpretation_criteria(interpretation_criteria, medicine_name_list_chinese, fungus)
|
||
|
||
# --对应输入图片,根据不同菌属的判读方法,找到满足颜色需求的微孔,标记出来,保存下标记后的图片,并记下标记坐标--
|
||
MIC_position_list = search_MIC_position(input_image_path, output_image_path, judge_standard,
|
||
crop_x, crop_y, crop_width, crop_height,
|
||
draw_width, draw_height)
|
||
# --对应药敏板信息,找到对应药品的 MIC值--
|
||
medicine_MIC_list = search_MIC(medicine_concentration, MIC_position_list)
|
||
|
||
#--对应规则找到最后展示出来的 MIC信息--
|
||
show_MIC_list = show_MIC(medicine_MIC_list, MIC_position_list)
|
||
|
||
#--对应折点信息表,找到药品对应的 MIC解释信息,如果没有解释信息,返回"-1",最后不解释--
|
||
vertices_ecv = pd.read_excel(excel_ecv)
|
||
final_explain = explain_MIC(vertices_ecv, fungus, bacteria, medicine_name_list_chinese, medicine_MIC_list)
|
||
|
||
return medicine_name_list_chinese, medicine_name_list_english, show_MIC_list, final_explain, MIC_position_list
|
||
|
||
# Todo: 输入像素位置,找到对应的组,然后替换掉坐标位置,加框,按照新的坐标重新找 MIC,最终显示的 MIC,解释信息
|
||
def add_position(excel_drag, excel_ecv, input_image_path, output_image_path,
|
||
location, location_list, fungus, bacteria,
|
||
crop_x=200, crop_y=240, crop_width=500, crop_height=330, draw_width=260, draw_height=260):
|
||
"""
|
||
:param excel_drag: 路径,药敏板分布的 excel表格
|
||
:param excel_ecv: 路径,折点信息的 excel表格
|
||
:param input_image_path: 图片路径,已经经过标记过的图像
|
||
:param output_image_path: 图片路径,手动点击添加框后的图像
|
||
:param location: tuple,(height, width),新加点的位置
|
||
:param location_list: list, 原画框列表位置
|
||
:param fungus: str, 菌属
|
||
:param bacteria: str, 菌种
|
||
:param crop_x: int,裁剪图片的 x值
|
||
:param crop_y: int,裁剪图片的 y值
|
||
:param crop_width: int,裁剪图片的宽度为 (图片的宽度 - crop_width)
|
||
:param crop_height: int,裁剪图片的高度为 (图片的高度 - crop_height)
|
||
:param draw_width: int,画框的宽度
|
||
:param draw_height: int,画框的高度
|
||
:return: medicine_name_list_chinese 药物的中文名字 [str, str, ..., str]
|
||
medicine_name_list_english 药物的英文名字 [str, str, ..., str]
|
||
show_MIC_list 新的展示的MIC信息 [str, str, ..., str]
|
||
final_explain 新的MIC对应的解释信息 [str, str, ..., str]
|
||
new_location_list 新的画框位置(同一组药品内计入新画框的位置)
|
||
"""
|
||
# --读取药敏板药品信息--
|
||
drug_sensitivity_plate = pd.read_excel(excel_drag)
|
||
drug_sensitivity_plate.drop(drug_sensitivity_plate.index[0], axis=0, inplace=True) # 删除第一行标题
|
||
drug_sensitivity_plate.drop(drug_sensitivity_plate.columns[0], axis=1, inplace=True) # 删除第一列序号
|
||
|
||
medicine_concentration = drug_sensitivity_plate.iloc[0:8, 0:12] # 得到 药品信息 + 浓度对应表
|
||
medicine_information = drug_sensitivity_plate.iloc[:, 13:16] # 得到 药品名称 缩写 + 英文 + 中文 对应表
|
||
# --找到药敏板中每一种药的名字(缩写)--
|
||
medicine_name_list = search_medicine_name(drug_sensitivity_plate)
|
||
# --找到药敏板药品对应的中文名字、英文名字--
|
||
medicine_name_list_chinese, medicine_name_list_english = translation_medicine_name(medicine_information,
|
||
medicine_name_list)
|
||
#--更新位置--
|
||
new_location_list = update_location(input_image_path, output_image_path, location, location_list,
|
||
crop_x, crop_y, crop_width, crop_height, draw_width, draw_height)
|
||
# --对应药敏板信息,找到对应药品的 MIC值--
|
||
medicine_MIC_list = search_MIC(medicine_concentration, new_location_list)
|
||
|
||
#--对应规则找到最后展示出来的 MIC信息--
|
||
show_MIC_list = show_MIC(medicine_MIC_list, new_location_list)
|
||
#--对应折点信息表,找到药品对应的 MIC解释信息,如果没有解释信息,返回"-1",最后不解释--
|
||
vertices_ecv = pd.read_excel(excel_ecv)
|
||
final_explain = explain_MIC(vertices_ecv, fungus, bacteria, medicine_name_list_chinese, medicine_MIC_list)
|
||
|
||
return medicine_name_list_chinese, medicine_name_list_english, show_MIC_list, final_explain, new_location_list
|
||
|
||
|
||
if __name__ == '__main__':
|
||
chinese_name, english_name, mic, explain, pos_li = main_function(
|
||
"C:\\Users\\Liao\\Desktop\\MXK\\丹娜\\MIC\\药敏板药物信息示例\\药敏板药物信息示例.xlsx",
|
||
"C:\\Users\\Liao\\Desktop\\MXK\\丹娜\\MIC\\药敏板药物信息示例\\药敏板药品判读规则表格.xlsx",
|
||
"C:\\Users\\Liao\\Desktop\\MXK\\丹娜\\MIC\\药敏板药物信息示例\\MIC解释标准及ECV值.xlsx",
|
||
"./data/念珠结果判读/2.jpg",
|
||
"./data/res/test2_0.jpg",
|
||
"隐球菌属",
|
||
"新生隐球菌VNⅠ")
|
||
print(chinese_name)
|
||
print(english_name)
|
||
print(mic)
|
||
print(explain)
|
||
print(pos_li)
|
||
|
||
print("------新增框------")
|
||
# 按照目前图片进行裁剪,可根据如下范围设定新加的孔在哪里
|
||
# [200, 558, 916, 1274, 1632, 1990, 2348, 2706, 3064]
|
||
# [240, 598, 956, 1314, 1672, 2030, 2388, 2746, 3104, 3462, 3820, 4178, 4536]
|
||
# 比如(210, 250)就应该对应的是(1, 1)这个位置,(2780, 3900)对应的就是(8, 11)这个位置
|
||
chinese_name_new, english_name_new, mic_new, explain_new, pos_new = add_position(
|
||
"C:\\Users\\Liao\\Desktop\\MXK\\丹娜\\MIC\\药敏板药物信息示例\\药敏板药物信息示例.xlsx",
|
||
"C:\\Users\\Liao\\Desktop\\MXK\\丹娜\\MIC\\药敏板药物信息示例\\MIC解释标准及ECV值.xlsx",
|
||
"./data/res/test2_0.jpg",
|
||
"./data/res/add_test2_0.jpg",
|
||
(1500, 2500), pos_li,
|
||
"隐球菌属",
|
||
"新生隐球菌VNⅠ"
|
||
)
|
||
print(chinese_name_new)
|
||
print(english_name_new)
|
||
print(mic_new)
|
||
print(explain_new)
|
||
print(pos_new)
|