Ejemplo n.º 1
0
def test_reader_pixeldata(a_dataset):
    """Check json serialization of pixeldata"""
    only_pixeldata = Dataset()
    only_pixeldata.PixelData = a_dataset.PixelData
    only_pixeldata.SpecificCharacterSet = a_dataset.SpecificCharacterSet
    output = to_json(only_pixeldata)
    loaded = Dataset.from_json(json.loads(output))
    assert loaded.PixelData == a_dataset.PixelData
Ejemplo n.º 2
0
def test_reconstruct(a_dataset):
    """Read dataset, serialise, then deserialise"""
    original = list(deepcopy(a_dataset))
    reloaded = Dataset.from_json(to_json(a_dataset))

    # make sure all elements that were included are the same as original
    for data_element in reloaded:
        assert data_element in original
Ejemplo n.º 3
0
    def to_dict(self) -> Dict:
        """Serializable representation of this annotated dataset.
        Insert NO_ANNOTATION type annotations for each DICOM element, so that
        annotations can easily be added in a text editor

        """
        annotations_dict = {x.tag: x.to_dict() for x in self.annotations}
        for element in self.dataset:
            if element.tag not in annotations_dict:
                # No annotation for this tag. Add an empty one to help json editors
                annotation = EmptyAnnotation(tag=element.tag,
                                             tag_info=str(element))
                annotations_dict[annotation.tag_key] = annotation.to_dict()

        return {
            "dataset": to_json(self.dataset),
            "annotations": list(annotations_dict.values()),
            "description": self.description,
        }
Ejemplo n.º 4
0
 def to_json(self):
     return to_json(self.dataset)
Ejemplo n.º 5
0
def test_reader(a_dataset):
    """Simple load to from dicom json"""
    output = to_json(a_dataset)
    loaded = Dataset.from_json(json.loads(output))
    assert len(loaded) == 106