Exemplo n.º 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
Exemplo n.º 2
0
    def addChannel(self, filename, type):
        """
        This image add a channel to this image. The functions update the size (in pixels) and
        the georeferencing information (if the image if georeferenced).
        The image data is loaded when the image channel is used for the first time.
        """

        img = rio.open(filename)

        # check image size consistency (all the channels must have the same size)
        if self.width is not None and self.height is not None:
            if self.width != img.width or self.height != img.height:
                raise Exception(
                    "Size of the images is not consistent! It is " +
                    str(img.width) + "x" + str(img.height) +
                    ", should have been: " + str(self.width) + "x" +
                    str(self.height))
                return

        # check image size limits
        if img.width > 32767 or img.height > 32767:
            raise Exception(
                "This map exceeds the image dimension handled by TagLab (the maximum size is 32767 x 32767)."
            )
            return

        if img.crs is not None:
            # this image contains georeference information
            self.georef_filename = filename

        self.width = img.width
        self.height = img.height

        self.channels.append(Channel(filename, type))
Exemplo n.º 3
0
    def __init__(self,
                 rect=[0.0, 0.0, 0.0, 0.0],
                 map_px_to_mm_factor=1.0,
                 width=None,
                 height=None,
                 channels=[],
                 id=None,
                 name=None,
                 acquisition_date="",
                 georef_filename="",
                 workspace=[],
                 metadata={},
                 annotations={},
                 working_area=[]):

        #we have to select a standanrd enforced!
        #in image standard (x, y, width height)
        #in numpy standard (y, x, height, width) #no the mixed format we use now I REFUSE to use it.
        #in range np format: (top, left, bottom, right)
        #in GIS standard (bottom, left, top, right)
        self.rect = rect  #coordinates of the image. (in the spatial reference system)
        self.map_px_to_mm_factor = map_px_to_mm_factor  #if we have a references system we should be able to recover this numner
        # otherwise we need to specify it.
        self.width = width
        self.height = height  #in pixels!

        self.annotations = Annotation()
        for data in annotations:
            blob = Blob(None, 0, 0, 0)
            blob.fromDict(data)
            self.annotations.addBlob(blob)

        self.channels = list(map(lambda c: Channel(**c), channels))

        self.id = id  # internal id used in correspondences it will never changes
        self.name = name  # a label for an annotated image
        self.workspace = workspace  # a polygon in spatial reference system
        self.working_area = working_area  # this is the working area of data exports for training
        self.acquisition_date = acquisition_date  # acquisition date is mandatory (format YYYY-MM-DD)
        self.georef_filename = georef_filename  # image file (GeoTiff) contained the georeferencing information
        self.metadata = metadata  # this follows image_metadata_template, do we want to allow freedom to add custome values?