本文整理汇总了Python中tifffile.imsave函数的典型用法代码示例。如果您正苦于以下问题:Python imsave函数的具体用法?Python imsave怎么用?Python imsave使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imsave函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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
示例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")
示例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
示例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)
示例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))
示例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)
示例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()
示例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"
示例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)
示例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'))
示例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)
示例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
示例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;
示例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