Example #1
0
    def from_url(cls, url: str, baseurl: Optional[str], aligned_group: int = 0):
        """
        Constructs an ImageStack object from a URL and a base URL.

        The following examples will all load from the same location:

        - url: https://www.example.com/images/primary_images.json  baseurl: None
        - url: https://www.example.com/images/primary_images.json  baseurl: I_am_ignored
        - url: primary_images.json  baseurl: https://www.example.com/images
        - url: images/primary_images.json  baseurl: https://www.example.com

        Parameters
        ----------
        url : str
            Either an absolute URL or a relative URL referring to the image to be read.
        baseurl : Optional[str]
            If url is a relative URL, then this must be provided.  If url is an absolute URL, then
            this parameter is ignored.
        aligned_group: int
            Which aligned tile group to load into the Imagestack, only applies if the
            tileset is unaligned. Default 0 (the first group)

        Returns
        -------
        ImageStack :
            An ImageStack representing encapsulating the data from the TileSet.
        """
        config = StarfishConfig()
        tileset = Reader.parse_doc(url, baseurl, backend_config=config.slicedimage)
        coordinate_groups = CropParameters.parse_aligned_groups(tileset)
        crop_params = coordinate_groups[aligned_group]
        return cls.from_tileset(tileset, crop_parameters=crop_params)
Example #2
0
 def __init__(
         self, name: str,
         image_tilesets: MutableMapping[str, TileSet]
 ) -> None:
     self._images: MutableMapping[str, TileSet] = dict()
     self._name = name
     self.aligned_coordinate_groups: Dict[str, List[CropParameters]] = dict()
     for name, tileset in image_tilesets.items():
         self.aligned_coordinate_groups[name] = CropParameters.parse_coordinate_groups(tileset)
     self._images = image_tilesets
Example #3
0
    def get_images(
        self,
        item: str,
        rounds: Optional[Collection[int]] = None,
        chs: Optional[Collection[int]] = None,
        zplanes: Optional[Collection[int]] = None,
        x: Optional[Union[int, slice]] = None,
        y: Optional[Union[int, slice]] = None,
    ) -> Iterator[ImageStack]:
        """
        Load into memory the an iterator of aligned Imagestacks for the given tileset and selected
        axes.

        Parameters
        ----------
        item: str
            The name of the tileset ex. 'primary' or 'nuclei'
        rounds : Optional[Collection[int]]
            The rounds in the original dataset to load into the ImageStack/s.  If this is not set,
            then all rounds are loaded into the ImageStack.
        chs : Optional[Collection[int]]
            The channels in the original dataset to load into the ImageStac/s.  If this is not set,
            then all channels are loaded into the ImageStack.
        zplanes : Optional[Collection[int]]
            The z-layers in the original dataset to load into the ImageStack/s.  If this is not set,
            then all z-layers are loaded into the ImageStack.
        x : Optional[Union[int, slice]]
            The x-range in the x-y tile that is loaded into the ImageStack/s.  If this is not set,
            then the entire x-y tile is loaded into the ImageStack.
        y : Optional[Union[int, slice]]
            The y-range in the x-y tile that is loaded into the ImageStack/s.  If this is not set,
            then the entire x-y tile is loaded into the ImageStack.

        Returns
        -------
        AlignedImageStackIterator
            The instantiated ImageStack or list of Imagestacks if the parameters given include
            multiple aligned groups.

        """
        # Parse the tileset into aligned groups, only include tiles from selected axes.
        aligned_groups = CropParameters.parse_aligned_groups(
            self._images[item],
            rounds=rounds,
            chs=chs,
            zplanes=zplanes,
            x=x,
            y=y)
        aligned_stack_iterator = AlignedImageStackIterator(
            tileset=self._images[item], aligned_groups=aligned_groups)
        return aligned_stack_iterator