Unable to generate masks from .xml built through custom annotated WSI
MalviyaR opened this issue · 0 comments
MalviyaR commented
Hello,
I am using ASAP 1.9 to generate customized annotations and save them as .xml files. Thus generated .xml file is fine, but when I use AnnotationtoMask.py to generate masks I am getting a blank image for the custom annotations I have done. However, the same code generates the masks for the annotations (.xml files) given with the dataset.
Please help me with this.
Thanks
Following is the code:
import os
import multiresolutionimageinterface as mir
reader = mir.MultiResolutionImageReader()
train_dataset_path = "F:\\CAMELYON17\\OriginalImagesGivenAnnotations"
anno_path = "F:\\CAMELYON17\\Training\\annotation\\" # path to annotation file
xml_files = os.listdir(anno_path)
for entry in os.listdir(anno_path):
print(entry)
annofile_lc = entry if len(entry) == 25 else None
img_path = train_dataset_path
# Looping
for item in os.listdir(img_path):
print(item)
if item.startswith(entry[0:-7]):
item = item
print(item)
wsi_path = train_dataset_path + '/' + item
print(wsi_path)
mr_image = reader.open(wsi_path)
try:
annotation_list = mir.AnnotationList()
xml_repository = mir.XmlRepository(annotation_list)
xml_repository.setSource(anno_path + annofile_lc)
xml_repository.load()
annotation_mask = mir.AnnotationToMask()
camelyon17_type_mask = True
label_map = {'metastases': 1, 'normal': 2} if camelyon17_type_mask else {'_0': 1, '_1': 1, '_2': 0}
conversion_order = ['metastases', 'normal'] if camelyon17_type_mask else ['_0', '_1', '_2']
output_path = ('G:\\DataPrep\\LocalContext\\WSI50Masks\\' + entry[0:-4] + 'try_mask.tif')
annotation_mask.convert(annotation_list, output_path, mr_image.getDimensions(), mr_image.getSpacing(), label_map, conversion_order)
except:
mr_image is None