def run( self, stack: ImageStack, ) -> Tuple[IntensityTable, ConnectedComponentDecodingResult]: """decode pixels and combine them into spots using connected component labeling Parameters ---------- stack : ImageStack ImageStack containing spots Returns ------- IntensityTable : IntensityTable containing decoded spots ConnectedComponentDecodingResult : Results of connected component labeling """ pixel_intensities = IntensityTable.from_image_stack( stack, crop_x=self.crop_x, crop_y=self.crop_y, crop_z=self.crop_z) decoded_intensities = self.codebook.metric_decode( pixel_intensities, max_distance=self.distance_threshold, min_intensity=self.magnitude_threshold, norm_order=self.norm_order, metric=self.metric ) caf = CombineAdjacentFeatures( min_area=self.min_area, max_area=self.max_area, mask_filtered_features=True ) decoded_spots, image_decoding_results = caf.run(intensities=decoded_intensities) return decoded_spots, image_decoding_results
def compute_magnitudes(stack, norm_order=2): pixel_intensities = IntensityTable.from_image_stack(zero_norm_stack) feature_traces = pixel_intensities.stack(traces=(Indices.CH.value, Indices.ROUND.value)) norm = np.linalg.norm(feature_traces.values, ord=norm_order, axis=1) return norm
def test_reshaping_between_stack_and_intensities(): """ transform an pixels of an ImageStack into an IntensityTable and back again, then verify that the created Imagestack is the same as the original """ np.random.seed(777) image = ImageStack.from_numpy_array(np.random.rand(1, 2, 3, 4, 5).astype(np.float32)) pixel_intensities = IntensityTable.from_image_stack(image, 0, 0, 0) image_shape = (image.shape['z'], image.shape['y'], image.shape['x']) image_from_pixels = pixel_intensities_to_imagestack(pixel_intensities, image_shape) assert np.array_equal(image.numpy_array, image_from_pixels.numpy_array)
def test_imagestack_to_intensity_table_no_noise(synthetic_spot_pass_through_stack): codebook, intensity_table, image = synthetic_spot_pass_through_stack pixel_intensities = IntensityTable.from_image_stack(image) pixel_intensities = codebook.metric_decode( pixel_intensities, max_distance=0, min_intensity=1000, norm_order=2) assert isinstance(pixel_intensities, IntensityTable)
def test_imagestack_to_intensity_table(): codebook, intensity_table, image = codebook_intensities_image_for_single_synthetic_spot() pixel_intensities = IntensityTable.from_image_stack(image) pixel_intensities = codebook.metric_decode( pixel_intensities, max_distance=0, min_intensity=1000, norm_order=2) assert isinstance(pixel_intensities, IntensityTable)