使用openslide和xlm
核心代码:
def split_svs(name: str, start_x: int, start_y: int, end_x: int, end_y: int):
img = np.array(g_slide.read_region((start_x, start_y), level=0, size=(end_x-start_x, end_y-start_y)), dtype=np.uint8)
# 保存图像
imageio.imsave(g_output + "/" + name + ".tif", img)
# img = np.array(slide.read_region((start_x, start_y), level=0, size=(width, height)), dtype=np.uint8)
# imageio.imsave(out_path + "/test.tif", img)
def parse_xml(file_path: str):
# xml
tree = ET.parse(file_path)
root = tree.getroot()
# 获取标签名
for annotations in root:
for annotation in annotations:
coordinates = annotation.find('Coordinates')
print(annotation.attrib['Name'])
print(int(float(coordinates[0].attrib['X'])))
split_svs(
annotation.attrib['Name'],
int(float(coordinates[0].attrib['X'])), int(float(coordinates[0].attrib['Y'])),
int(float(coordinates[2].attrib['X'])), int(float(coordinates[2].attrib['Y']))
)
怎么让输出的图像以它在原图像中的行和列来命名
比如他是第一行第二个被标注的图,那就以1.2来命名