def _cli(cls, args, print_help=False): """Runs the spot finder component based on parsed arguments.""" if args.spot_finder_algorithm_class is None or print_help: cls.spot_finder_group.print_help() cls.spot_finder_group.exit(status=2) print('Detecting Spots ...') hybridization_stack = ImageStack.from_path_or_url(args.input) instance = args.spot_finder_algorithm_class(**vars(args)) spot_attributes, encoded_spots = instance.find(hybridization_stack) if args.show: encoded_spots.show(figsize=(10, 10)) path = os.path.join(args.output, 'spots.geojson') print(f"Writing | spots geojson to: {path}") spot_attributes.save_geojson(path) path = os.path.join(args.output, 'spots.json') print(f"Writing | spot_id | x | y | z | to: {path}") spot_attributes.save(path) path = os.path.join(args.output, 'encoder_table.json') print(f"Writing | spot_id | hyb | ch | val | to: {path}") encoded_spots.save(path)
def __init__(self, min_sigma, max_sigma, num_sigma, threshold, blobs_stack, overlap=0.5, measurement_type='max', is_volume: bool = True, **kwargs) -> None: """Multi-dimensional gaussian spot detector Parameters ---------- min_sigma : float The minimum standard deviation for Gaussian Kernel. Keep this low to detect smaller blobs. max_sigma : float The maximum standard deviation for Gaussian Kernel. Keep this high to detect larger blobs. num_sigma : int The number of intermediate values of standard deviations to consider between `min_sigma` and `max_sigma`. threshold : float The absolute lower bound for scale space maxima. Local maxima smaller than thresh are ignored. Reduce this to detect blobs with less intensities. overlap : float [0, 1] If two spots have more than this fraction of overlap, the spots are combined (default = 0.5) blobs_stack : Union[ImageStack, str] ImageStack or the path or URL that references the ImageStack that contains the blobs. measurement_type : str ['max', 'mean'] name of the function used to calculate the intensity for each identified spot area Notes ----- This spot detector is very sensitive to the threshold that is selected, and the threshold is defined as an absolute value -- therefore it must be adjusted depending on the datatype of the passed image. """ self.min_sigma = min_sigma self.max_sigma = max_sigma self.num_sigma = num_sigma self.threshold = threshold self.overlap = overlap self.is_volume = is_volume if isinstance(blobs_stack, ImageStack): self.blobs_stack = blobs_stack else: self.blobs_stack = ImageStack.from_path_or_url(blobs_stack) self.blobs_image: np.ndarray = self.blobs_stack.max_proj( Indices.HYB, Indices.CH) try: self.measurement_function = getattr(np, measurement_type) except AttributeError: raise ValueError( f'measurement_type must be a numpy reduce function such as "max" or "mean". {measurement_type} ' f'not found.')
def __init__(self, upsampling: int, reference_stack: Union[str, ImageStack], **kwargs) -> None: self.upsampling = upsampling if isinstance(reference_stack, ImageStack): self.reference_stack = reference_stack else: self.reference_stack = ImageStack.from_path_or_url(reference_stack)
def _cli(cls, args, print_help=False): """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.segment(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))
def _cli(cls, args, print_help=False): """Runs the spot finder component based on parsed arguments.""" if args.spot_finder_algorithm_class is None or print_help: cls.spot_finder_group.print_help() cls.spot_finder_group.exit(status=2) print('Detecting Spots ...') hybridization_stack = ImageStack.from_path_or_url(args.input) instance = args.spot_finder_algorithm_class(**vars(args)) intensities = instance.find(hybridization_stack) intensities.save(os.path.join(args.output, 'spots.nc'))
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.register(stack) stack.write(args.output)