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

Python tifffile.imsave函数代码示例

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

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



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

示例1: recolor_volume

def recolor_volume(dir, outdir, database_file):

    conn = sqlite3.connect(database_file)
    cursor = conn.cursor()
    cursor.execute('SELECT * FROM relabelMap')
    result = cursor.fetchall()

    mergeTable = {}
    for r in result:
        mergeTable[r[0]] = r[1:]

    print 'loaded colortable.'
    # print mergeTable

    files = os.listdir(dir)

    for f in files:

        if (f.startswith('.')):
            continue

        i = tif.imread(os.path.join(dir,f))

        for oldid in mergeTable.keys():
            i[i==oldid] = mergeTable[oldid]

        tif.imsave(os.path.join(outdir,f), i)
开发者ID:3Scan,项目名称:dojo,代码行数:27,代码来源:crop_volume.py


示例2: relabel_volume

def relabel_volume(dir, outdir):


    files = sorted(os.listdir(dir))

    out = None
    out_is_there = False

    for f in files:

        i = tif.imread(os.path.join(dir,f))
        if (out_is_there):
            out = numpy.dstack([out, i])

        else:
            out = i
            out_is_there = True


    print '3d volume', out.shape

    import skimage
    from skimage.segmentation import relabel_sequential

    relabeled,fm,im = skimage.segmentation.relabel_sequential(out)

    print 'Max', relabeled.max()

    for z in range(relabeled.shape[2]):
        tif.imsave(os.path.join(outdir,str(z)+'.tif'),relabeled[:,:,z].astype(numpy.uint32))
        print 'stored', z
开发者ID:3Scan,项目名称:dojo,代码行数:31,代码来源:crop_volume.py


示例3: test_movie_of_cell

    def test_movie_of_cell(self):
        fake_mdf_1 = pd.DataFrame({
            "Object": [1],
            "X": [100],
            "Y": [100]
        })
        movie = movie_of_cell(
            fake_mdf_1,
            fixture("single_page.tif"),
            200, 200)
        self.assertIsInstance(movie, np.ndarray)
        self.assertEqual(movie.shape, (1, 200, 200))

        # test the pillow code path
        movie = movie_of_cell(
            fake_mdf_1,
            [fixture("single_page.tif")],
            200, 200)
        self.assertIsInstance(movie, np.ndarray)
        self.assertEqual(movie.shape, (1, 200, 200))

        fake_mdf_4 = pd.DataFrame({
            "Object": [1, 1, 1, 1],
            "X": [100, 120, 140, 160],
            "Y": [200, 180, 160, 140],
        })
        movie = movie_of_cell(
            fake_mdf_4,
            fixture("multi_page.tif"),
            200, 200)
        self.assertIsInstance(movie, np.ndarray)
        self.assertEqual(movie.shape, (4, 200, 200))
        if WRITE_OUTPUT:
            tf.imsave("test_movie_of_cell.tif", movie, photometric="minisblack")
开发者ID:tdsmith,项目名称:migrationscripts,代码行数:34,代码来源:test_extract_cell.py


示例4: main

def main(args):
    tiff_fileno = args.filenumber
    for arg in args.ge2:
        if not arg.endswith('.ge2'):
            if args.verbose:
                print('Skipping %s, file format not recognized.' % (arg))
                continue
        if args.dezing:
            raise NotImplementedError('dezinging has not been implemented')
            continue
        if args.summed:
            out = "%s.tif" % (arg.rsplit('.ge2', 1)[0])
            if os.path.exists(out):
                if args.verbose:
                    print('Skipping %s, %s already exists' % (arg,out))
                    continue
            if args.verbose:
                print('Converting %s to %s'% (arg, out), end='\n')
            tifffile.imsave(out, load_ge2(arg, summed=args.summed))
            if args.delete:
                os.remove(arg)
                if args.verbose:
                    print('Removed %s' % arg)
        else:
            stem = args.output if args.output else arg.rsplit('.ge2', 1)[0]
            for i, d in enumerate(AdeptFile(arg)):
                out = '%s_%05d.tif' % (stem, tiff_fileno)
                if args.verbose:
                    print("saving image %d from %s as %s" % (i+1, arg, out))
                tifffile.imsave(out, d)
                tiff_fileno += 1
开发者ID:ddale,项目名称:hedm-conda-recipes,代码行数:31,代码来源:ge2tiff.py


示例5: test_extract_window

 def test_extract_window(self):
     for i, (x, y) in enumerate(((0, 0), (100, 100), (250, 250))):
         window = extract_window(self.single_page, x, y, 200, 200)
         self.assertIsInstance(window, np.ndarray)
         self.assertEqual(window.shape, (200, 200))
         if WRITE_OUTPUT:
             tf.imsave("test_extract_window_%d.tif" % i, window)
开发者ID:tdsmith,项目名称:migrationscripts,代码行数:7,代码来源:test_extract_cell.py


示例6: saveTiffStack

def saveTiffStack(fname, data, useLibTiff = False):
    """Save data in file fname
    """
    if useLibTiff:
        raise NotImplementedError
    from tifffile import imsave
    imsave(str(fname), data.swapaxes(1,2))
开发者ID:raacampbell,项目名称:lasagna,代码行数:7,代码来源:imageStackLoader.py


示例7: initFindAndFit

def initFindAndFit(parameters):
    """
    Initialize and return a fitting.PeakFinderFitter object.
    """
    # Create pupil function object.
    [min_z, max_z] = parameters.getZRange()
    pupil_fn = pupilFn.PupilFunction(pf_filename = parameters.getAttr("pupil_function"),
                                     zmin = min_z * 1.0e+3,
                                     zmax = max_z * 1.0e+3)

    # PSF debugging.
    if False:
        tifffile.imsave("pupil_fn_psf.tif", pupil_fn.getPSF(0.1).astype(numpy.float32))

    # Check that the PF and camera pixel sizes agree.
    diff = abs(parameters.getAttr("pixel_size") - pupil_fn.getPixelSize()*1.0e3)
    assert (diff < 1.0e-6), "Incorrect pupil function?"
    
    # Create peak finder.
    finder = fitting.PeakFinderArbitraryPSF(parameters = parameters,
                                            psf_object = pupil_fn)

    # Create cubicFitC.CSplineFit object.
    mfitter = initFitter(finder, parameters, pupil_fn)
    
    # Create peak fitter.
    fitter = fitting.PeakFitterArbitraryPSF(mfitter = mfitter,
                                            parameters = parameters)
    
    # Specify which properties we want from the analysis.
    properties = ["background", "error", "height", "iterations", "significance", "sum", "x", "y", "z"]

    return fitting.PeakFinderFitter(peak_finder = finder,
                                    peak_fitter = fitter,
                                    properties = properties)
开发者ID:ZhuangLab,项目名称:storm-analysis,代码行数:35,代码来源:find_peaks_std.py


示例8: start

    def start(self):

        self.main.recWidget.writable = False
        self.main.tree.writable = False
        self.main.liveviewButton.setEnabled(False)

        path = self.main.recWidget.folderEdit.text()
        name = '3Dcalibration_step{}'.format(self.step)
        savename = guitools.getUniqueName(os.path.join(path, name) + '.tiff')

        steps = (self.rangeUm // self.step).magnitude
        self.main.focusWidget.zMove(-0.5*steps*self.step)
        self.main.focusWidget.zMove(self.step)
        time.sleep(0.1)

        stack = np.zeros((int(steps), self.main.shape[0], self.main.shape[1]),
                         dtype=np.uint16)

        for s in np.arange(steps, dtype=int):
            self.main.focusWidget.zMove(self.step)
            time.sleep(0.1)     # Waiting for the motor to get to new position
            image = self.main.img.image.astype(np.uint16)
            stack[s] = image

        tiff.imsave(savename, stack, software='Tormenta',
                    photometric='minisblack',
                    resolution=(1/self.main.umxpx, 1/self.main.umxpx),
                    extratags=[('resolution_unit', 'H', 1, 3, True)])

        self.main.focusWidget.zMove(-0.5*steps*self.step)

        self.main.recWidget.writable = True
        self.main.tree.writable = True
        self.main.liveviewButton.setEnabled(True)
        self.sigDone.emit()
开发者ID:fedebarabas,项目名称:tormenta,代码行数:35,代码来源:pyqtsubclasses.py


示例9: HSVizualizer

def HSVizualizer(inputDirectory, filenames, outputDirectory):
    """

    Args:
        inputDirectory: (str)
        filenames: (list) filenames to analyze and draw
        outputDirectory: (str) Where to place output

    Returns:

    """
    for filename in filenames:

        raw = tiff.imread(inputDirectory+filename)
        nframes, frame_width, frame_height = raw.shape
        #outstack is in RGB color so we need an extra 3 dimensions
        outStack = np.zeros((nframes-1, frame_width, frame_height, 3), dtype='uint8')

        for i in xrange(nframes-1):
            t1 = time.time()
            print "Start frame "+str(i)+"..."+filename
            frame = raw[i]
            next_frame = raw[i+1]
            flow = cv2.calcOpticalFlowFarneback(frame, next_frame, None, 0.5, 3, 8, 4, 7, 1.5, 0)
            outStack[i] = draw_hsv(flow)

            print "Finish frame "+str(i)+" in "+str(time.time()-t1)+" s."

        #print outStack.shape
        tiff.imsave(outputDirectory+filename+'_HSV.tif', outStack)

    print "All done in "+str(time.time()-t0)+" s"
开发者ID:Oftatkofta,项目名称:Vector_visualizer,代码行数:32,代码来源:opflowtester.py


示例10: write_tiff

def write_tiff(data, fname='tmp/data', digit=None, ext='tiff'):
    """
    Write image data to a tiff file.

    Overwrite existing data and infer data-type from the data.

    Parameters
    ----------
    data : ndarray
        Array data to be saved.
    fname : str
        File name to which the data is saved. ``.tiff`` extension
        will be appended if it doesn't already have one.
    digit : int
        Append this number to fname using a folder e.g. {fname}/{digit}.{ext}
    """
    # Add the extension and digit.
    if digit is not None:
        fname = os.path.join(fname, str(digit))
    if not str(fname).endswith(ext):
        fname = ".".join([fname, ext])
    # Convert to absolute path.
    fname = os.path.abspath(fname)
    # Create the directory if it doesn't exist.
    dname = os.path.dirname(os.path.abspath(fname))
    if not os.path.exists(dname):
        os.makedirs(dname)
    # Save the file.
    tifffile.imsave(fname, data)
开发者ID:decarlof,项目名称:tomopy,代码行数:29,代码来源:misc.py


示例11: shift_stack_onfile

def shift_stack_onfile(fpath, shift_coord, new_path = None, partial = False, srange = (0, 500), sub = False):
    '''
    Open a stack, take the shifted coordinates and correct the stack on file.
    '''
    if partial:
        print("Only save part of the stack.")
        with tf.TiffFile(fpath) as tif:
            raw_img = tif.asarray()[srange[0]:srange[1]]
            shift_coord = shift_coord[srange[0]:srange[1]]
            tif.close()
    else:
        print("save the whole stack.")
        with tf.TiffFile(fpath) as tif:
            raw_img = tif.asarray()

    n_slice, ny, nx = raw_img.shape
    # subpixel correction interpolation needed
    for ii in range(n_slice):
        frame = raw_img[ii]
        raw_img[ii] = interpolation.shift(frame, shift = shift_coord[ii], order = 0)
        if (ii%100 == 0):
            print("Finished ", ii, "slices.")

    if new_path is None:
        tf.imsave(fpath, raw_img.astype('uint16'))
    else:
        tf.imsave(new_path, raw_img.astype('uint16'))
开发者ID:danustc,项目名称:Image_toolbox,代码行数:27,代码来源:drift_correction.py


示例12: tiffSave

def tiffSave(parent,array,path,cellname,cellNumber):
    array=np.swapaxes(array,0,1)
    numints=len(str(array.shape[2]))
    fullname=path+cellname
    w=0
    while w!=array.shape[2]:
        currentslice="Exporting cell " + str(cellNumber) + " of " + str(int(np.sum(parent.verifiedcells))) + ": Exporting image " + str(w+1) + " of " + str(array.shape[2])
       	parent.progress.set(currentslice)
        parent.frames[ExtractGUI2].update_idletasks()
        intdiff=numints-len(str(w))
        ints=0
        intstr=""
        while ints!=intdiff:
            intstr=intstr+"0"
            ints += 1
        intstr=intstr+str(w)
        tempfilename=fullname+"_slice"+intstr+".tiff"
        tempfile=array[:,:,w].astype("uint8")
        tifffile.imsave(tempfilename,tempfile)
        w += 1

    currentslice="Exporting cell " + str(cellNumber) + " of " + str(int(np.sum(parent.verifiedcells))) + ": Stacking TIFFs"
    parent.progress.set(currentslice)
    parent.frames[ExtractGUI2].update_idletasks()

    mptiffstring="convert " + path + "*.tiff " + fullname +"_EM.tiff"
    subprocess.call(mptiffstring,shell=True)

    currentslice="Exporting cell " + str(cellNumber) + " of " + str(int(np.sum(parent.verifiedcells))) + ": Cleaning up TIFFs"
    parent.progress.set(currentslice)
    parent.frames[ExtractGUI2].update_idletasks()

    tempfiles=glob.glob(fullname+"_slice*.tiff")
    for f in tempfiles:
        os.remove(f)
开发者ID:SpirouLab,项目名称:CellSeeker,代码行数:35,代码来源:cellseeker.py


示例13: mip

	def mip():
		files = tkFileDialog.askopenfilenames(parent=root,title='Choose image(stack) files')
		if not files: return
		for filename in files:
			if filename.endswith('.tif'):
				print "Creating normalized Maximum Intensity Projection (MIP):", filename
				img = tf.imread(filename)
				fpath,fname = os.path.split(filename)
				fname_norm = os.path.join(fpath,"MIP_"+fname)
				if len(img.shape) == 4:
					img_MIP = np.zeros((img.shape[0],img.shape[2],img.shape[3]), dtype=img.dtype)
					for i in range(0,img.shape[0]):
						for ii in range(0,img.shape[2]):
							for iii in range(0,img.shape[3]):
								img_MIP[i,ii,iii] = img[i,:,ii,iii].max()
					img_MIP = norm_img(img_MIP)
					tf.imsave(fname_norm, img_MIP, imagej=True)
				elif len(img.shape) == 3:
					img_MIP = np.zeros((img.shape[1],img.shape[2]), dtype=img.dtype)
					for i in range(0,img.shape[1]):
						for ii in range(0,img.shape[2]):
							img_MIP[i,ii] = img[:,i,ii].max()
					img_MIP = norm_img(img_MIP)
					tf.imsave(fname_norm, img_MIP)
				else: print "I'm sorry, I don't know this image shape: {0}".format(img.shape)
				print "		...done"
		print "Maximum Intensity Projection finished."
		print "="*40
开发者ID:Splo0sh,项目名称:3DCT,代码行数:28,代码来源:stackProcessing.py


示例14: writeData

def writeData(filename, data):
    """Write image data to tif file
    
    Arguments:
        filename (str): file name 
        data (array): image data
    
    Returns:
        str: tif file name
    """
    
    d = len(data.shape);
    
    if d == 2:
        #tiff.imsave(filename, data);
        tiff.imsave(filename, data.transpose([1,0]));
    elif d == 3:   
        #tiff.imsave(filename, data.transpose([2,0,1]));
        tiff.imsave(filename, data.transpose([2,1,0]));
    elif d == 4:
        #tiffile (z,y,x,c)
        t = tiff.TiffWriter(filename, bigtiff = True);
        #t.save(data.transpose([2,0,1,3]), photometric = 'minisblack',  planarconfig = 'contig');
        t.save(data.transpose([2,1,0,3]), photometric = 'minisblack',  planarconfig = 'contig')
        t.close();    
    else:
        raise RuntimeError('writing multiple channel data to tif not supported');
    
    return filename;
开发者ID:jennan,项目名称:ClearMap,代码行数:29,代码来源:TIF.py


示例15: main

def main():
    fpath = '2018-11-14/TL150_tune_0001.dax'
    DM = DaxReader(global_datapath + fpath)
    print(DM.image_height)
    print(DM.image_width)
    print(DM.number_frames)
    stack = []
    for cc in range(DM.number_frames):
        frame = DM.loadAFrame(cc)
        stack.append(frame.astype('float64'))

    stack = np.array(stack)
    zz, dom_z = psfstack_survey(stack)
    tf.imsave('imstack.tif', stack.astype('uint16'))
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.imshow(stack[dom_z])
    psf_collection, centers = psf_finder(stack, dom_z)
    ax.scatter(centers[:,1], centers[:,0], s = 150, facecolors = 'none',edgecolors = 'yellow', linewidth = 2 )
    ax.axis('off')
    plt.tight_layout()
    fig.savefig('PSF_extract')
    print("# of psfs:",len(psf_collection))
    ii = 0
    for psf in psf_collection:
        print(centers[ii])
        ax.imshow(psf[:, 23, :], cmap = 'Greys_r', extent = [-0.088*24, 0.088*24, -3, 3])
        ax.axis('off')
        fig.savefig('psf_xz'+str(ii)+'tune1')
        ii+=1
开发者ID:danustc,项目名称:Image_toolbox,代码行数:30,代码来源:Acadia_test.py


示例16: visualize_image_for_hand_labelling

def visualize_image_for_hand_labelling(file_id):
    """Saves out a visualization of the image ``file_id`` that's appropriate for hand-labelling"""
    im = get_bounded_im(file_id)
    im = two_channel_to_color(im)
    
    target_path = os.path.join(LABELS_FOLDER, '{}_corrected.bmp'.format(file_id))
    tifffile.imsave(target_path, im)
开发者ID:andyljones,项目名称:NeuralNetworkMicroarraySegmentation,代码行数:7,代码来源:experimental_training.py


示例17: saveImg

def saveImg(img,fn,enc="uint16",scale=True,maxVal=None):
	
	"""Saves image as tif file.
	
	``scale`` triggers the image to be scaled to either the maximum
	range of encoding or ``maxVal``. See also :py:func:`scaleToEnc`.
	
	Args:
		img (numpy.ndarray): Image to save.
		fn (str): Filename.
		
	Keyword Args:	
		enc (str): Encoding of image.
		scale (bool): Scale image.
		maxVal (int): Maximum value to which image is scaled.
	
	Returns:
		str: Filename.
	
	"""
	
	#Fill nan pixels with 0
	img=np.nan_to_num(img)
	
	#Scale img
	if scale:
		img=scaleToEnc(img,enc,maxVal=maxVal)
	tifffile.imsave(fn,img)
	
	return fn
开发者ID:alexblaessle,项目名称:QuantDorsal,代码行数:30,代码来源:im_module.py


示例18: theoreticalOTF

    def theoreticalOTF(self):
        """
        Returns a theoretical OTF.

        OTF = 2 * (psi - cos(psi)sin(psi)) / pi
        psi = inv_cos(lambda * wavelength / 2 * NA)

        Reference:
        https://www.microscopyu.com/microscopy-basics/modulation-transfer-function

        I'm assuming that the formula in this reference is for the FT of the PSF and 
        not the FT of the square root of the PSF.
        """
        tmp = (1.5 * self.wavelength * self.k / (2.0 * self.NA))
        tmp[(tmp > 1.0)] = 1.0
        tmp[(tmp < -1.0)] = -1.0
        
        psi = numpy.arccos(tmp)
        otf = 2.0 * (psi - numpy.cos(psi)*numpy.sin(psi)) / numpy.pi

        otf = otf/numpy.sum(otf)

        if False:
            tifffile.imsave("otf.tif", otf.astype(numpy.float32))
        
        return otf
开发者ID:ZhuangLab,项目名称:storm-analysis,代码行数:26,代码来源:pupil_math.py


示例19: remove_dark

def remove_dark(A, folder):
    """
    This function will subtract the dark files from the data files
    Parameters
    ----------
    A : list
        list of tiff files
        
    Returns
    -------
    clean_data : array
        dark subtracted data , clean data
        shape (number of clean images, detectore shape 0, detecotor shape 1)
    """
    
    clean_data_arr = []  # save the cleaned data
    for name in A:
        if "dark" in name:   # check the dark files
            dark_data = imread(name)  
            print ("+++++ bad", name)
        else:
            arr = imread(name)
            print ("good", name)
            #  clean the data
            clean_data = arr - dark_data 
            #print (os.path.join(name))
            imsave(name, clean_data)
            clean_data_arr.append(clean_data)
    return np.asarray(clean_data_arr)
开发者ID:sameera2004,项目名称:test_codes,代码行数:29,代码来源:Remove_dark_new.py


示例20: roundtrip

 def roundtrip(self, dtype, x):
     f = NamedTemporaryFile(suffix='.tif')
     fname = f.name
     f.close()
     imsave(fname, x)
     y = imread(fname)
     assert_array_equal(x, y)
开发者ID:alimuldal,项目名称:tifffile,代码行数:7,代码来源:test_tifffile.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python parser.from_file函数代码示例发布时间:2022-05-27
下一篇:
Python tifffile.imread函数代码示例发布时间: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