首先需要下载一个工具,这个工具的地址在这工具下载,这个工具可以实现kfb转成svs格式,但是一次只能转一个文件(压缩包里面有使用教程)
如果要将大量的kfb文件装成svs文件,用这个工具就会比较麻烦,因此可以写一个Python脚本调用这个工具以实现批量转换的功能,下面是代码:
import os
import sys
import subprocess
from time import time
from glob import glob
def main():
#Set your 'src_folder_name' , 'des_folder_name' and 'level'
src_folder_name = 'F:\\CLAM_DATA\\radiotherapy'#KFB文件所在文件夹
des_folder_name = 'F:\\CLAM_DATA\\Test_data' #保存SVS文件的文件夹
level = 9
# argvs = sys.argv
# if len(argvs) != 4:
# raise AttributeError('Example: convert_kfb2svs.py [src_folder_name] [des_folder_name] [level]')
exe_path = r'F:\CLAM_DATA\kfb_to_svs_Tool\x86\KFbioConverter.exe' #下载的转换程序所在文件夹
if not os.path.exists(exe_path):
raise FileNotFoundError('Could not find convert library.')
# _, src_folder_name, des_folder_name, level = tuple(argvs)
if int(level) < 2 or int(level) > 9:
raise AttributeError('NOTE: 2 < [level] <= 9')
pwd = os.popen('chdir').read().strip()
full_path = os.path.join(pwd, src_folder_name)
dest_path = os.path.join(pwd, des_folder_name)
if not os.path.exists(full_path):
raise FileNotFoundError(f'could not get into dir {src_folder_name}')
if not os.path.exists(dest_path):
os.makedirs(dest_path)
kfb_list = os.popen(f'dir {full_path}').read().split('\n')
kfb_list = [elem.split(' ')[-1] for elem in kfb_list if elem.endswith('kfb')]
print(f'Found {len(kfb_list)} slides, transfering to svs format ...')
for elem in kfb_list:
st = time()
kfb_elem_path = os.path.join(full_path, elem)
svs_dest_path = os.path.join(dest_path, elem.replace('.kfb', '.svs'))
command = f'{exe_path} {kfb_elem_path} {svs_dest_path} {level}'
print(f'Processing {elem} ...')
p = subprocess.Popen(command)
p.wait()
print(f'\nFinished {elem}, time: {time() - st}s ...')
if __name__ == "__main__":
main()
参考链接:将KFB文件转为SVS文件 - 知乎