Beispiel #1
0
 def _cli(ctx, primary_images, nuclei, output):
     print('Segmenting ...')
     ctx.obj = dict(
         component=Segmentation,
         output=output,
         primary_images=ImageStack.from_path_or_url(primary_images),
         nuclei=ImageStack.from_path_or_url(nuclei),
     )
Beispiel #2
0
 def _cli(ctx, primary_images, nuclei, output):
     """define polygons for cell boundaries and assign spots"""
     print('Segmenting ...')
     ctx.obj = dict(
         component=Segmentation,
         output=output,
         primary_images=ImageStack.from_path_or_url(primary_images),
         nuclei=ImageStack.from_path_or_url(nuclei),
     )
Beispiel #3
0
def test_imagestack_export(tmpdir, format, count, recwarn):
    """
    Save a synthetic stack to files and check the results
    """
    stack_shape = OrderedDict([(Axes.ROUND, 3), (Axes.CH, 2), (Axes.ZPLANE, 1),
                               (Axes.Y, 50), (Axes.X, 40)])

    physical_coords = OrderedDict([
        (PhysicalCoordinateTypes.X_MIN, X_COORDS[0]),
        (PhysicalCoordinateTypes.X_MAX, X_COORDS[1]),
        (PhysicalCoordinateTypes.Y_MIN, Y_COORDS[0]),
        (PhysicalCoordinateTypes.Y_MAX, Y_COORDS[1]),
        (PhysicalCoordinateTypes.Z_MIN, Z_COORDS[0]),
        (PhysicalCoordinateTypes.Z_MAX, Z_COORDS[1])
    ])

    stack = test_utils.imagestack_with_coords_factory(stack_shape,
                                                      physical_coords)

    stack_json = tmpdir / "output.json"
    stack.export(str(stack_json), tile_format=format)
    files = list(
        [x for x in tmpdir.listdir() if str(x).endswith(format.file_ext)])
    loaded_stack = ImageStack.from_path_or_url(str(stack_json))
    verify_physical_coordinates(
        loaded_stack,
        X_COORDS,
        Y_COORDS,
        get_physical_coordinates_of_z_plane(Z_COORDS),
    )
    assert count == len(files)
    with open(files[0], "rb") as fh:
        format.reader_func(fh)
Beispiel #4
0
 def _cli(ctx, input, output):
     print("Registering...")
     ctx.obj = dict(
         component=Registration,
         input=input,
         output=output,
         stack=ImageStack.from_path_or_url(input),
     )
Beispiel #5
0
 def _cli(ctx, input, output):
     print("Filtering images...")
     ctx.obj = dict(
         component=Filter,
         input=input,
         output=output,
         stack=ImageStack.from_path_or_url(input),
     )
Beispiel #6
0
 def _cli(ctx, input, output):
     """smooth, sharpen, denoise, etc"""
     print("Filtering images...")
     ctx.obj = dict(
         component=Filter,
         input=input,
         output=output,
         stack=ImageStack.from_path_or_url(input),
     )
Beispiel #7
0
 def _cli(ctx, input, output, codebook):
     """pixel-wise spot detection and decoding"""
     print('Detecting Spots ...')
     ctx.obj = dict(
         component=PixelSpotDecoder,
         image_stack=ImageStack.from_path_or_url(input),
         output=output,
         codebook=Codebook.from_json(codebook),
     )
Beispiel #8
0
    def _cli(cls, args, print_help=False) -> None:
        """Runs the segmentation component based on parsed arguments."""
        if args.segmentation_algorithm_class is None or print_help:
            cls.segmentation_group.print_help()
            cls.segmentation_group.exit(status=2)

        instance = args.segmentation_algorithm_class(**vars(args))

        print('Segmenting ...')
        hybridization_stack = ImageStack.from_path_or_url(
            args.hybridization_stack)
        nuclei_stack = ImageStack.from_path_or_url(args.nuclei_stack)
        regions = instance.run(hybridization_stack, nuclei_stack)
        geojson = regions_to_geojson(regions, use_hull=False)

        print("Writing | regions geojson to: {}".format(args.output))
        with open(args.output, "w") as f:
            f.write(json.dumps(geojson))
Beispiel #9
0
 def _cli(ctx, input, output):
     """translation correction of image stacks"""
     print("Registering...")
     ctx.obj = dict(
         component=Registration,
         input=input,
         output=output,
         stack=ImageStack.from_path_or_url(input),
     )
Beispiel #10
0
 def _cli(ctx, input, output, blobs_stack, reference_image_from_max_projection):
     """detect spots"""
     print('Detecting Spots ...')
     ctx.obj = dict(
         component=SpotFinder,
         image_stack=ImageStack.from_path_or_url(input),
         output=output,
         blobs_stack=blobs_stack,
         reference_image_from_max_projection=reference_image_from_max_projection,
     )
Beispiel #11
0
    def _cli(cls, args, print_help=False):
        """Runs the filter component based on parsed arguments."""

        if args.filter_algorithm_class is None or print_help:
            cls.filter_group.print_help()
            cls.filter_group.exit(status=2)

        print('Filtering images ...')
        stack = ImageStack.from_path_or_url(args.input)
        instance = args.filter_algorithm_class(**vars(args))
        output = instance.run(stack)
        output.write(args.output)
Beispiel #12
0
def test_imagestack_export(tmpdir, format, count, recwarn):
    """
    Save a synthetic stack to files and check the results
    """
    stack = ImageStack.synthetic_stack()
    stack_json = tmpdir / "output.json"
    stack.export(str(stack_json), tile_format=format)
    files = list([x for x in tmpdir.listdir() if str(x).endswith(format.file_ext)])
    assert ImageStack.from_path_or_url(str(stack_json))
    assert count == len(files)
    with open(files[0], "rb") as fh:
        format.reader_func(fh)
Beispiel #13
0
    def _cli(cls, args, print_help=False):
        """Runs the registration component based on parsed arguments."""
        if args.registration_algorithm_class is None or print_help:
            cls.register_group.print_help()
            cls.register_group.exit(status=2)

        print('Registering ...')
        stack = ImageStack.from_path_or_url(args.input)
        instance = args.registration_algorithm_class(**vars(args))
        instance.run(stack)

        stack.write(args.output)
Beispiel #14
0
    def _cli(ctx, input, output, blobs_stack,
             reference_image_from_max_projection, codebook):
        print('Detecting Spots ...')
        ctx.obj = dict(
            component=SpotFinder,
            image_stack=ImageStack.from_path_or_url(input),
            output=output,
            blobs_stack=blobs_stack,
            reference_image_from_max_projection=
            reference_image_from_max_projection,
            codebook=None,
        )

        if codebook is not None:
            ctx.obj["codebook"] = Codebook.from_json(codebook)
Beispiel #15
0
    def _cli_run(cls, ctx, instance):
        output = ctx.obj["output"]
        blobs_stack = ctx.obj["blobs_stack"]
        image_stack = ctx.obj["image_stack"]
        ref_image = ctx.obj["reference_image_from_max_projection"]
        if blobs_stack is not None:
            blobs_stack = ImageStack.from_path_or_url(
                blobs_stack)  # type: ignore
            blobs_image = blobs_stack.max_proj(Indices.ROUND, Indices.CH)
            #  TODO: this won't work for PixelSpotDectector
            intensities = instance.run(
                image_stack,
                blobs_image=blobs_image,
                reference_image_from_max_projection=ref_image,
            )
        else:
            intensities = instance.run(image_stack)

        # When PixelSpotDetector is used run() returns a tuple
        if isinstance(intensities, tuple):
            intensities = intensities[0]
        intensities.save(output)
Beispiel #16
0
    def __init__(self, upsampling: int, reference_stack: Union[str, ImageStack], **kwargs) -> None:
        """Implements fourier shift registrations, which performs a simple translation registration

        Parameters
        ----------
        upsampling : int
            images are registered to within 1 / upsample_factor of a pixel
        reference_stack : ImageStack
            the ImageStack against which this object will register images

        See Also
        --------
        https://en.wikipedia.org/wiki/Phase_correlation

        """
        self.upsampling = upsampling

        # TODO ambrosejcarr: remove the ability to load from string in the constructor, move to CLI
        if isinstance(reference_stack, ImageStack):
            self.reference_stack = reference_stack
        else:
            self.reference_stack = ImageStack.from_path_or_url(reference_stack)
Beispiel #17
0
    def _cli_run(cls, ctx, instance):
        output = ctx.obj["output"]
        blobs_stack = ctx.obj["blobs_stack"]
        image_stack = ctx.obj["image_stack"]
        ref_image = ctx.obj["reference_image_from_max_projection"]
        if blobs_stack is not None:
            blobs_stack = ImageStack.from_path_or_url(blobs_stack)  # type: ignore
            mp = blobs_stack.max_proj(Axes.ROUND, Axes.CH)
            mp_numpy = mp._squeezed_numpy(Axes.ROUND, Axes.CH)
            intensities = instance.run(
                image_stack,
                blobs_image=mp_numpy,
                reference_image_from_max_projection=ref_image,
            )
        else:
            intensities = instance.run(image_stack)

        # When run() returns a tuple, we only save the intensities for now
        # TODO ambrosejcarr find a way to save arbitrary detector results
        if isinstance(intensities, tuple):
            intensities = intensities[0]
        intensities.save(output)
Beispiel #18
0
 def load(self, input_parameter: str) -> ImageStack:
     return ImageStack.from_path_or_url(input_parameter)