Ejemplo n.º 1
0
 def set_rgb_image(self, rgb_image):
     with self.output:
         if self.last_image_layer:
             self.map.remove_layer(self.last_image_layer)
         url = vaex.image.rgba_to_url(rgb_image[::-1, ::].copy())
         image = ll.ImageOverlay(url=url, bounds=list(self.map.bounds))
         self.map.add_layer(image)
         self.last_image_layer = image
Ejemplo n.º 2
0
 def update_image(self, rgb_image):
     if self.last_image_layer:
         self.map.remove_layer(self.last_image_layer)
     url = vaex.image.rgba_to_url(rgb_image[::-1, ::].copy())
     image = ll.ImageOverlay(url=url, bounds=self.map.bounds)
     #print("add ", self.limits, self.map.bounds)
     self.last_image_layer = image
     self.map.add_layer(image)
Ejemplo n.º 3
0
    def load_raster(self, path, **kwargs):
        """Load Raster Files

        Args:
            path: string - path to the raster file

        Kwargs:
            bandno: int - band number of the raster to be displayed
            cmap: string - colormap to be used to display the raster
        """

        bandno = kwargs.get('bandno', 1)
        cmap = kwargs.get('cmap', None)

        # Create Raser Object
        raster = data.Raster(path)

        # Convert raster band to array
        array = raster.dataset.read(bandno)

        # Set raster crs
        crs = raster.crs

        # Set extent
        extent = [
            raster.bounds.left, raster.bounds.right, raster.bounds.bottom,
            raster.bounds.top
        ]

        # Extent Coordinates have to be converted to WGS84 to be displayed on the map
        if crs is None or crs == 'EPSG:4326':
            extent_transf = extent
        else:
            proj_custom = Proj(init=crs)
            proj_deafult = Proj(init='EPSG:4326')

            extent_transf = np.zeros(4)

            extent_transf[0], extent_transf[1] = transform(
                proj_custom, proj_deafult, extent[0], extent[2])
            extent_transf[2], extent_transf[3] = transform(
                proj_custom, proj_deafult, extent[1], extent[3])

        # TODO: Implement ImageOverlay with TIFF and make colormaps work, currently only import as b/w image

        # Array is saved as PNG File for the Image Overlay
        plt.imsave('%s.png' % raster.name, array, cmap=cmap)

        # Creating Image Overlay
        image_overlay = ipyleaflet.ImageOverlay(url='%s.png' % raster.name,
                                                name=raster.name,
                                                bounds=((extent_transf[1],
                                                         extent_transf[0]),
                                                        (extent_transf[3],
                                                         extent_transf[2])))

        return image_overlay
Ejemplo n.º 4
0
        def raster_dynamic(self):
            """Animation of images, initialize layer with the first image in temp
            :return:
            """
            temp_path = self.p["temp_path"]
            bounds = self.p["task"]["options"]["Bounds"]
            layer = ill.ImageOverlay(
                url="",
                bounds=bounds
            )

            first_img = os.path.join(temp_path, self.file_list[0])
            layer.url = self.read_image(first_img)

            return layer
Ejemplo n.º 5
0
        def raster_static(self):
            """Single image or ghost view of multiple images
            :return:
            """
            temp_path = self.p["temp_path"]
            bounds = self.p["task"]["options"]["Bounds"]
            layer = ill.ImageOverlay(
                url="",
                bounds=bounds
            )

            # create average image
            ims = []
            for f in self.file_list:
                fp = os.path.join(temp_path, f)
                ims.append(Image.open(fp, mode="r"))
            ims = np.array([np.array(im) for im in ims])
            imave = np.average(ims, axis=0)
            result = Image.fromarray(imave.astype("uint8"))
            target_path = os.path.join(temp_path, "ghost.png")
            result.save(target_path, "PNG")
            layer.url = self.read_image(target_path)
            os.remove(target_path)
            return layer