• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python trackpy.locate函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_oldmass_invert

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

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


示例17: test_smoke_datatypes

    def test_smoke_datatypes(self):
        self.check_skip()
        SHAPE = (300, 300)
        # simple "smoke" test to see if numba explodes
        dummy_image = np.random.randint(0, 100, SHAPE).astype(np.uint8)
        tp.locate(dummy_image, 5, engine=self.engine)
        tp.locate(dummy_image, 5, invert=True, engine=self.engine)

        # Check float types
        dummy_image = np.random.rand(*SHAPE)
        tp.locate(dummy_image, 5, engine=self.engine)
        tp.locate(dummy_image, 5, invert=True, engine=self.engine)
开发者ID:neilpanchal,项目名称:trackpy,代码行数:12,代码来源:test_feature.py


示例18: test_oldmass_float

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

        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,代码行数:10,代码来源:test_feature.py


示例19: test_mass

    def test_mass(self):
        # The mass calculated from the processed image should be independent
        # of added noise. Its absolute value is untested.

        # The mass calculated from the raw image should equal
        # noiseless mass + noise_size/2 * Npx_in_mask.
        self.check_skip()
        ndim = 2
        size = 3    # for drawing
        radius = 6  # for locate
        diameter = radius * 2 + 1
        N = 20
        shape = (128, 127)

        # Calculate the expected mass from a single spot using the set masksize
        center = (diameter,) * ndim
        spot = draw_spots((diameter*2,) * ndim, [center], size, bitdepth=12)
        rect = [slice(c - radius, c + radius + 1) for c in center]
        mask = tp.masks.binary_mask(radius, 2)
        Npx = mask.sum()
        EXPECTED_MASS = (spot[rect] * mask).sum()

        # Generate feature locations and make the image
        expected = gen_nonoverlapping_locations(shape, N, diameter, diameter)
        expected = expected + np.random.random(expected.shape)
        N = expected.shape[0]
        image = draw_spots(shape, expected, size, bitdepth=12)

        # analyze the image without noise
        f = tp.locate(image, diameter, engine=self.engine, topn=N)
        PROCESSED_MASS = f['mass'].mean()
        assert_allclose(f['raw_mass'].mean(), EXPECTED_MASS, rtol=0.01)

        for n, noise in enumerate(np.arange(0.05, 0.8, 0.05)):
            noise_level = int((2**12 - 1) * noise)
            image_noisy = image + np.array(np.random.randint(0, noise_level,
                                                             image.shape),
                                           dtype=image.dtype)
            f = tp.locate(image_noisy, radius*2+1, engine=self.engine, topn=N)
            assert_allclose(f['mass'].mean(), PROCESSED_MASS, rtol=0.1)
            assert_allclose(f['raw_mass'].mean(),
                            EXPECTED_MASS + Npx*noise_level/2, rtol=0.1)
开发者ID:caspervdw,项目名称:trackpy,代码行数:42,代码来源:test_feature.py


示例20: upload

def upload():
	#clear the DOWNLOAD directory
	for root, dirs, files in os.walk(app.config['DOWNLOAD_FOLDER']):
	    for f in files:
	    	os.unlink(os.path.join(root, f))
	    for d in dirs:
	    	shutil.rmtree(os.path.join(root, d))
	#clear the UPLOAD directory
	for root, dirs, files in os.walk(app.config['UPLOAD_FOLDER']):
	    for f in files:
	    	os.unlink(os.path.join(root, f))
	    for d in dirs:
	    	shutil.rmtree(os.path.join(root, d))

	# Get specifications
	uploaded_files = request.files.getlist("file[]")
	_invert = request.form['invert']
	_diameter = int(request.form['diameter'])
	_min_mass = float(request.form['minmass'])
	_noise_size = float(request.form['noise_size'])
	_smoothing_size = float(request.form['smoothing_size'])
	_separation = float(request.form['separation'])
	#list of files for use on upload.html
	filenames = []

	for file in uploaded_files:
		# Check if the file is one of the allowed types/extensions
		if file and allowed_file(file.filename):
			# Make the filename safe, remove unsupported chars
			filename = secure_filename(file.filename)
			#Save file to upload folder
			file.save(os.path.join(app.config['DOWNLOAD_FOLDER'], filename))
			#load the image frames
			frames = pims.ImageSequence(os.path.join(app.config['DOWNLOAD_FOLDER'], filename), as_grey=True)
			#for loop of 1 to deal with PIMS bug.
			for frame in frames: 
				#locate features
				f = tp.locate(frames, _diameter, minmass=_min_mass, separation=_separation, invert=_invert) #noise_size=_noise_size, smoothing_size=_smoothing_size, 
				plt.ioff() #interactive mode = off
				plt.figure(filename) # make a new figure
				plt.title(filename)
				plt.xlabel('Number of cells: ' + str(len(f))) #label axis
				tp.annotate(f, frame) #display the iamge and the circle overlay
				
				#filename_png_extension = os.path.splitext(filename)[0] + ".png"

				plt.savefig(os.path.join(app.config['UPLOAD_FOLDER'], filename), format='png')   # save the figure to filenames
				plt.close() #close figure
					
				# Save the filename into a list, we'll use it later
				filenames.append(filename)
	print(filenames, file=sys.stderr)
	# Load an html page with a link to each uploaded file
	return render_template('upload.html', filenames=filenames)
开发者ID:julianparismorgan,项目名称:flask_cellcounter,代码行数:54,代码来源:cell-app.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python artificial.draw_feature函数代码示例发布时间:2022-05-27
下一篇:
Python utils.show函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap