当前位置: 首页>>代码示例>>Python>>正文


Python trackpy.locate函数代码示例

本文整理汇总了Python中trackpy.locate函数的典型用法代码示例。如果您正苦于以下问题:Python locate函数的具体用法?Python locate怎么用?Python locate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了locate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_topn

    def test_topn(self):
        self.check_skip()
        L = 21
        dims = (L, L + 2)  # avoid square images in tests
        cols = ['x', 'y']
        PRECISION = 0.1

        # top 2
        pos1 = np.array([7, 7])
        pos2 = np.array([14, 14])
        pos3 = np.array([7, 14])
        image = np.ones(dims, dtype='uint8')
        draw_point(image, pos1, 100)
        draw_point(image, pos2, 90)
        draw_point(image, pos3, 80)
        actual = tp.locate(image, 5, 1, topn=2, preprocess=False,
                           engine=self.engine)[cols]
        actual = actual.sort(['x', 'y'])  # sort for reliable comparison
        expected = DataFrame([pos1, pos2], columns=cols).sort(['x', 'y'])
        assert_allclose(actual, expected, atol=PRECISION)

        # top 1
        actual = tp.locate(image, 5, 1, topn=1, preprocess=False,
                           engine=self.engine)[cols]
        actual = actual.sort(['x', 'y'])  # sort for reliable comparison
        expected = DataFrame([pos1], columns=cols).sort(['x', 'y'])
        assert_allclose(actual, expected, atol=PRECISION)
开发者ID:neilpanchal,项目名称:trackpy,代码行数:27,代码来源:test_feature.py

示例2: test_flat_peak

    def test_flat_peak(self):
        # This tests the part of locate_maxima that eliminates multiple
        # maxima in the same mask area.
        self.check_skip()
        image = np.ones((21, 23)).astype(np.uint8)
        image[11, 13] = 100
        image[11, 14] = 100
        image[12, 13] = 100
        count = len(tp.locate(image, 5, preprocess=False))
        self.assertEqual(count, 1)

        image = np.ones((21, 23)).astype(np.uint8)
        image[11, 13] = 100
        image[11, 14] = 100
        image[12, 13] = 100
        image[12, 13] = 100
        count = len(tp.locate(image, 5, preprocess=False))
        self.assertEqual(count, 1)

        image = np.ones((21, 23)).astype(np.uint8)
        image[11, 13] = 100
        image[11, 14] = 100
        image[11, 15] = 100
        count = len(tp.locate(image, 5, preprocess=False))
        self.assertEqual(count, 1)
开发者ID:JoshuaSkootsky,项目名称:trackpy,代码行数:25,代码来源:test_feature.py

示例3: test_eccentricity

    def test_eccentricity(self):
        # Eccentricity (elongation) is measured with good accuracy and
        # ~0.02 precision, as long as the mask is large enough to cover
        # the whole object.
        self.check_skip()
        L = 501 
        dims = (L + 2, L)  # avoid square images in tests
        pos = [50, 55]
        cols = ['x', 'y']

        ECC = 0
        image = np.ones(dims, dtype='uint8')
        draw_gaussian_spot(image, pos, 4, ecc=ECC)
        actual = tp.locate(image, 21, 1, preprocess=False,
                           engine=self.engine)['ecc']
        expected = ECC
        assert_allclose(actual, expected, atol=0.02)

        ECC = 0.2
        image = np.ones(dims, dtype='uint8')
        draw_gaussian_spot(image, pos, 4, ecc=ECC)
        actual = tp.locate(image, 21, 1, preprocess=False,
                           engine=self.engine)['ecc']
        expected = ECC
        assert_allclose(actual, expected, atol=0.1)

        ECC = 0.5
        image = np.ones(dims, dtype='uint8')
        draw_gaussian_spot(image, pos, 4, ecc=ECC)
        actual = tp.locate(image, 21, 1, preprocess=False,
                           engine=self.engine)['ecc']
        expected = ECC
        assert_allclose(actual, expected, atol=0.1)
开发者ID:neilpanchal,项目名称:trackpy,代码行数:33,代码来源:test_feature.py

示例4: test_nocharacterize

    def test_nocharacterize(self):
        pos = gen_nonoverlapping_locations((200, 300), 9, 5)
        image = draw_spots((200, 300), pos, 5)
        f_c = tp.locate(image, 5, engine=self.engine, characterize=True)
        f_nc = tp.locate(image, 5, engine=self.engine, characterize=False)

        assert len(f_nc.columns) == 3
        assert_allclose(f_c.values[:, :3], f_nc.values)
开发者ID:danielballan,项目名称:trackpy,代码行数:8,代码来源:test_feature.py

示例5: setup

    def setup(self):
        shape = (100, 101)
        r = 3
        noise_level = 0.01
        cases = {"sparse": 5, "dense": 100}
        for case_name, count in cases.items():
            locations = gen_random_locations(shape, count)
            image = draw_spots(shape, locations, r, noise_level)
            setattr(self, "{0}_image".format(case_name), image)

        # Prime FFTW (if it's there).
        tp.locate(self.sparse_image, 7)
开发者ID:nkeim,项目名称:trackpy-bench,代码行数:12,代码来源:benchmarks.py

示例6: test_warn_color_image

    def test_warn_color_image(self):
        self.check_skip()

        # RGB-like
        image = np.random.randint(0, 100, (21, 23, 3)).astype(np.uint8)
        with assert_produces_warning(UserWarning):
            tp.locate(image, 5)

        # RGBA-like
        image = np.random.randint(0, 100, (21, 23, 4)).astype(np.uint8)
        with assert_produces_warning(UserWarning):
            tp.locate(image, 5)
开发者ID:neilpanchal,项目名称:trackpy,代码行数:12,代码来源:test_feature.py

示例7: bckgrd_pdetect

    def bckgrd_pdetect(self, thld=100, progress_barF=None, Print=True, **kwargs):
        '''Such as:
        P_dfs = bckgrd_pdetect(thld=125,
                      diameter=(5,5), 
                      minmass=300, 
                      invert=True)
        thld : thershold, a TRUE particle must be darker than the backgroud image by this amount
        progress_barF : a handle for external status bar (such as in a GUI)
        Print         : print out this frame number that is currently processing
        **kwars       : additional parameters passed to trackpy.locate() method

        Returns
        a pandas.DataFrame containing the information of all particles (both True and False ones) detected
        '''
        particle_dfs = []
        for _idx, _img in enumerate(self.img_stack):
            if progress_barF is None:
                pass
            else:
                progress_barF(_idx, len(self.img_stack))
            _f_df = tp.locate(_img, **kwargs)
            if len(_f_df)>1:
                _f_df['ST_dsty'] = [self._area_density(_f_df.ix[i, 'x'], 
                                                       _f_df.ix[i, 'y'],
                                                       _f_df.ix[i, 'size'], 
                                                       255-self.crtd_image[_idx]) 
                                    for i in range(len(_f_df))]
                _f_df['True_particle'] = (_f_df['ST_dsty']>thld)
                _f_df['Timestamp']     = _idx*(1./self.frame_rate) #if frame rate is know may convert to timestamp
                _f_df['frame']         = _idx                      #must have it to make the tracker work
            particle_dfs.append(_f_df)
            if Print:
                print_update('Analyzing frame %s'%_idx)
            self.particle_dfs = particle_dfs
        return particle_dfs
开发者ID:ctzhu,项目名称:vial_detector,代码行数:35,代码来源:detector.py

示例8: test_all_maxima_filtered

 def test_all_maxima_filtered(self):
     self.check_skip()
     black_image = np.ones((21, 23)).astype(np.uint8)
     draw_point(black_image, [11, 13], 10)
     with assert_produces_warning(UserWarning):
         f = tp.locate(black_image, 5, minmass=1000,
                       engine=self.engine, preprocess=False)
开发者ID:neilpanchal,项目名称:trackpy,代码行数:7,代码来源:test_feature.py

示例9: compare

def compare(shape, count, radius, noise_level, engine):
    pos = gen_random_locations(shape, count) 
    image = draw_spots(shape, pos, radius, noise_level)
    f = tp.locate(image, 2*radius + 1, minmass=1800, engine=engine)
    actual = f[['x', 'y']].sort(['x', 'y'])
    expected = DataFrame(pos, columns=['x', 'y']).sort(['x', 'y']) 
    return actual, expected
开发者ID:neilpanchal,项目名称:trackpy,代码行数:7,代码来源:test_feature.py

示例10: test_oldmass_16bit

    def test_oldmass_16bit(self):
        old_minmass = 2800000
        im = draw_spots(self.shape, self.pos, self.size, bitdepth=16,
                        noise_level=10000)

        new_minmass = self.minmass_v02_to_v04(im, old_minmass)
        f = tp.locate(im, self.tp_diameter, minmass=new_minmass)
        assert len(f) == self.N
开发者ID:caspervdw,项目名称:trackpy,代码行数:8,代码来源:test_feature.py

示例11: test_rg

    def test_rg(self):
        # For Gaussians with radii 2, 3, 5, and 7 px, with proportionately
        # chosen feature (mask) sizes, the 'size' comes out to be within 10%
        # of the true Gaussian width.

        # The IDL code has mistake in this area, documented here:
        # http://www.physics.emory.edu/~weeks/idl/radius.html

        self.check_skip()
        L = 101 
        dims = (L, L + 2)  # avoid square images in tests
        pos = [50, 55]
        cols = ['x', 'y']

        SIZE = 2
        image = np.ones(dims, dtype='uint8')
        draw_gaussian_spot(image, pos, SIZE)
        actual = tp.locate(image, 7, 1, preprocess=False,
                           engine=self.engine)['size']
        expected = SIZE
        assert_allclose(actual, expected, rtol=0.1)

        SIZE = 3
        image = np.ones(dims, dtype='uint8')
        draw_gaussian_spot(image, pos, SIZE)
        actual = tp.locate(image, 11, 1, preprocess=False,
                           engine=self.engine)['size']
        expected = SIZE
        assert_allclose(actual, expected, rtol=0.1)

        SIZE = 5
        image = np.ones(dims, dtype='uint8')
        draw_gaussian_spot(image, pos, SIZE)
        actual = tp.locate(image, 17, 1, preprocess=False,
                           engine=self.engine)['size']
        expected = SIZE
        assert_allclose(actual, expected, rtol=0.1)
        
        SIZE = 7
        image = np.ones(dims, dtype='uint8')
        draw_gaussian_spot(image, pos, SIZE)
        actual = tp.locate(image, 23, 1, preprocess=False,
                           engine=self.engine)['size']
        expected = SIZE
        assert_allclose(actual, expected, rtol=0.1)
开发者ID:neilpanchal,项目名称:trackpy,代码行数:45,代码来源:test_feature.py

示例12: test_oldmass_float

    def test_oldmass_float(self):
        old_minmass = 5500
        im = draw_spots(self.shape, self.pos, self.size, bitdepth=8,
                        noise_level=50)
        im = (im / im.max()).astype(np.float)

        new_minmass = self.minmass_v02_to_v04(im, old_minmass)
        f = tp.locate(im, self.tp_diameter, minmass=new_minmass)
        assert len(f) == self.N
开发者ID:caspervdw,项目名称:trackpy,代码行数:9,代码来源:test_feature.py

示例13: test_ep

    def test_ep(self):
        # Test whether the estimated static error equals the rms deviation from
        # the expected values. Next to the feature mass, the static error is
        # calculated from the estimated image background level and variance.
        # This estimate is also tested here.

        # A threshold is necessary to identify the background array so that
        # background average and standard deviation can be estimated within 1%
        # accuracy.

        # The tolerance for ep in this test is 0.001 px or 20%.
        # This amounts to roughly the following rms error values:
        # noise / signal = 0.01 : 0.004+-0.001 px
        # noise / signal = 0.02 : 0.008+-0.002 px
        # noise / signal = 0.05 : 0.02+-0.004 px
        # noise / signal = 0.1 : 0.04+-0.008 px
        # noise / signal = 0.2 : 0.08+-0.016 px
        # noise / signal = 0.3 : 0.12+-0.024 px
        # noise / signal = 0.5 : 0.2+-0.04 px
        # Parameters are tweaked so that there is no deviation due to a too
        # small mask size. Noise/signal ratios up to 50% are tested.
        self.check_skip()
        draw_size = 4.5
        locate_diameter = 21
        N = 200
        noise_levels = (np.array([0.01, 0.02, 0.05, 0.1, 0.2, 0.3, 0.5]) * (2**12 - 1)).astype(np.int)
        real_rms_dev = []
        eps = []
        actual_black_level = []
        actual_noise = []
        expected, image = draw_array(N, draw_size, bitdepth=12)
        for n, noise_level in enumerate(noise_levels):
            image_noisy = image + np.array(np.random.randint(0, noise_level,
                                                             image.shape),
                                           dtype=image.dtype)

            f = tp.locate(image_noisy, locate_diameter, engine=self.engine,
                          topn=N, threshold=noise_level/4)

            _, actual = sort_positions(f[['y', 'x']].values, expected)
            rms_dev = np.sqrt(np.mean(np.sum((actual-expected)**2, 1)))

            real_rms_dev.append(rms_dev)
            eps.append(f['ep'].mean())

            # Additionally test the measured noise
            black_level, noise = measure_noise(image, image_noisy,
                                               locate_diameter // 2)
            actual_black_level.append(black_level)
            actual_noise.append(noise)

        assert_allclose(actual_black_level, 1/2 * noise_levels,
                        rtol=0.01, atol=1)
        assert_allclose(actual_noise, np.sqrt(1/12.) * noise_levels,
                        rtol=0.01, atol=1)
        assert_allclose(real_rms_dev, eps, rtol=0.2, atol=0.001)
        assert_array_less(real_rms_dev, eps)
开发者ID:caspervdw,项目名称:trackpy,代码行数:57,代码来源:test_feature.py

示例14: test_oldmass_16bit

    def test_oldmass_16bit(self):
        old_minmass = 2800000
        im = draw_spots(self.shape, self.pos, self.draw_diameter, bitdepth=16,
                        noise_level=10000)

        new_minmass = tp.minmass_version_change(im, old_minmass,
                                                smoothing_size=self.tp_diameter)
        f = tp.locate(im, self.tp_diameter, minmass=new_minmass)
        assert len(f) == self.N
开发者ID:hadim,项目名称:trackpy,代码行数:9,代码来源:test_feature.py

示例15: test_oldmass_invert

    def test_oldmass_invert(self):
        old_minmass = 2800000
        im = draw_spots(self.shape, self.pos, self.size, bitdepth=12,
                        noise_level=500)
        im = (im.max() - im + 10000)

        new_minmass = self.minmass_v02_to_v04(im, old_minmass, invert=True)

        f = tp.locate(invert_image(im), self.tp_diameter, minmass=new_minmass)
        assert len(f) == self.N
开发者ID:caspervdw,项目名称:trackpy,代码行数:10,代码来源:test_feature.py


注:本文中的trackpy.locate函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。