本文整理汇总了Python中ij.ImagePlus.close方法的典型用法代码示例。如果您正苦于以下问题:Python ImagePlus.close方法的具体用法?Python ImagePlus.close怎么用?Python ImagePlus.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ij.ImagePlus
的用法示例。
在下文中一共展示了ImagePlus.close方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scaleandfilter
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
def scaleandfilter(infile,outfile,scalex,scaley,scalez,anisofilter,runtube):
print ("infile is: "+infile)
imp = Opener().openImage(infile)
print imp
print "scalex = %f; scaley = %f ; scalez = %f" % (scalex,scaley,scalez)
# Rescale
cal = imp.getCalibration()
iml = ImgLib.wrap(imp)
scaledimg = Scale3D(iml, scalex, scaley, scalez)
imp2=ImgLib.wrap(scaledimg)
# find range of pixel values for scaled image
from mpicbg.imglib.algorithm.math import ComputeMinMax
# (for imglib2 will be: net.imglib2.algorithm.stats)
minmax=ComputeMinMax(scaledimg)
minmax.process()
(min,max)=(minmax.getMin().get(),minmax.getMax().get())
# Make a copy of the stack (converting to 8 bit as we go)
stack = ImageStack(imp2.width, imp2.height)
print "min = %e, max =%e" % (min,max)
for i in xrange(1, imp2.getNSlices()+1):
imp2.setSliceWithoutUpdate(i)
ip=imp2.getProcessor()
# set range
ip.setMinAndMax(min,max)
stack.addSlice(str(i), ip.convertToByte(True))
# save copy of calibration info
cal=imp.getCalibration()
# close original image
imp.close()
# make an image plus with the copy
scaled = ImagePlus(imp2.title, stack)
# Deal with calibration info which didn't seem to come along for the ride
cal.pixelWidth/=scalex
cal.pixelHeight/=scaley
cal.pixelDepth/=scalez
scaled.setCalibration(cal)
print "dx = %f; dy=%f; dz=%f" % (cal.pixelWidth,cal.pixelHeight,cal.pixelDepth)
intif=infile+".tif"
outtif=infile+"-filtered.tif"
if anisofilter.upper() != 'FALSE':
print("saving input file as "+intif)
f=FileSaver(scaled)
f.saveAsTiffStack(intif)
scaled.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]))
# Open anisofilter output back into Fiji
print("Opening output tif: "+outtif)
scaled = Opener().openImage(outtif)
scaled.setCalibration(cal)
# Hessian (tubeness)
print("Running tubeness")
if(runtube):
tp=TubenessProcessor(1.0,False)
result = tp.generateImage(scaled)
IJ.run(result, "8-bit","")
else:
result=scaled
# Save out file
fileName, fileExtension = os.path.splitext(outfile)
print("Saving as "+fileExtension+": "+outfile)
if fileExtension.lower()=='.nrrd':
nw=Nrrd_Writer()
nw.setNrrdEncoding("gzip")
nw.save(result,outfile)
else:
# Save to PIC
IJ.run(result,"Biorad ...", "biorad=["+outfile+"]")
scaled.close()
result.close()
示例2: print
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
con = 1.0-(lMode[j]/iZero)
conOut.append(con)
cirOut.append(lCirc[j])
arOut.append(lAspRat[j])
rndOut.append(lRound[j])
solOut.append(lSolid[j])
orig.show()
outPth = sRptImgPath + strName + ".png"
# burn a scale bar and save the image
IJ.run(orig, "RGB Color", "")
IJ.run(orig, "Add Scale Bar", strBar)
IJ.saveAs(orig, "PNG", outPth)
orig.changes = False
orig.close()
print("%d particles detected in image %s" % (nMeas, strNum))
# prepare the output file
f=open(sRptCsvPath, 'w')
strLine = 'img, part, ecd.nm, contrast, circ, a.r, round, solidity\n'
f.write(strLine)
for k in range(len(ecdOut)):
strLine = "%d, %d, %.2f, %.4f, %.4f, %.4f, %.4f, %.4f\n" % (imgOut[k], parOut[k], ecdOut[k], conOut[k], cirOut[k], arOut[k], rndOut[k], solOut[k] )
f.write(strLine)
f.close()
toc = time.time()
示例3: str
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
IJ.log('Working on short time course around cut at frame ' + str(cutIndex))
imStack = ij.ImageStack(512,512)
for fileIndex in range(-1,21):
filename = "%06d_mix.tif" % (cutIndex+fileIndex)
#print filename
imp = IJ.openImage(os.path.join(srcDir, folder, filename))
ip = imp.getProcessor()
#print(ip)
imStack.addSlice(filename, ip)
newFileName = "%s_E%sC%d.tif" % (date, embryoNumber, 1+cutIndices.index(cutIndex))
newImp = ImagePlus(newFileName, imStack)
newImp.show()
IJ.log('Saving data to ' + os.path.join(outputDir, newFileName))
IJ.save(newImp, os.path.join(outputDir, newFileName))
newImp.close()
# Also save whole lot as an image stack...
IJ.log('Working on complete time course - this might take a while...')
images = [f for f in os.listdir(os.path.join(srcDir, folder))
if f.endswith('mix.tif')]
imStack = ij.ImageStack(512,512)
for image in images:
imp = IJ.openImage(os.path.join(srcDir, folder, image))
ip = imp.getProcessor()
imStack.addSlice(image, ip)
newFileName = "%s_E%s complete data.tif" % (date, embryoNumber)
newImp = ImagePlus(newFileName, imStack)
newImp.show()
示例4: Parameters
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
import glob
import os.path
import sys
from ij import IJ, ImagePlus, ImageStack, WindowManager
from ij.io import DirectoryChooser
from edfgui import ExtendedDepthOfField, Parameters
file_in = sys.argv[1]
file_out = sys.argv[2]
# EDF parameters
params = Parameters()
params.setQualitySettings(params.QUALITY_HIGH)
params.nScales = 10
# read input image
imp = ImagePlus(file_in)
# make all-in-focus image
edf = ExtendedDepthOfField(imp,params)
edf.process()
# save output
imp = WindowManager.getCurrentImage()
IJ.saveAsTiff(imp,file_out)
imp.close()
示例5: process
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
def process(self,imp):
# extract nucleus channel, 8-bit and twice binned
imp.setC(self.nucleusChannel)
ip = imp.getChannelProcessor().duplicate()
ip = ip.convertToByteProcessor()
ip = ip.bin(4)
nucleus = ImagePlus("nucleus_channel", ip)
# threshold image and separate clumped nuclei
IJ.run(nucleus, "Auto Threshold", "method=Otsu white setthreshold show");
IJ.run(nucleus, "Make Binary", "thresholded remaining black");
IJ.run(nucleus, "Watershed", "");
directory = imp.getTitle()
directory = directory.replace(" ", "_")\
.replace(",", "_")\
.replace("#", "_series")\
.replace("...", "")\
.replace(".","_")
directory = os.path.join(self.exportDir, directory)
sliceDirectory = os.path.join(directory, "slices")
print directory
print sliceDirectory
if not os.path.exists(sliceDirectory):
os.makedirs(sliceDirectory)
# Create a table to store the results
table = ResultsTable()
# Create a hidden ROI manager, to store a ROI for each blob or cell
#roim = RoiManager(True)
# remove small particles and border particles
pa = ParticleAnalyzer(\
ParticleAnalyzer.ADD_TO_MANAGER | ParticleAnalyzer.EXCLUDE_EDGE_PARTICLES,\
Measurements.CENTER_OF_MASS,\
table,\
self.minArea, self.maxArea,\
0.0,1.0)
if pa.analyze(nucleus):
print "All ok, number of particles: ", table.size()
else:
print "There was a problem in analyzing", imp, nucleus
table.save(os.path.join(directory, "rt.csv"))
# read the center of mass coordinates
cmx = table.getColumn(0)
cmy = table.getColumn(1)
if self.debug:
imp.show()
i=0
for i in range(0, min(self.nCells,table.size())):
# ROI around the cell
cmx = table.getValue("XM",i)
cmy = table.getValue("YM",i)
x = 4 * cmx - (self.boxSize - 1) / 2
y = 4 * cmy - (self.boxSize - 1) / 2
if (x < self.edge or y < self.edge or x > imp.getWidth() - self.edge or y > imp.getHeight() - self.edge):
continue
roi = Roi(x,y,self.boxSize,self.boxSize)
imp.setRoi(roi, False)
cellStack = ImageStack(self.boxSize, self.boxSize)
for z in range(1, imp.getNSlices() + 1):
imp.setSlice(z)
for c in range(1, imp.getNChannels() + 1):
imp.setC(c)
# copy ROI to stack
imp.copy()
impSlice = imp.getClipboard()
cellStack.addSlice(impSlice.getProcessor())
if self.slices:
sliceTitle = "cell_%s_z%s_c%s" % (str(i).zfill(4), str(z).zfill(3), str(c))
print sliceTitle
IJ.saveAsTiff(impSlice, os.path.join(sliceDirectory, sliceTitle))
impSlice.close()
title = "cell_" + str(i).zfill(4)
cell = ImagePlus(title, cellStack)
# save ROI image
IJ.saveAsTiff(cell, os.path.join(directory, title))
cell.close()
if self.debug:
imp.updateAndDraw()
wait = Wait("particle done")
wait.show()
示例6: makeMask
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
def makeMask(self):
"""
This function makes the mask. The steps are (1) Minimum Filter - makes a darker boundary around beads (2) Autothresholding using the Huang algorithm - has some fuzzy logic and seems to work (3) Analyze particles with a size between 500-50000 and
circularity between 0.4 to 1.0; The mask generated is sometimes black on beads and white around. Then I need to invert the LUTs
"""
ipOriginal = self.stack.getProcessor(self.DIC_index)
ip = ipOriginal.duplicate()
imgUpdate = ImagePlus("New",ip)
imgUpdate.setProcessor("Mask",ip)
img0 = ImagePlus("Before",ipOriginal)
img0.show()
# Minimum filter
RankFilters().rank(ip,2,RankFilters.MIN)
img1 = ImagePlus("Filter",ip)
# Autothreshold - Huang algorithm
hist = ip.getHistogram()
lowTH = Auto_Threshold.Huang(hist)
ip.setThreshold(0,lowTH, ImageProcessor.BLACK_AND_WHITE_LUT)
img3 = ImagePlus("Thresholded",ip)
img3.show()
# Making a binary mask
IJ.run(img3,"Convert to Mask","")
if self._dialog("Invert Mask ??") is True: IJ.run("Invert LUT")
img3.updateAndDraw()
# The true mask after Particle Analysis; Creates a mask image around the particles
IJ.run(img3,"Analyze Particles...", "size=500-50000 circularity=0.40-1.00 show=Masks")
img1.close()
#img3.close()
# Editing the masks (filling holes and dilating it twice)
imgActive = IJ.getImage()
IJ.run(imgActive,"Convert to Mask","")
IJ.run(imgActive,"Fill Holes","")
for i in range(8): IJ.run(imgActive,"Dilate","")
ipActive = imgActive.getProcessor().convertToFloat()
# Saving the mask
maskFname = self.sourceDir + "\\" + self.title + '_mask'
IJ.saveAs(imgActive, "PNG", maskFname)
# Confirming that the image is masked and the histogram is correct
#IJ.run(imgActive, "Histogram", "")
#stats = ipActive.getStatistics()
pixels = ipActive.getPixels()
self.maskPixels = [pix/255 for pix in pixels]
self.areaMask = self.maskPixels.count(1)
# Checking if the image is fine. If not, returns option to skip
ImageCalculator().calculate("zero create", img0, imgActive)
skip = False
if self._dialog("Skip Image ??") is True: skip = True
IJ.run("Close All")
return self.maskPixels, skip
示例7: len
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
gd.showDialog()
## Does simple interpolation of the ROIs through the stack
if len(sliceList)>0:
sliceList.sort(reverse=True)
for sl in range(theImage.getNSlices()):
if (sl+1) < sliceList[-1]:
maskImage.setSliceWithoutUpdate(sliceList[-1])
activeIp = maskImage.getProcessor().duplicate()
elif (sl+1) > sliceList[0]:
maskImage.setSliceWithoutUpdate(sliceList[0])
activeIp = maskImage.getProcessor().duplicate()
else:
isFound = False
for mark in sliceList:
dist = sl+1 - mark
if dist >= 0 and not isFound:
isFound = True
refSlice = mark
maskImage.setSliceWithoutUpdate(refSlice)
activeIp = maskImage.getProcessor().duplicate()
maskImage.setSliceWithoutUpdate(sl+1)
maskImage.setProcessor(activeIp)
## Computes the overlay image
ic = ImageCalculator()
resultImage = ic.run("AND create stack",theImage,maskImage)
resultImage.show()
maskImage.close()
示例8: NonBlockingGenericDialog
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
accept_waiter = NonBlockingGenericDialog("Thresholding...")
accept_waiter.addNumericField("Threshold:",t_line,0)
accept_waiter.setCancelLabel("Apply new threshold")
accept_waiter.setOKLabel("Accept threshold")
accept_waiter.showDialog()
if (accept_waiter.wasCanceled()):
newip.reset()
newip.snapshot()
t_line = accept_waiter.getNextNumber()
# if (t_line > 10):
# t_line = t_line - 5
# else:
# t_line = 5
newip.setThreshold(0,t_line,ImageProcessor.BLACK_AND_WHITE_LUT)
newImage.updateAndDraw()
else:
doSameSlice = False
for i in range(newImage.getWidth()):
for j in range(newImage.getHeight()):
if (newip.getPixel(i,j) > newip.getMaxThreshold()):
newip.putPixel(i,j,254)
else:
newip.putPixel(i,j,0)
newnewip = newip.duplicate()
newStack.addSlice(newnewip)
newImage.close()
castImage = ImagePlus("cast",newStack)
castImage.show()
示例9: print
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
image.setDimensions(2, z_slices, 1)
image.setOpenAsHyperStack(True)
print(image.isHyperStack(), image.getNChannels(), image.getOverlay())
#image.flattenStack()
image.show()
fs = FileSaver(image)
filepath = directory + "/" + filename + "_coloc.tiff"
fs.saveAsTiff(filepath)
image.close()
image = IJ.getImage()
IJ.run(image_dapi,"Convert to Mask", "method=Otsu background=Default calculate")
fs = FileSaver(image_dapi)
filepath = directory + "/" + filename + "_dapi.tiff"
fs.saveAsTiff(filepath)
#image = IJ.getImage()
#image.close()
[red_spots, red_spots_dapi] = get_red_spots(rest, z_slices, image_dapi)
[green_spots, green_spots_dapi] = get_green_spots(rest, z_slices, image_dapi)
示例10: ImageReader
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
## Outputs each stitched z plane as a separate file
iReader = ImageReader()
iReader.setId(parentLSMFilePath)
for z in range(max_coords[2]+basic_info[4]):
## for z in range(50,51):
IJ.showStatus("z: "+str(z+1)+" of "+str(max_coords[2]+basic_info[4]))
chIps = []
resImages = []
for ch in range(basic_info[0]):
chIps.append(ByteProcessor(max_coords[0]+scale_info[2],max_coords[1]+scale_info[2]))
for ch in range(basic_info[0]):
resImages.append(ImagePlus("ch"+str(ch+1),chIps[ch]))
for se in range(basic_info[1]):
IJ.showProgress(se,basic_info[1])
if z >= coords_upscaled[se][2] and z <= coords_upscaled[se][2]+basic_info[4]-1:
iReader.setSeries(se)
for ch in range(basic_info[0]):
byteArray = iReader.openBytes((z-coords_upscaled[se][2])*basic_info[0]+ch)
testIp = ByteProcessor(scale_info[2],scale_info[2],byteArray)
testImage = ImagePlus("tester",testIp)
Image_stamper.stampStack(testImage,resImages[ch],coords_upscaled[se][0],coords_upscaled[se][1],0)
activeIp = chIps[ch]
testImage.close()
for ch in range(len(resImages)):
IJ.saveAsTiff(resImages[ch],parentLSMFilePath+"_tiles/v_img/img_z_"+str(z+1)+"_c_"+str(ch+1)+".tif")
#outPlaneImage = RGBStackMerge.mergeChannels(resImages,False)
#IJ.saveAsTiff(outPlaneImage,parentLSMFilePath+"_tiles/v_img/img_z_"+str(z+1)+".tif")
#outPlaneImage.close()
示例11:
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
imstack=ImagePlus("stack3", istack)
#IJ.run("Images to Stack", "name="+cle+"-plots title="+cle+" use")
imstack.show()
IJ.selectWindow("stack3")
#imtorgb=[implot1,implot2,implot3]
#rgbcon=RGBStackMerge()
#IJ.run("Merge Channels...", "red="+implot1.getTitle()+" green="+implot2.getTitle()+" blue="+implot3.getTitle()+" gray=*None*");
#lastimage=IJ.getImage()
#lastimage = rgbcon.mergeChannels(imtorgb, True)
#lastimage.show()
#IJ.run("Invert", "stack")
IJ.run("Stack to RGB", "")
lastimage=IJ.getImage()
imstack.close()
#cp = lastimage.getProcessor().convertToRGB()
cp = lastimage.getProcessor()
try : rgbstack.addSlice(cle, cp)
except NameError :
rgbstack = lastimage.createEmptyStack()
rgbstack.addSlice(cle, cp)
lastimage.close()
#IJ.selectWindow(cle+"-plots")
#IJ.getImage().hide()
del(reversions)
del(speed)
del(cumuld)
imprgb=ImagePlus("rgbStack", rgbstack)
示例12: gui
# 需要导入模块: from ij import ImagePlus [as 别名]
# 或者: from ij.ImagePlus import close [as 别名]
class gui(JFrame):
def __init__(self): # constructor
#origing of coordinates
self.coordx = 300
self.coordy = 50
self.imageCount = 0 #a counter for the image list
self.listendFlag = 0 #some values to check
#inintialize values
self.imLeft = None
self.imRight = None
self.chosenOne = None
self.chosenIm = None
#create panel (what is inside the GUI)
self.panel = self.getContentPane()
self.panel.setLayout(GridLayout(5,2))
#define buttons here:
quitButton = JButton("Quit", actionPerformed=self.quit)
loadButton = JButton("Load", actionPerformed=self.load)
leftButton = JButton("Choose Left", actionPerformed = self.ChooseLeft)
rightButton = JButton("Choose Right", actionPerformed = self.ChooseRight)
ThresButton = JButton("Threshold",actionPerformed = self.ImThresh)
self.ThreshField = JTextField("5", 1)
StartConversionButton = JButton("Start Conversion", actionPerformed = self.StartConv)
ConvertButton = JButton("Convert Image", actionPerformed = self.ImConvert)
#Zslider = JSlider(JSlider.HORIZONTAL,0, 100, 0)
#add buttons here
self.panel.add(loadButton)
self.panel.add(quitButton)
self.panel.add(leftButton)
self.panel.add(rightButton)
self.panel.add(self.ThreshField)
self.panel.add(ThresButton)
self.panel.add(StartConversionButton)
self.panel.add(ConvertButton)
#self.panel.add(Zslider)
#other stuff to improve the look
self.pack() # packs the frame
self.setVisible(True) # shows the JFrame
self.setLocation(0,self.coordy+200)
#define functions for the buttons:
def quit(self, event): #quit the gui
if self.imLeft is not None:
self.imLeft.close()
self.imRight.close()
self.dispose()
def load(self, event): #choose a folder to load images
self.imdir = DirectoryChooser("Select a dir, dude").getDirectory()
self.pictureList = [path.join(self.imdir, f) for f in listdir(self.imdir) if path.splitext(f)[1]==".tiff" and 'AVG' not in f and 'Avg' not in f] #list of pictures (not averages) with .tiff extension
print self.pictureList #list of pictures
self.imLeft = ImagePlus(self.pictureList[self.imageCount]) #read the image
self.imageCount =self.imageCount+1 #increase counter
self.imRight = ImagePlus(self.pictureList[self.imageCount]) #read the image
self.imageCount =self.imageCount+1
self.imLeft.show() #show image on the left
self.imLeft.getWindow().setLocation(self.coordx,self.coordy) #reposition image
self.imRight.show() #show image on the right
self.rightImLocx = self.coordx+self.imLeft.getWindow().getWidth() #set a variable with the x position for right image
self.imRight.getWindow().setLocation(self.rightImLocx,self.coordy) #reposition image
#WindowOrganizer("Tile")
#SyncWindows(self.imLeft.getTitle() + " " + self.imRight.getTitle())
#IJ.run("Sync Windows")
print len(self.pictureList)
def ChooseLeft(self, event): #remove right image and load another
if self.listendFlag==0: #if is not the end of the list
print "You chose left, which is of course right"
self.imRight.close()
if self.imageCount>=len(self.pictureList): #if is the end of the list
print "YOU HAVE A WINNER!!!"
self.listendFlag = 1 #flag
if self.imageCount==len(self.pictureList):
self.chosenOne = 'L' #a variable to know the position of the chosen one
self.imageCount = self.imageCount+1 #this is to avoid changing the chosen one
else:
self.imRight = ImagePlus(self.pictureList[self.imageCount]) #read next image
self.imageCount =self.imageCount+1 #increase counter
#.........这里部分代码省略.........