예제 #1
0
def loadOldProject(data, labels_dict):

    project = Project()
    project.importLabelsFromConfiguration(labels_dict)
    map_filename = data["Map File"]

    #convert to relative paths in case:
    dir = QDir(os.getcwd())
    map_filename = dir.relativeFilePath(map_filename)
    image_name = os.path.basename(map_filename)
    image_name = image_name[:-4]
    image = Image(id=image_name)
    image.map_px_to_mm_factor = data["Map Scale"]
    image.acquisition_date = "1955-11-05"
    channel = Channel(filename=map_filename, type="RGB")
    image.channels.append(channel)

    for blob_data in data["Segmentation Data"]:
        blob = Blob(None, 0, 0, 0)
        blob.fromDict(blob_data)
        blob.setId(int(
            blob.id))  # id should be set again to update related info
        image.annotations.addBlob(blob)

    project.images.append(image)
    return project
예제 #2
0
    def __init__(self,
                 filename=None,
                 labels={},
                 images=[],
                 correspondences=None,
                 spatial_reference_system=None,
                 metadata={},
                 image_metadata_template={}):
        self.filename = None  #filename with path of the project json
        self.labels = {key: Label(**value) for key, value in labels.items()}
        if not 'Empty' in self.labels:
            self.labels['Empty'] = Label(id='Empty',
                                         name='Empty',
                                         description=None,
                                         fill=[127, 127, 127],
                                         border=[200, 200, 200],
                                         visible=True)

        self.images = list(map(lambda img: Image(**img),
                               images))  #list of annotated images

        # dict of tables (DataFrame) of correspondences betweeen a source and a target image
        self.correspondences = {}
        if correspondences is not None:
            for key in correspondences.keys():
                source = correspondences[key]['source']
                target = correspondences[key]['target']
                self.correspondences[key] = Correspondences(
                    self.getImageFromId(source), self.getImageFromId(target))
                self.correspondences[key].fillTable(
                    correspondences[key]['correspondences'])

        self.spatial_reference_system = spatial_reference_system  #if None we assume coordinates in pixels (but Y is up or down?!)
        self.metadata = metadata  # project metadata => keyword -> value
        self.image_metadata_template = image_metadata_template  # description of metadata keywords expected in images