本文整理汇总了Python中ij.io.FileSaver类的典型用法代码示例。如果您正苦于以下问题:Python FileSaver类的具体用法?Python FileSaver怎么用?Python FileSaver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileSaver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SaveToZip
def SaveToZip(zf, ip, baseDir, counter):
fs = FileSaver(ip)
fs.setJpegQuality(75)
fs.saveAsJpeg(baseDir + "/tmp.jpeg")
zipName = str(counter) + ".jpeg"
zf.write(baseDir + "/tmp.jpeg", arcname=zipName)
os.remove(baseDir + "/tmp.jpeg")
示例2: autoProcAZtecImage
def autoProcAZtecImage(fwMicrons, wrkDir, barWid=0.1, barHt=9, barFnt=24, barCol="Black", barLoc="Lower Right"):
imp = IJ.getImage()
fName = imp.getShortTitle()
wid = imp.getWidth()
argThree = "distance=%g known=%f pixel=1 unit=um" % (wid, fwMicrons)
IJ.run(imp, "Set Scale...", argThree)
IJ.run(imp, "Enhance Contrast", "saturated=0.35")
fs = FileSaver(imp)
if path.exists(wrkDir) and path.isdir(wrkDir):
print "folder exists:", wrkDir
tifName = fName + ".tif"
tifPath = path.join(wrkDir, tifName)
print(tifPath)
if fs.saveAsTiff(tifPath):
print "Tif saved successfully at ", tifPath
IJ.run(imp, "RGB Color", "")
# dummy to get things set
foo = imp.duplicate()
s2 = "width=%g height=%g font=%g color=%s location=[%s] bold" % (barWid, barHt, barFnt, barCol, barLoc)
IJ.run(foo, "Add Scale Bar", s2)
# explicitly save preferences
Prefs.savePreferences()
foo.changes = False
foo.close()
IJ.run(imp, "Add Scale Bar", s2)
fs = FileSaver(imp)
pngName = fName + ".png"
pngPath = path.join(wrkDir, pngName)
if fs.saveAsPng(pngPath):
print "png saved successfully at ", pngPath
示例3: makeStack
def makeStack(stackDir, stackName = "stack"):
IJ.run("Image Sequence...", "open="+stackDir+" file = (\"img_.*\") sort")
imp = IJ.getImage()
#IJ.run("8-bit")
fs = FileSaver(imp)
print "Saving stack"
fs.saveAsTiff(stackDir + "/" +stackName+".tif")
示例4: run
def run():
printLog("=====ZY_CreatTemp_V2====",0)
#Prompt user to open a image
od = OpenDialog("Choose image file", None)
if od is None:
msgStr = "User Cancled"
printLog(msgStr,1)
else:
sourceFolder = od.getDirectory()
fileName = od.getFileName()
imp = IJ.openImage(sourceFolder+fileName)
imp.show()
n = imp.getNSlices()
printLog("Processing source file: " + fileName,1)
imp2= pickSlice(imp)
if imp2:
destFolder = os.path.join(sourceFolder, 'Temps')
#outName = os.path.join(destFolder,fileName[:-4]+'_temp.tif') #remove the .tif in filename
outName = os.path.join(destFolder,'temp.tif')
# check or make the folder
if not os.path.isdir(destFolder):
os.makedirs(destFolder)
#make temp
dupNSlice(imp2,n-1)
printLog("Saving to: " + outName,1)
fs = FileSaver(imp2)
fs.saveAsTiffStack(outName)
imp2.close()
imp.close()
msgStr = "ZY_CraetTemp_V2.py is Done."
printLog(msgStr,0)
示例5: bSaveStack
def bSaveStack(imp, fullPath):
fs = FileSaver(imp)
#print 'bSaveStack()', fullPath, 'nslices=', imp.getNSlices()
bPrintLog('bSaveStack():' + fullPath + ' slices=' + str(imp.getNSlices()), 1)
if imp.getNSlices()>1:
fs.saveAsTiffStack(fullPath)
else:
fs.saveAsTiff(fullPath)
示例6: straighten
def straighten(stackName):
'''
IJ.run("Set Measurements...", "area mean min center redirect=None decimal=3")
IJ.open(stackName)
imp = IJ.getImage()
stack = imp.getImageStack()
for i in xrange(1, imp.getNSlices()+1):
image = ImagePlus(str(i), stack.getProcessor(i))
xvals = []
yvals = []
maxvals = []
j = 0
for k in xrange(0, 512, 2):
IJ.makeRectangle(k, 0, 4, 512)
IJ.run("Measure")
table = RT.getResultsTable()
x = table.getValue("XM", 0)
y = table.getValue("YM", 0)
#maxi = IJ.getResult("Max")
table = []
xvals.append(k)
yvals.append(y)
#maxvals.append(maxi)
#if maxvals[j] == 0 and j > 0:
#yvals[j] = yvals[j-1]
j += 1
print "xvals:", xvals
print "yvals:", yvals
mr = MR()
IJ.run("Make Selection...", "freeline, "+str(xvals)+" ,"+ str(yvals))
#IJ.runMacro("makeSelection...", "freeline, "+str(xvals)+" ,"+ str(yvals));
#IJ.run("makeSelection(\"freeline\", xvals, yvals);")
#IJ.run("Straighten...", "line = 80")
'''
IJ.open(stackName)
imp = IJ.getImage()
stack = imp.getImageStack()
print imp.getNSlices()
for i in range(1, imp.getNSlices()+1):
image = ImagePlus(str(i), stack.getProcessor(i))
IJ.runMacroFile("/Users/juliansegert/repos/Bio119_root_tracking/straightenOneImage.ijm")
newImp = WM.getCurrentImage()
fs = FileSaver(newImp)
fs.saveAsTiff("/Users/juliansegert/Documents/Roots/Four_root_image_stacks/Pos01/"+str(i)+".tif")
newImp.close()
示例7: saveStack
def saveStack(destFolder,file_name,imp):
#rename the result and save it to subfolder
if not os.path.isdir(destFolder):
os.makedirs(destFolder)
fullname=os.path.join(destFolder,file_name)
#print (fullname)
fs = FileSaver(imp)
#print 'bSaveStack()', fullPath, 'nslices=', sr_imp.getNSlices()
msgStr = "Dimension:" + str(imp.width) + " X " + str(imp.height) + " X " + str(imp.getNSlices())
printLog("-Save "+file_name+" to "+destFolder,1)
printLog("-"+msgStr,2)
fs.saveAsTiffStack(fullname)
示例8: applyFilter
def applyFilter(stackName):
imp = IJ.openImage(stackName)
stack = imp.getImageStack()
for i in xrange(1, imp.getNSlices()+1):
image = ImagePlus(str(i), stack.getProcessor(i))
IJ.run(image, "Auto Threshold", "method=Li white")
#IJ.run(image, "Analyze Particles...", "size= 1000-Infinity circularity=0.00-1.00 show=Masks in_situ")
imp2 = ImagePlus("Threshold", stack)
fs = FileSaver(imp2)
print "Saving filtered stack"
fs.saveAsTiff(stackName[:-4] + "-filtered(Li).tif")
示例9: scaleandfilter
def scaleandfilter(infile,outfile,scalex,scaley):
print ("infile is: "+infile)
imp = Opener().openImage(infile)
print imp
print "scalex = %f; scaley = %f" % (scalex,scaley)
# Rescale
ip = imp.getProcessor()
ip.setInterpolate(True)
sp = StackProcessor(imp.getStack(),ip);
sp2=sp.resize(int(round(ip.width * scalex)), int(round(ip.height *scaley)));
imp.setStack(imp.getTitle(),sp2);
cal = imp.getCalibration()
cal.pixelWidth /= scalex
cal.pixelHeight /= scaley
IJ.run(imp, "8-bit","")
intif=infile+".tif"
outtif=infile+"-filtered.tif"
print("saving input file as "+intif)
f=FileSaver(imp)
f.saveAsTiffStack(intif)
imp.close()
# anisotropic filtering
anisopts="-scanrange:10 -tau:2 -nsteps:2 -lambda:0.1 -ipflag:0 -anicoeff1:1 -anicoeff2:0 -anicoeff3:0"
anisopts=anisopts+" -dx:%f -dy:%f -dz:%f" % (cal.pixelWidth,cal.pixelHeight,cal.pixelDepth)
if sys.version_info > (2, 4):
#for testing
# subprocess.check_call(["cp",intif,outtif])
subprocess.check_call(["anisofilter"]+anisopts.split(' ')+[intif,outtif])
else:
os.system(" ".join(["anisofilter"]+anisopts.split(' ')+[intif,outtif]))
# Hessian (tubeness)
print("Opening output tif: "+outtif)
imp = Opener().openImage(outtif)
imp.setCalibration(cal)
print("Running tubeness on tif: "+outtif)
IJ.run(imp,"Tubeness", "sigma=1")
IJ.run(imp, "8-bit","")
# Save to PIC
print("Saving as PIC: "+outfile)
# IJ.saveAs("tiff","outtif")
IJ.run(imp,"Biorad ...", "biorad="+outfile)
示例10: run
def run():
msg = "<html>"
wm = WindowManager
wcount = wm.getWindowCount()
if wcount == 0:
msg += "No windows open, nothing to do.<br/>"
IJ.showMessage(PluginTitle, msg)
return
msg += "Number of open windows: " + str(wcount) + "<br/>"
# let the User choose a directory to store the files
target = DirectoryChooser("Choose target directory").getDirectory()
if target is None:
# User canceled the dialog
msg += "<br/>No directory chosen, aborting.<br/>"
IJ.showMessage(PluginTitle, msg)
return
msg += "Selected '" + target + "'as destination folder.<br/>"
# determine padding width for filenames
pad = len(str(wcount))
for i in range(wcount):
# image ID lists start with 1 instead of 0, so for convenience:
wid = i + 1
imp = wm.getImage(wid)
imgid = wm.getNthImageID(wid)
#print "window id:", wid, ", imageID:", wm.getNthImageID(wid)
# Construct filename
filename = 'tile_' + str(wid).zfill(pad) + '.tif'
filepath = target + '/' + filename
fs = FileSaver(imp)
if imp.getImageStackSize() > 1:
if not fs.saveAsTiffStack(filepath):
IJ.error("<html>Error saving current image, stopping.")
return
else:
if not fs.saveAsTiff(filepath):
IJ.error("<html>Error saving current image, stopping.")
return
msg += "<br/>Successfully saved " + str(wcount) + " files.<br/>"
IJ.showMessage(PluginTitle, msg)
示例11: process
def process(srcDir, dstDir, nameContains, currentDir, fileName, keepDirectories, anneBoleyn, overOut):
print "Opening", fileName
saveDir = currentDir.replace(srcDir, dstDir) if keepDirectories else dstDir
head, tail = os.path.splitext(fileName)
imps = BF.openImagePlus(os.path.join(currentDir, fileName))
for imp in imps:
if not anneBoleyn:
print "Now showing image..."
imp.show()
IJ.run(imp, "Blue", "")
fs = FileSaver(imp)
if not os.path.exists(saveDir):
os.makedirs(saveDir)
if not overOut:
if os.path.exists(saveDir + "\\" + head + ".jpg"):
print "This JPG exists already and will not be overwritten. Moving on..."
else:
print "Saving to", os.path.join(saveDir, head + ".jpg")
fs.saveAsJpeg(os.path.join(saveDir, head + ".jpg"))
imp.close()
示例12: saveMaxProject
def saveMaxProject(self, destFolder=''):
# ch1
if self.imp_ch1:
# make max project
zp = ZProjector(self.imp_ch1)
zp.setMethod(ZProjector.MAX_METHOD)
zp.doProjection()
zimp = zp.getProjection()
# save
fs = FileSaver(zimp)
bPrintLog('saveMaxProject():' + self.savePathMax_ch1, 3)
fs.saveAsTiff(self.savePathMax_ch1)
# ch2
if self.imp_ch2:
# make max project
zp = ZProjector(self.imp_ch2)
zp.setMethod(ZProjector.MAX_METHOD)
zp.doProjection()
zimp = zp.getProjection()
# save
fs = FileSaver(zimp)
bPrintLog('saveMaxProject():' + self.savePathMax_ch2, 3)
fs.saveAsTiff(self.savePathMax_ch2)
# ch1
if self.imp_ch3:
# make max project
zp = ZProjector(self.imp_ch3)
zp.setMethod(ZProjector.MAX_METHOD)
zp.doProjection()
zimp = zp.getProjection()
# save
fs = FileSaver(zimp)
bPrintLog('saveMaxProject():' + self.savePathMax_ch3, 3)
fs.saveAsTiff(self.savePathMax_ch3)
示例13: FileSaver
labId = "qm-04513"
smpId = "RAD-2015-0148Y-HCl-xs"
datDir = edsDir + "/Oxford/" + ePrjDir + "/reports/" + labId + "-" + smpId
sTifPath = datDir + "/tif/"
bSetMinMax = False
gMin = 1000
gMax = 11400
fwUnits = 28.9
units = IJ.micronSymbol + "m"
imp = IJ.getImage()
imp = jmg.calibImage(imp, fwUnits, units=-6)
if(bSetMinMax == True):
IJ.setMinAndMax(gMin, gMax)
imp.updateAndRepaintWindow()
ti = imp.getShortTitle()
fi = sTifPath + ti + ".tif"
fs = FileSaver(imp)
imp.changes = False
print(fi)
if fs.saveAsTiff(fi):
print "Tif saved successfully at ", fi
print("done")
示例14: run
#.........这里部分代码省略.........
if imp is None:
msgStr = " ERROR: Could not open image from file: " + filename
print msgStr
IJ.log(msgStr)
continue #with next iteration
imp.show()
numOpened +=1
infoStr = imp.getProperty("Info") #get all .tif tags
if not infoStr:
infoStr = ''
infoStr += 'bBatchConvertTo8Bit_Version=' + str(gVersion) + '\n'
infoStr += 'bBatchConvertTo8Bit_Time=' + time.strftime("%Y%m%d") + '_' + time.strftime("%H%M%S") + '\n'
msgStr = " Original Image is: " + str(imp.width) + " X " + str(imp.height) + " X " + str(imp.getNSlices())
print msgStr
IJ.log(msgStr)
if imp.getBitDepth() == 16:
msgStr = " Converting to 8-bit..."
print msgStr
IJ.log(msgStr)
IJ.run("8-bit")
if numberOfChannels == 2:
msgStr = " deinterleaving"
print msgStr
IJ.run("Deinterleave", "how=2"); #makes 2 window
#
#ch2
imp2 = IJ.getImage()
imp2.setProperty("Info", infoStr);
fs = FileSaver(imp2)
msgStr = " ch2: Saving deinterleaved 8bit File to: " + outPath2
print msgStr
IJ.log(msgStr)
numSlices = imp2.getNSlices()
if (numSlices>1):
fs.saveAsTiffStack(outPath2)
else:
fs.saveAsTiff(outPath2)
#max, ch2
if (numSlices>1):
maxCmdParams = 'start=1' + ' stop=' + str(numSlices) + ' projection=[Max Intensity]'
IJ.run("Z Project...", maxCmdParams)
#impMax2 = IJ.getImage()
print " Saving 8bit Max File to", outMaxPath2
impMax2 = IJ.getImage()
fs = FileSaver(impMax2)
fs.saveAsTiff(outMaxPath2)
impMax2.changes = 0
impMax2.close()
numSaved += 1
imp2.changes = 0
imp2.close()
#
#ch1
imp1 = IJ.getImage()
imp1.setProperty("Info", infoStr);
示例15: runOneTif
#.........这里部分代码省略.........
madeAverage = 0
# if numSlices is not divisable by gNumToAverage then chop a few slices off bottom/end
if b_sequence.startswith('TSeries'):
if globalOptions['gNumToAverage'] > 1:
numToRemove = numSlices % globalOptions['gNumToAverage']
if numToRemove > 0:
bPrintLog('Removing bottom slices: ' + str(numToRemove), 3)
# run("Slice Remover", "first=3 last=5 increment=1");
removeArgs = 'first=' + str(numSlices-numToRemove+1) + ' last=' + str(numSlices) + ' increment=1'
IJ.run('Slice Remover', removeArgs)
numSlices = imp.getNSlices()
bPrintLog('numSlices: ' + str(numSlices), 3)
#fix this: if stack is really short this will not be taken
if (numSlices > globalOptions['gNumToAverage']):
bPrintLog('Taking average of ' + str(globalOptions['gNumToAverage']) + ' slices from ' + str(numSlices), 3)
stackRegParams = 'projection=[Average Intensity] group=' + str(globalOptions['gNumToAverage'])
IJ.run('Grouped Z Project...', stackRegParams) # makes window AVG_
madeAverage = 1
avgWindow = 'AVG_' + impWin
avgImp = WindowManager.getImage(avgWindow)
avgSlices = avgImp.getNSlices()
# Grouped Z PRoject swaps slices for frames?
tmpSlices = avgImp.getNSlices()
tmpFrames = avgImp.getNFrames()
if tmpFrames > 1:
newSlices = tmpFrames
newFrames = tmpSlices
nChannels = 1
bPrintLog('Swaping frames for slices after grouped z',3)
bPrintLog('newSlices=' + str(newSlices) + ' newFrames='+str(newFrames), 4)
avgImp.setDimensions(nChannels, newSlices, newFrames)
infoStr += 'gNumToAverage=' + str(globalOptions['gNumToAverage']) + '\n'
# I want to adjust the framePeriod, prairie would be 'b_framePeriod'
avgImp.setProperty("Info", infoStr)
else:
avgImp = imp
avgSlices = numSlices
else:
bPrintLog('Not taking average of sequence: ' + b_sequence,3)
avgImp = imp
avgSlices = numSlices
if globalOptions['medianFilter']>0:
bPrintLog('Running median filter: ' + str(globalOptions['medianFilter']), 3)
medianArgs = 'radius=' + str(globalOptions['medianFilter']) + ' stack'
IJ.run(avgImp, "Median...", medianArgs);
infoStr += 'bMedianFilter=' + str(globalOptions['medianFilter']) + '\n'
avgImp.setProperty("Info", infoStr)
# convert to 8 bit
# 1) read bit depth from header (e.g. 2^13)
# 2) do math on image and convert to 8-bit
# run("Divide...", "value=32 stack");
if globalOptions['gConvertToEightBit']:
bPrintLog('converting to 8-bit by dividing image down and then convert to 8-bit with ImageConverter.setDoScaling(False)', 3)
bitDepth = 2^13
divideBy = bitDepth / 2^8
# divide the 13 bit image down to 8 bit
#run("Divide...", "value=32 stack");
bPrintLog('divideBy:' + str(divideBy), 3)
divideArgs = 'value=' + str(divideBy) + ' stack'
IJ.run(avgImp, "Divide...", divideArgs);
# convert to 8-bit will automatically scale, to turn this off use
# eval("script", "ImageConverter.setDoScaling(false)");
ImageConverter.setDoScaling(False)
# run("8-bit");
bPrintLog('converting to 8-bit with setDoScaling False', 3)
IJ.run(avgImp, "8-bit", '');
bPrintLog('Saving stack with ' + str(avgSlices) + ' slices:' + dstTifPath, 3)
fs = FileSaver(avgImp)
if avgSlices>1:
fs.saveAsTiffStack(dstTifPath)
else:
fs.saveAsTiff(dstTifPath)
if madeAverage:
avgImp.changes = 0
avgImp.close()
imp.changes = 0
imp.close()
# end body
#
# why was this here
#imp.changes = 0
#imp.close()
return 1