def test_local_search_blob_detector_jitter_code(): stack = jitter_code() bd = blob_detector() spot_results = bd.run(stack) intensity_table = build_traces_nearest_neighbors(spot_results=spot_results, anchor_round=1, search_radius=3) assert intensity_table.shape == (1, 2, 3) f, c, r = np.where(~intensity_table.isnull()) assert np.all(f == np.array([0, 0, 0])) assert np.all(c == np.array([0, 0, 1])) assert np.all(r == np.array([0, 2, 1])) # test again with smaller search radius bd = BlobDetector(min_sigma=1, max_sigma=4, num_sigma=30, threshold=.1) per_tile_spot_results = bd.run(stack) intensity_table = build_traces_nearest_neighbors( spot_results=per_tile_spot_results, anchor_round=0, search_radius=1) assert intensity_table.shape == (1, 2, 3) f, c, r = np.where(~intensity_table.isnull()) assert np.all(f == 0) assert np.all(c == 0) assert np.all(r == 0)
def testExactMatches(): codebook = seqfishCodebook(5, 3, 20) img, trueTargets = syntheticSeqfish(100, 100, 20, codebook, 5, 0, False) bd = BlobDetector(min_sigma=1, max_sigma=4, num_sigma=30, threshold=.1, exclude_border=False) spots = bd.run(image_stack=img) assert spots.count_total_spots( ) == 5 * 5, 'Spot detector did not find all spots' decoder = CheckAll(codebook=codebook, search_radius=1, error_rounds=0) hits = decoder.run(spots=spots, n_processes=4) testTargets = [] for i in range(len(hits)): testTargets.append( (int(hits[i]['target'].data), (int(hits[i]['x'].data), int(hits[i]['y'].data), int(hits[i]['z'].data)))) matches = 0 for true in trueTargets: for test in testTargets: if true[0] == test[0]: if test[1][0] + 1 >= true[1][0] >= test[1][0] - 1 and \ test[1][1] + 1 >= true[1][1] >= test[1][1] - 1: matches += 1 assert matches == len(trueTargets)
def simple_gaussian_spot_detector() -> BlobDetector: """create a basic gaussian spot detector""" return BlobDetector(min_sigma=1, max_sigma=4, num_sigma=5, threshold=0, measurement_type='max')
def synthetic_dataset_with_truth_values_and_called_spots(): codebook, true_intensities, image = synthetic_dataset_with_truth_values() wth = WhiteTophat(masking_radius=15) filtered = wth.run(image, in_place=False) min_sigma = 1.5 max_sigma = 4 num_sigma = 10 threshold = 1e-4 gsd = BlobDetector(min_sigma=min_sigma, max_sigma=max_sigma, num_sigma=num_sigma, threshold=threshold, measurement_type='max') spots = gsd.run(image_stack=filtered) decoder = MetricDistance(codebook=codebook, max_distance=1, min_intensity=0, norm_order=2) decoded_intensities = decoder.run(spots) assert decoded_intensities.shape[0] == 5 return codebook, true_intensities, image, decoded_intensities
def test_blob_doh_error_handling(): """ Test that BlobDetector throws a Value error if a user tries to use blob_doh on 3d data. `skimage.blob_doh` only supports 2d data. """ stack = ImageStack.from_numpy(np.zeros((4, 2, 10, 100, 100), dtype=np.float32)) blob_doh = BlobDetector( min_sigma=1, max_sigma=4, num_sigma=5, threshold=0, detector_method='blob_doh', measurement_type='max', is_volume=True) # Check that Value error gets raised when blob_doh and is_volume=True provided with pytest.raises(ValueError): blob_doh.run(stack) ref_image = stack.reduce({Axes.ROUND, Axes.CH}, func='max') # Check that Value error gets raised when blob_doh and reference image is 3d with pytest.raises(ValueError): blob_doh.run(stack, reference_image=ref_image)
def blob_detector(): return BlobDetector(min_sigma=1, max_sigma=4, num_sigma=30, threshold=.1)