Skip to content

Instantly share code, notes, and snippets.

@3dimaging
Created July 3, 2018 12:55
Show Gist options
  • Save 3dimaging/f6271a0daf85faf077290d37f90aeb95 to your computer and use it in GitHub Desktop.
Save 3dimaging/f6271a0daf85faf077290d37f90aeb95 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import multiresolutionimageinterface as mir
import matplotlib.pyplot as plt
reader = mir.MultiResolutionImageReader()
mr_image = reader.open('/home/wli/Downloads/tumor_009.tif')
# dims=mr_image.getLevelDimensions(6)
# tile = mr_image.getUCharPatch(0, 0, dims[0], dims[1], 6)
# plt.imshow(tile)
# plt.show()
annotation_list=mir.AnnotationList()
xml_repository = mir.XmlRepository(annotation_list)
xml_repository.setSource('/home/wli/Downloads/tumor_009.xml')
xml_repository.load()
#annotation=annotation_list.getAnnotation(0)
#print(annotation.getArea())
#print(annotation.getNumberOfPoints())
#print(annotation.getCoordinate(0).getX())
annotation_mask=mir.AnnotationToMask()
camelyon17_type_mask = False
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='/home/wli/Downloads/tumor_009_labels.tif'
annotation_mask.convert(annotation_list, output_path, mr_image.getDimensions(), mr_image.getSpacing(), label_map, conversion_order)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment