Exemple #1
0
def test_featurevector(lt_ctx):
    shape = np.array([128, 128])
    zero = shape // 2
    a = np.array([24, 0.])
    b = np.array([0., 30])
    indices = np.mgrid[-2:3, -2:3]
    indices = np.concatenate(indices.T)

    radius = 5
    radius_outer = 10

    template = m.background_subtraction(centerX=radius_outer + 1,
                                        centerY=radius_outer + 1,
                                        imageSizeX=radius_outer * 2 + 2,
                                        imageSizeY=radius_outer * 2 + 2,
                                        radius=radius_outer,
                                        radius_inner=radius + 1,
                                        antialiased=False)

    data, indices, peaks = cbed_frame(*shape,
                                      zero,
                                      a,
                                      b,
                                      indices,
                                      radius,
                                      all_equal=True)

    dataset = MemoryDataSet(data=data,
                            tileshape=(1, *shape),
                            num_partitions=1,
                            sig_dims=2)

    match_pattern = blobfinder.UserTemplate(template=template)

    stack = functools.partial(
        blobfinder.feature_vector,
        imageSizeX=shape[1],
        imageSizeY=shape[0],
        peaks=peaks,
        match_pattern=match_pattern,
    )

    job = lt_ctx.create_mask_job(dataset=dataset,
                                 factories=stack,
                                 mask_count=len(peaks),
                                 mask_dtype=np.float32)
    res = lt_ctx.run(job)

    peak_data, _, _ = cbed_frame(*shape,
                                 zero,
                                 a,
                                 b,
                                 np.array([(0, 0)]),
                                 radius,
                                 all_equal=True)
    peak_sum = peak_data.sum()

    assert np.allclose(res.sum(), data.sum())
    assert np.allclose(res, peak_sum)
Exemple #2
0
 def get_mask(self, sig_shape):
     return masks.background_subtraction(centerY=sig_shape[0] // 2,
                                         centerX=sig_shape[1] // 2,
                                         imageSizeY=sig_shape[0],
                                         imageSizeX=sig_shape[1],
                                         radius=self.radius_outer,
                                         radius_inner=self.radius,
                                         antialiased=True)
Exemple #3
0
def test_background_subtraction():
    mask = m.background_subtraction(10, 10, 20, 20, 5, 3)
    assert (np.allclose(np.sum(mask), 0))