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

Python tifffile.imread函数代码示例

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

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



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

示例1: 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


示例2: __init__

 def __init__(self, file_path):
     self.file_path = file_path
     if isinstance(file_path, str):
         self.data = tifffile.imread(self.file_path)
     elif any([isinstance(file_path, t) for t in [np.ndarray,list]]):
         data = [tifffile.imread(f) for f in self.file_path if 'tif' in f]
         self.data = np.concatenate([d if d.ndim==3 else [d] for d in data], axis=0)
开发者ID:bensondaled,项目名称:pyfluo,代码行数:7,代码来源:tiff.py


示例3: get_new_images

 def get_new_images(self, temp_file_list):
     new_pics = []
     if temp_file_list is not None:
         for i in temp_file_list:
             self.pic_list.append(imread(self._directory_name + i))
             new_pics.append(imread(self._directory_name + i))
     return temp_file_list, new_pics
开发者ID:JKThanassi,项目名称:2016_summer_XPD,代码行数:7,代码来源:Tif_File_Finder.py


示例4: imreadStack

def imreadStack(filenameList):
    """Simple wrapper to read a list of image series tiffs into a stack.

    Note that this function assumes all images are the same size.

    We tend to work with single channel tiff files, and as such use tifffile's imread function.
    We've wrapped tifffiles read function to account for the differences in default
    image dimension ordering.  By convention, we use x,y,frame.  The major advantages of
    tifffile are 1) speed and 2) the ability to read multiframe tiffs.

    :param filenameList: list of strings representing the files to load
    :returns:  4d numpy array
    """

    firstImageSeries = tifffile.imread(filenameList[0])
    if len(firstImageSeries.shape) == 3:
	firstImageSeries=np.transpose(firstImageSeries, [1,2,0])

    imageStack = np.zeros((firstImageSeries.shape[0], firstImageSeries.shape[1], firstImageSeries.shape[2], len(filenameList)))

    for i, fileName in enumerate(filenameList):
	array=tifffile.imread(fileName)
	if len(array.shape) == 3:
	    array=np.transpose(array, [1,2,0])
        imageStack[:,:,:,i] = array
    return imageStack
开发者ID:peltonen,项目名称:dattacode,代码行数:26,代码来源:imageIORoutines.py


示例5: get_images

def get_images(imageId, img_key = None):
    '''
    Load images correspoding to imageId

    Parameters
    ----------
    imageId : str
        imageId as used in grid_size.csv
    img_key : {None, '3', 'A', 'M', 'P'}, optional
        Specify this to load single image
        None loads all images and returns in a dict
        '3' loads image from three_band/
        'A' loads '_A' image from sixteen_band/
        'M' loads '_M' image from sixteen_band/
        'P' loads '_P' image from sixteen_band/

    Returns
    -------
    images : dict
        A dict of image data from TIFF files as numpy array
    '''
    img_names = get_image_names(imageId)
    images = dict()
    if img_key is None:
        for k in img_names.keys():
            images[k] = tiff.imread(img_names[k])
    else:
        images[img_key] = tiff.imread(img_names[img_key])
    return images
开发者ID:ashleysmart,项目名称:kraggle_share,代码行数:29,代码来源:visualizer.py


示例6: main

def main(vol_fname='', label_fname='', dataset_name='', percent_test=0,
	normalize_mean=False):

	print "Reading data..."
	vol = tifffile.imread(vol_fname)
	label = tifffile.imread(label_fname)

	if zero_mean:
		vol = zero_mean(vol)

	if len(label.shape) > 3 and label.shape[3] == 3:
		print "Converting label to binary..."
		label = rgb2bin(label)

	#Splitting into training and test sets
	train, label_train, test, label_test = split_data(vol, label, percent_test)

	#Transpose
	train = train.transpose(0,2,1)
	test = test.transpose(0,2,1)

	label_train = label_train.transpose(0,2,1)
	label_test = label_test.transpose(0,2,1)

	s_train = train.shape
	s_test = test.shape

	print "Saving data in znn format..."
	#Making the necessary directories
	os.makedirs('dataset/{}/data/'.format(dataset_name))
	os.makedirs('dataset/{}/spec/'.format(dataset_name))
		
	#Save as znn format
	train_outname = "dataset/{0}/data/batch{1}.image".format(dataset_name, 1)
	label_train_outname = "dataset/{0}/data/batch{1}.label".format(dataset_name, 1)

	if percent_test > 0:

		test_outname = "dataset/{0}/data/batch{1}.image".format(dataset_name, 2)
		label_test_outname = "dataset/{0}/data/batch{1}.label".format(dataset_name, 2)

	emirt.io.znn_img_save(train.astype('double'), train_outname)
	emirt.io.znn_img_save(label_train.astype('double'), label_train_outname)

	if percent_test > 0:

		emirt.io.znn_img_save(test.astype('double'), test_outname)
		emirt.io.znn_img_save(label_test.astype('double'), label_test_outname)

	#Prepare a spec file
	print "Writing spec file..."
	write_spec_file(dataset_name, 1, s_train)

	if percent_test > 0:

		write_spec_file(dataset_name, 2, s_test)
开发者ID:nicholasturner1,项目名称:pynn,代码行数:56,代码来源:import_tif_file.py


示例7: readData

def readData(filename, x = all, y = all, z = all, **args):
    """Read data from a single tif image or stack
    
    Arguments:
        filename (str): file name as regular expression
        x,y,z (tuple): data range specifications
    
    Returns:
        array: image data
    """
    
    dsize = dataSize(filename);
    #print "dsize %s" % str(dsize);    
    
    if len(dsize) == 2:
        data = tiff.imread(filename, key = 0);
        #print "data.shape %s" % str(data.shape);        
        
        return io.dataToRange(data.transpose([1,0]), x = x, y = y);
        #return io.dataToRange(data, x = x, y = y);
        
    else:
        if z is all:
            data = tiff.imread(filename);
            if data.ndim == 2:
                # data = data
                data = data.transpose([1,0]);
            elif data.ndim == 3:
                #data = data.transpose([1,2,0]);
                data = data.transpose([2,1,0]);
            elif data.ndim == 4: # multi channel image
                #data = data.transpose([1,2,0,3]);
                data = data.transpose([2,1,0,3]);
            else:
                raise RuntimeError('readData: dimension %d not supproted!' % data.ndim)
            
            return io.dataToRange(data, x = x, y = y, z = all);
        
        else: #optimize for z ranges
            ds = io.dataSizeFromDataRange(dsize, x = x, y = y, z = z);
            t = tiff.TiffFile(filename);
            p = t.pages[0];
            data = numpy.zeros(ds, dtype = p.dtype);
            rz = io.toDataRange(dsize[2], r = z);
            
            #print "test"
            #print rz;
            #print dsize            
            
            for i in range(rz[0], rz[1]):
                xydata = t.pages[i].asarray();
                #data[:,:,i-rz[0]] = io.dataToRange(xydata, x = x, y = y);
                data[:,:,i-rz[0]] = io.dataToRange(xydata.transpose([1,0]), x = x, y = y);
            
            return data
开发者ID:jennan,项目名称:ClearMap,代码行数:55,代码来源:TIF.py


示例8: __init__

  def __init__(self,infile,rawfile,verbosity=1):
    self.verbosity = verbosity;

    # read images
    self.IN   =tiff.imread(infile,verbosity=self.verbosity);
    self.INRAW=tiff.imread(rawfile,verbosity=self.verbosity);
  
    # image parameters (TODO: read scale from Tiff?)
    self.info = { 'desc':     infile.split('/')[-1],
                  'filename': infile,
                  'atoms'   : 'C' };
开发者ID:rhambach,项目名称:TEMimage,代码行数:11,代码来源:gui_interaction.py


示例9: baboon

def baboon(size=512, dtype='float32'):
    """
    Load test baboon image array.

    Parameters
    ----------
    size : int or tuple of int, optional
        Size of the output image.
    dtype : str, optional
        The desired data-type for the array.

    Returns
    -------
    ndarray
        Output 3D test image.
    """
    size = _totuple(size, 2)
    fname = os.path.join(DATA_PATH, 'baboon.tif')
    im = tifffile.imread(fname)
    im = skimage.transform.resize(im, size, order=3,
                                  preserve_range=True, mode='constant',
                                  **resize_kwargs)
    im = np.expand_dims(im, 0)
    im = im.astype(dtype)
    return im
开发者ID:carterbox,项目名称:tomopy,代码行数:25,代码来源:phantom.py


示例10: singletiff2multidicom

def singletiff2multidicom(in_files, dicomdir, plans, out_prefix):
    import DicomIO
    import numpy as np
    import os
    import shutil
    import warnings
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        import tifffile as tiff
    outdir = experiment_dir + '/' + out_prefix + '/' + dicomdir
    if not os.path.exists(outdir):
        os.makedirs(outdir)
    else:
        shutil.rmtree(outdir)
        os.makedirs(outdir)

    # Resolve new frame list
    out_vols = plans
    for file_i in range(len(in_files)):
        print "Reading " + in_files[file_i]
        ds = tiff.imread(in_files[file_i])
        no_slices = ds.shape[0]
        for z_i in range(no_slices):
            out_vols[file_i][z_i].PixelData = ds[z_i].astype(np.uint16).tostring()

    dcmio = DicomIO.DicomIO()
    filenames = dcmio.WriteDICOM_frames(outdir, out_vols, 'IM')

    return outdir, filenames
开发者ID:haanme,项目名称:DWIProstateMotionCorrection,代码行数:29,代码来源:coreg_T2andROI_to_DWI.py


示例11: optimize_z

def optimize_z(x,y,z,image,n=None):
	"""Optimize z for poly fit"""
	if type(image) == str:
		img = tf.imread(image)
	elif type(image) == np.ndarray:
		img = image

	data_z = img[:,y,x]

	if n is None:
		n = getn(data_z)

	x_opt_vals, y_opt_vals, z_opt_vals = [], [], []

	x_opt,y_opt,z_opt = x,y,z
	for i in range(5):
		try:
			print x_opt,y_opt,z_opt
			x_opt,y_opt,z_opt = int(round(x_opt)),int(round(y_opt)),int(round(z_opt))
			x_opt, y_opt = optimize_xy(x_opt,y_opt,z_opt,img,nx=None,ny=None)
			data_z = img[:,round(y_opt),round(x_opt)]
		except Exception as e:
			if clrmsg and debug is True: print clrmsg.ERROR
			print IndexError("Optimization failed, possibly due to low signal or low SNR. "+str(e))
			return [x],[y],['failed']
		n = getn(data_z)
		z_opt, data_z_yp_poly = parabolic.parabolic_polyfit(data_z, np.argmax(data_z), n)
		x_opt_vals.append(x_opt)
		y_opt_vals.append(y_opt)
		z_opt_vals.append(z_opt)

	return x_opt_vals, y_opt_vals, z_opt_vals
开发者ID:Splo0sh,项目名称:3DCT,代码行数:32,代码来源:beadPos.py


示例12: 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


示例13: find

def find(args):
    from sys import stdout
    from tifffile import imread

    image = imread(str(args.image)).astype('float32')

    scale = asarray(args.scale) if args.scale else ones(image.ndim, dtype='int')
    blobs = findBlobs(image, range(*args.size), args.threshold)[:, 1:] # Remove scale
    blobs = blobs[peakEnclosed(blobs, shape=image.shape, size=args.edge)]
    blobs = blobs[:, ::-1] # Reverse to xyz order
    blobs = blobs * scale

    if args.format == "pickle":
        from pickle import dump, HIGHEST_PROTOCOL
        from functools import partial
        dump = partial(dump, protocol=HIGHEST_PROTOCOL)

        dump(blobs, stdout.buffer)
    else:
        import csv

        if args.format == 'txt':
            delimiter = ' '
        elif args.format == 'csv':
            delimiter = ','
        writer = csv.writer(stdout, delimiter=delimiter)
        for blob in blobs:
            writer.writerow(blob)
开发者ID:TheLaueLab,项目名称:blob,代码行数:28,代码来源:blob.py


示例14: loadTiffStack

def loadTiffStack(fname,useLibTiff=False):
  """
  Read a TIFF stack.
  We're using tifflib by default as, right now, only this works when the application is compile on Windows. [17/08/15]
  Bugs: known to fail with tiffs produced by Icy [23/07/15]

  """
  if not os.path.exists(fname):
    print "imageStackLoader.loadTiffStack can not find %s" % fname
    return

  purePython = True
  if useLibTiff:
    from libtiff import TIFFfile
    import numpy as np
    tiff = TIFFfile(fname)
    samples, sample_names = tiff.get_samples() #we should have just one
    print "Loading:\n" + tiff.get_info() + " with libtiff\n"
    im = np.asarray(samples[0])
  else:
    print "Loading:\n" + fname + " with tifffile\n"
    from tifffile import imread 
    im = imread(fname)

  im=im.swapaxes(1,2) 
  print "read image of size: cols: %d, rows: %d, layers: %d" % (im.shape[1],im.shape[2],im.shape[0])
  return im
开发者ID:raacampbell,项目名称:lasagna,代码行数:27,代码来源:imageStackLoader.py


示例15: imread

 def imread(_path):
     """ allow loading jpg, png as well as tif
     """
     if os.path.splitext(_path)[1] in ['.tiff', '.tif']:
         return tiff.imread(_path)
     else:
         return cv2.imread(_path,0)
开发者ID:Rhoana,项目名称:butterfly,代码行数:7,代码来源:Mojo.py


示例16: read_clip_write

def read_clip_write(directory, file_name, all_out_files, out_directory, desired_width, desired_height):
    try:
        prefix, extension = file_name.split('.')
        run_string, site_key = prefix.split("_")
        if site_key + ".npy" in all_out_files: return
        imarray = tf.imread(directory + "\\" + file_name)
        if(any(np.isnan(np.ravel(imarray)))):
            print("NA VALUES")
            return
        width = imarray.shape[0]
        height = imarray.shape[1]
        if(width != desired_width):
            excess = width - desired_width
            if excess < 0:
                print("TOO SMALL")
                return
            offset = excess / 2
            if 2 * offset == excess:
                left_offset, right_offset = offset, width-offset
            else:
                left_offset, right_offset = offset+1, width-offset
        if(height != desired_height): 
            excess = height - desired_height
            if excess < 0:
                print("TOO SMALL")
                return
            offset = excess / 2
            if 2 * offset == excess:
                bottom_offset, top_offset = offset, height - offset
            else:
                bottom_offset, top_offset = offset+1, height - offset
        out_array = imarray[left_offset:right_offset, bottom_offset:top_offset, :]
        np.save(out_directory + "\\" + site_key + ".npy", out_array)
    except:
        print("Error")
开发者ID:pdgwelle,项目名称:salinity,代码行数:35,代码来源:general.py


示例17: x_and_y_vals

    def x_and_y_vals(self, lock, queue, file_list):

        #x = range(0,len(self.file_list))
        y = []
        label = ""
        func = None

        if self.selection == "sigma":
            func= self.get_stdev
            self.label = "standard deviation"
        elif self.selection == "mean":
            func = self.get_avg_2d
            self.label = "mean"
        elif self.selection == "min":
            func = self.get_min
            self.label = "min"
        elif self.selection == "max":
            func = self.get_max
            self.label = "max"
        elif  self.selection == "total intensity":
            func = self.get_total_intensity
            self.label = "total intensity"

        list_num = file_list.pop(0)
        y.append(list_num)
        for img in file_list:

            lock.acquire()
            print(img)
            lock.release()
            temp_arr = imread(img)

            y.append(func(temp_arr))

        queue.put(y)
开发者ID:JKThanassi,项目名称:2016_summer_XPD,代码行数:35,代码来源:analysis_concurrent.py


示例18: 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


示例19: mapConvert

def mapConvert(slide):
    code.interact(local=locals())
    slide = tifffile.imread(slide)
    xx, yy = slide.shape
    newSlide = np.zeros((xx, yy, 3))
    u = []
    for r in xrange(slide.shape[0]):
        for c in xrange(slide.shape[1]):
            if slide[r,c] not in u:
                u.append(slide[r,c])

    number_of_colors = len(u)


    #subprocess.Popen(['./glasbey.py', str(number_QtCoreof_colors), 'colors.txt'])

    with open('colors.txt') as f:
        colors = f.readlines()

    colors = [[int(x) for x in c[:-1].split(',')] for c in colors]

    map_16_to_8 = dict([(x,y) for x,y in zip(u, colors)])

    for c in map_16_to_8.keys():
        for point in zip(np.where(slide==c)[0],np.where(slide==c)[1]):
            newSlide[point] = map_16_to_8[c]

    code.interact(local=locals())

    return newSlide
开发者ID:mmorehea,项目名称:annie,代码行数:30,代码来源:annie.py


示例20: makeDisplayFile

def makeDisplayFile(path):
    img = tifffile.imread(path)

    xx, yy = img.shape
    newImg = np.zeros((xx, yy, 3))
    u = []
    for r in xrange(img.shape[0]):
        for c in xrange(img.shape[1]):
            if img[r,c] not in u:
                u.append(img[r,c])

    number_of_colors = len(u)

    with open('colors.txt') as f:
        colors = f.readlines()

    colors = [[int(x) for x in c[:-1].split(',')] for c in colors]

    map_16_to_8 = dict([(x,y) for x,y in zip(u, colors)])
    map_16_to_8[0] = [0, 0, 0]

    for c in map_16_to_8.keys():
        for point in zip(np.where(img==c)[0],np.where(img==c)[1]):
            newImg[point] = map_16_to_8[c]

    if not os.path.exists('display'):
        os.mkdir('display')

    newPath = 'display/' + path[path.index('/') + 1:]

    cv2.imwrite(newPath, newImg)
    print 'Writing ' + newPath

    return newPath
开发者ID:mmorehea,项目名称:annie,代码行数:34,代码来源:annie.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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