Exemplo n.º 1
0
def _reprocess_image(queue: Queue) -> None:
    global stats
    while not queue.empty():
        img_data = queue.get()
        img_data["filePath"] = f"{os.path.splitext(img_data['filePath'])[0]}.tif"
        tif_filename = os.path.basename(img_data["filePath"])
        local_file = f"TEMP_{os.path.basename(img_data['id'])}"
        logger.info(f"Processing {img_data['id']}")
        if _download_source_file(img_data, local_file):
            image = _preprocess_image(img_data, local_file)
            if image:
                image.tiffsave(tif_filename, tile=True, pyramid=True, compression=config.COMPRESSION_TYPE,
                    tile_width=config.PYTIF_TILE_WIDTH, tile_height=config.PYTIF_TILE_HEIGHT, \
                    xres=config.DPI_VALUE, yres=config.DPI_VALUE) # noqa
                new_tiff = Image.tiffload(tif_filename)
                _upload_files(img_data, local_file, tif_filename)
                gql.update_item(img_data['id'], new_tiff.height, new_tiff.width)
                os.remove(tif_filename)
            os.remove(local_file)
            logger.info(f'Completed {local_file}')
        else:
            gql.remove_missing_item(img_data['id'])
            Statistic.download_err(img_data)
        Statistic.attempted()
        queue.task_done()
Exemplo n.º 2
0
 def read_func(path, region, page=None, subifd=None):  # noqa
     opts = dict(page=page)
     if subifd is not None:
         opts['subifd'] = subifd
     tiff_page = VIPSImage.tiffload(str(path), **opts)
     im = tiff_page.extract_area(region.left, region.top, region.width,
                                 region.height)
     return im
Exemplo n.º 3
0
    def read_window(self,
                    region,
                    out_width,
                    out_height,
                    c: Optional[Union[int, List[int]]] = None,
                    **other):
        tier = self.format.pyramid.most_appropriate_tier(
            region, (out_width, out_height))
        region = region.scale_to_tier(tier)

        page = tier.data.get('page_index')
        tiff_page = VIPSImage.tiffload(str(self.format.path), page=page)
        im = tiff_page.extract_area(region.left, region.top, region.width,
                                    region.height)
        return self._extract_channels(im, c)
Exemplo n.º 4
0
    def read_tile(self,
                  tile,
                  c: Optional[Union[int, List[int]]] = None,
                  **other):
        tier = tile.tier
        page = tier.data.get('page_index')
        tiff_page = VIPSImage.tiffload(str(self.format.path), page=page)

        # There is no direct access to underlying tiles in vips
        # But the following computation match vips implementation so that only the tile
        # that has to be read is read.
        # https://github.com/jcupitt/tilesrv/blob/master/tilesrv.c#L461
        # TODO: is direct tile access significantly faster ?
        im = tiff_page.extract_area(tile.left, tile.top, tile.width,
                                    tile.height)
        return self._extract_channels(im, c)