本文整理汇总了Python中ij.plugin.frame.RoiManager.addRoi方法的典型用法代码示例。如果您正苦于以下问题:Python RoiManager.addRoi方法的具体用法?Python RoiManager.addRoi怎么用?Python RoiManager.addRoi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ij.plugin.frame.RoiManager
的用法示例。
在下文中一共展示了RoiManager.addRoi方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RoiSelection
# 需要导入模块: from ij.plugin.frame import RoiManager [as 别名]
# 或者: from ij.plugin.frame.RoiManager import addRoi [as 别名]
def RoiSelection():
true=1
false=0
IJ.run("Invert", "stack");
IJ.run("Fill Holes", "stack");
IJ.run("Create Selection");
rm = RoiManager()
rm.runCommand("add")
rm.runCommand("split")
#number_selected=rm.getCount()
IJ.run("Select None");
rm.runCommand("deselect")
#rm.select(0)
#print number_selected
roi_array=rm.getRoisAsArray()
max_roi=None
max_points=-1
for roi in roi_array:
polygon=roi.getPolygon()
if polygon is not None:
number_of_points = polygon.npoints
if max_points < number_of_points:
max_points=number_of_points
max_roi=roi
#print max_points
#sorted_roi_array=sorted(roi_array, key=methodcaller('getLength'), reverse=True)
#length_array=[]
#index=0
#for roi in roi_array:
# index=index+1
# length_array.append((index,roi.getLength()))
#sorted_length_array=sorted(length_array, key=itemgetter(0))
rm.runCommand("Select All")
rm.runCommand("Delete")
#for roi in roi_array:
interpolated_polygon=max_roi.getInterpolatedPolygon(20,True)
roi_polygon=PolygonRoi(interpolated_polygon,Roi.POLYGON)
rm.addRoi(roi_polygon)
示例2: __displayCells
# 需要导入模块: from ij.plugin.frame import RoiManager [as 别名]
# 或者: from ij.plugin.frame.RoiManager import addRoi [as 别名]
def __displayCells(self, nameimage, methodeleon=False):
"""
Displays all the ROIs of the cells with different colors
"""
# we define a list of colors that will be used.
colors = []
ncells= len(self.__dict[nameimage])
if ncells > 0 :
step=200/ncells
if step<1 : step=1
for i in range(ncells) :
r = random.randrange(5,205,step)
g = random.randrange(10,210,step)
b = random.randrange(30,230,step)
#r = int(0+i*step)
#g = random.randrange(10, 190, 30)
#b = int(250-i*step)
colors.append(Color(r, g, b))
else : colors=[Color.blue, Color.green, Color.magenta, Color.orange, Color.yellow]
tempcolors=list(colors)
# we try to have random and different colors for each cell.
for cellname in self.__dict[nameimage].keys() :
if len(tempcolors)>0 :
self.__dict[nameimage][cellname].setColor(tempcolors.pop(0))
else :
tempcolors=list(colors)
self.__dict[nameimage][cellname].setColor(tempcolors.pop(0))
self.__SaveCells(nameimage)
rm = RoiManager.getInstance()
if (rm==None): rm = RoiManager()
rm.runCommand("reset")
# if the user wants to save files, .zip for the ROIs are saved.
#if self.__optionSave == True :
#os.mkdir(self.__pathdir+"ROIs/", mode=0777)
os.makedirs(self.__pathdir+"ROIs/", mode=0777)
tempimp = IJ.createImage("tempimp", "8-bit Black", self.__dictImages[nameimage].getWidth(), self.__dictImages[nameimage].getHeight(), 1)
tempimp.show()
for cellname in self.__dict[nameimage].keys() :
for numslice in range(self.__dictImages[nameimage].getImageStackSize()) :
r = self.__dict[nameimage][cellname].getRoi(numslice)
try :
name=r.getName()
except AttributeError : continue
else :
s = "%04i" % (numslice+1)
#name=s+"-"+name.split("-", 1)[1]
name=s+"-cell"+name.split("cell")[1]
r.setName(name)
try :
rm.addRoi(r)
rname=rm.getName(rm.getCount()-1)
#rm.select(self.__dictImages[nameimage], rm.getCount()-1)
rm.select(tempimp, rm.getCount()-1)
rm.runCommand("Rename", name)
except TypeError : continue
#if isinstance(self.__dict[nameimage][cellname].getRoi(numslice),Roi) == True :
# s = "%04i" % (numslice)
# #rm.add(self.__dictImages[nameimage], self.__dict[nameimage][cellname].getRoi(numslice) , numslice)
# name=self.__dict[nameimage][cellname].getRoi(numslice).getName()
# name=s+name
# self.__dict[nameimage][cellname].getRoi(numslice).setName(name)
# rm.addRoi(self.__dict[nameimage][cellname].getRoi(numslice))
rm.runCommand("Save", self.__pathdir+"ROIs/"+cellname+".zip")
rm.runCommand("reset")
tempimp.close()
示例3: __settings
# 需要导入模块: from ij.plugin.frame import RoiManager [as 别名]
# 或者: from ij.plugin.frame.RoiManager import addRoi [as 别名]
#.........这里部分代码省略.........
#velocities=[]
for i in range(len(self.__listcellname)) :
IJ.showProgress(i, len(self.__listcellname))
self.__measurecumulDist(self.__img,imgName)
self.__img.show()
self.__img.getProcessor().resetThreshold()
if self.__updateoverlay :
if self.__img.getOverlay() is not None : self.__img.getOverlay().clear()
outputrois=[]
cellnames=[]
self.__img.hide()
for cellname in self.__listcellname :
for r in dico[cellname].getListRoi():
if isinstance(r,Roi) :
pos=r.getPosition()
#print "MC overlay", cellname, r.getName(), pos
#r.setPosition(0)
#overlay.add(r)
outputrois.append(r)
if "cell" in r.getName() : cellnames.append(r.getName())
else : cellnames.append(str(pos)+"-"+cellname)
#print cellnames[-1]
rm = RoiManager.getInstance()
if (rm==None): rm = RoiManager()
rm.show()
self.__img.show()
IJ.selectWindow(self.__img.getTitle())
rm.runCommand("reset")
for i in range(len(outputrois)) :
outputrois[i].setName(cellnames[i])
rm.addRoi(outputrois[i])
rm.select(rm.getCount()-1)
rm.runCommand("Rename", cellnames[i])
IJ.run("Show Overlay", "")
rm.runCommand("UseNames", "true")
rm.runCommand("Associate", "true")
IJ.run(self.__img, "Labels...", "color=red font=12 show use")
IJ.run(self.__img, "From ROI Manager", "")
rm.runCommand("Show None")
rm.runCommand("Show All")
# ----------- batch analyse ------------------------
if self.__batchanalyse :
if self.__savetables : saveResults()
self.__dictMeasures.clear()
self.__allcells[:]=[]
self.__measurescompl[:]=[]
self.__measures[:]=[]
return False
# ---------- display methodes dialog ----------------
# Allows the user to choose how to see the results of the measures.
gd0=NonBlockingGenericDialog("Display")
gd0.addMessage("How do you want to see the results ?")
panel0=Panel()
diagrambutton=Button("Diagram")
diagrambutton.actionPerformed = diagrambuttonPressed
panel0.add(diagrambutton)
graphbutton=Button("Graph")
graphbutton.actionPerformed = graphbuttonPressed
panel0.add(graphbutton)
tabbutton=Button("Tab")
tabbutton.actionPerformed = tabbuttonPressed
panel0.add(tabbutton)
gd0.addPanel(panel0)
gd0.addCheckbox("Analyse next stack ?", self.__nextstack)
gd0.hideCancelButton()
gd0.showDialog()
self.__nextstack = gd0.getNextBoolean()
# ---------- save tables ---------------------------
if self.__savetables : saveResults()
# --------- re-start analysis -------------------
self.__dictMeasures.clear()
#self.__listcellname[:]=[]
self.__allcells[:]=[]
self.__measurescompl[:]=[]
self.__measures[:]=[]
if self.__nextstack : return False
else : return True
示例4: CellsSelection
# 需要导入模块: from ij.plugin.frame import RoiManager [as 别名]
# 或者: from ij.plugin.frame.RoiManager import addRoi [as 别名]
#.........这里部分代码省略.........
def __show(self, event):
IJ.run("Show Overlay", "")
def __hide(self, event):
IJ.run("Hide Overlay", "")
def __showall(self, event) :
self.__rm.runCommand("Associate", "false")
self.__rm.runCommand("Show All")
def __showone(self, event) :
self.__rm.runCommand("Associate", "true")
self.__rm.runCommand("Show All")
def __reset(self, event) :
self.__rm.runCommand("reset")
def __boxaction(self, event):
self.__setDisplay(str(event.getSource().text)+" is "+str(event.getSource().isSelected()))
if event.getSource().isSelected() : #print self.__dictFiles[event.getSource().text][1]
#self.__rm.runCommand("reset")
self.__rm.runCommand("Open", self.__dictFiles[event.getSource().text][1])
def __setDisplay(self, val=""):
self.__display.text = str(val)
def __split(self, event) :
sel = self.getSelected()
if len(sel) != 1 :
IJ.showMessage("only one cell should be selected !")
return
else :
cellname = sel[0]
rois = self.__rm.getRoisAsArray()
self.__rm.runCommand("reset")
n = int(IJ.getNumber("slice to split ?", 1))
for i in range(n) :
self.__rm.addRoi(rois[i])
#print self.__path+cellname+"-a.zip"
self.__rm.runCommand("Save", self.__path+cellname+"-a.zip")
self.__rm.runCommand("reset")
for i in range(n, len(rois)) :
self.__rm.addRoi(rois[i])
self.__rm.runCommand("Save", self.__path+cellname+"-b.zip")
self.__rm.runCommand("reset")
root = self.__path.rsplit(os.path.sep, 2)[0]+os.path.sep
if not path.exists(root+"Cells"+os.path.sep) :os.makedirs(root+"Cells"+os.path.sep, mode=0777)
fichiertemp = open(root+"Cells"+os.path.sep+cellname+"-a.cell","w")
fichiertemp.write("NAMECELL="+cellname+"-a\n")
fichiertemp.write("PATHCELL="+root+"Cells"+os.path.sep+cellname+"-a.cell\n")
fichiertemp.write("PATHROIS="+root+"ROIs"+os.path.sep+cellname+"-a.zip\n")
fichiertemp.write("NSLICES="+str(len(rois))+"\n")
fichiertemp.write("SLICEINIT="+str(1)+"\n")
fichiertemp.write("SLICEEND="+str(n)+"\n")
r = random.randrange(5,205,1)
g = random.randrange(10,210,1)
b = random.randrange(30,230,1)
fichiertemp.write("COLOR="+str(r)+";"+str(g)+";"+str(b)+"\n")
fichiertemp.close()
fichiertemp = open(root+"Cells"+os.path.sep+cellname+"-b.cell","w")
fichiertemp.write("NAMECELL="+cellname+"-b\n")
fichiertemp.write("PATHCELL="+root+"Cells"+os.path.sep+cellname+"-b.cell\n")
fichiertemp.write("PATHROIS="+root+"ROIs"+os.path.sep+cellname+"-b.zip\n")
fichiertemp.write("NSLICES="+str(len(rois))+"\n")
fichiertemp.write("SLICEINIT="+str(n+1)+"\n")
fichiertemp.write("SLICEEND="+str(len(rois))+"\n")
r = random.randrange(5,205,1)
g = random.randrange(10,210,1)
b = random.randrange(30,230,1)
fichiertemp.write("COLOR="+str(r)+";"+str(g)+";"+str(b)+"\n")
fichiertemp.close()
def getSelected(self) :
#selected=[self.__cells[i] for i in range(len(self.__cells)) if self.__boxes[i].isSelected()]
selected=[b.getText() for b in self.__boxes if b.isSelected()]
return selected
def setSelected(self, selected) :
for b in self.__boxes : b.setSelected(False)
#for s in selected : print str(s)
for c in self.__cells :
#print str(c)
if c in selected :
self.__dictBox[c][1].setSelected(True)
def resetok(self):
self.oked = False
def setLabel(self, text):
self.__label.setText(text)
示例5: range
# 需要导入模块: from ij.plugin.frame import RoiManager [as 别名]
# 或者: from ij.plugin.frame.RoiManager import addRoi [as 别名]
#sorted_roi_array=sorted(roi_array, key=methodcaller('getLength'), reverse=True)
#length_array=[]
#index=0
#for roi in roi_array:
# index=index+1
# length_array.append((index,roi.getLength()))
#sorted_length_array=sorted(length_array, key=itemgetter(0))
rm.runCommand("Select All")
rm.runCommand("Delete")
#for roi in roi_array:
interpolated_polygon=max_roi.getInterpolatedPolygon(20,True)
roi_polygon=PolygonRoi(interpolated_polygon,Roi.POLYGON)
rm.addRoi(roi_polygon)
#imp = IJ.getImage()
#roi = imp.getRoi()
#p = roi.getPolygon()
#peterimeter = roi.getLength()
#p.npoints
#rm.sort()
#rm.split();
#print rm
#for i in range(1,p.npoints):
# print "(" + str(p.xpoints[i]) + "," + str(p.ypoints[i]) + ")"
#IJ.run("Create Selection");
示例6: RoiManager
# 需要导入模块: from ij.plugin.frame import RoiManager [as 别名]
# 或者: from ij.plugin.frame.RoiManager import addRoi [as 别名]
from ij import IJ
from ij.gui import OvalRoi
from ij.plugin.frame import RoiManager
imp = IJ.getImage()
rm = RoiManager() # instantiate manager # throws exception if it doesn't exist
#rm = RoiManager.getInstance() # if manager exists
roi = OvalRoi(75, 75, 50, 50); # define and add ROI
imp.setRoi(roi) # make active on image
rm.addRoi(roi) # add
rm.select(0) # select the zeroth ROI and rename it
rm.runCommand("Rename", "roi");
示例7: procOneImage
# 需要导入模块: from ij.plugin.frame import RoiManager [as 别名]
# 或者: from ij.plugin.frame.RoiManager import addRoi [as 别名]
def procOneImage(pathpre, wnumber, endings):
""" Analyzes a single image set (Dapi, VSVG, PM images)
pathpre: fullpath prefix, down till "endings".
endings: a dictionary with signiture for three different channels.
wnumber: a number in string, indicating the spot ID.
Returns three results tables.
"""
imp = IJ.openImage(pathpre + endings['dapi'] + '.tif')
impVSVG = IJ.openImage(pathpre + endings['vsvg'] + '.tif')
impPM = IJ.openImage(pathpre + endings['pm'] + '.tif')
imp2 = imp.duplicate()
rtallcellPM = ResultsTable()
rtjnucVSVG = ResultsTable()
rtallcellVSVG = ResultsTable()
backVSVG = backgroundSubtraction(impVSVG)
backPM = backgroundSubtraction(impPM)
impfilteredNuc = nucleusSegmentation(imp2)
intmax = impfilteredNuc.getProcessor().getMax()
if intmax == 0:
return rtallcellPM, rtjnucVSVG, rtallcellVSVG
impfilteredNuc.getProcessor().setThreshold(1, intmax, ImageProcessor.NO_LUT_UPDATE)
nucroi = ThresholdToSelection().convert(impfilteredNuc.getProcessor())
nucroiA = ShapeRoi(nucroi).getRois()
#print nucroiA
allcellA = [roiEnlarger(r) for r in nucroiA]
jnucroiA = [roiRingGenerator(r) for r in nucroiA]
#print allcellA
print 'Detected Cells: ', len(jnucroiA)
if len(jnucroiA) <2:
print "measurement omitted, as there is only on nucleus detected"
return rtallcellPM, rtjnucVSVG, rtallcellVSVG
if (GUIMODE):
rm = RoiManager()
for r in jnucroiA:
rm.addRoi(r)
rm.show()
impfilteredNuc.show()
measOpt = PA.AREA + PA.MEAN + PA.CENTROID + PA.STD_DEV + PA.SHAPE_DESCRIPTORS + PA.INTEGRATED_DENSITY + PA.MIN_MAX +\
PA.SKEWNESS + PA.KURTOSIS + PA.MEDIAN + PA.MODE
## All Cell Plasma Membrane intensity
measureROIs(impPM, measOpt, rtallcellPM, allcellA, backPM, True)
meanInt_Cell = rtallcellPM.getColumn(rtallcellPM.getColumnIndex('Mean'))
print "Results Table rownumber:", len(meanInt_Cell)
# JuxtaNuclear VSVG intensity
measureROIs(impVSVG, measOpt, rtjnucVSVG, jnucroiA, backVSVG, False)
meanInt_jnuc = rtjnucVSVG.getColumn(rtjnucVSVG.getColumnIndex('Mean'))
# AllCell VSVG intensity
measureROIs(impVSVG, measOpt, rtallcellVSVG, allcellA, backVSVG, True)
meanInt_vsvgall = rtallcellVSVG.getColumn(rtallcellVSVG.getColumnIndex('Mean'))
#Calculation of Transport Ratio JuxtaNuclear VSVG intensity / All Cell Plasma Membrane intensity results will be appended to PM results table.
for i in range(len(meanInt_Cell)):
if meanInt_Cell[i] != 0.0:
transportR = meanInt_jnuc[i] / meanInt_Cell[i]
transportRall = meanInt_vsvgall[i] / meanInt_Cell[i]
else:
transportR = float('inf')
transportRall = float('inf')
rtjnucVSVG.setValue('TransportRatio', i, transportR)
rtallcellVSVG.setValue('TransportRatio', i, transportRall)
rtjnucVSVG.setValue('WellNumber', i, int(wnumber))
rtallcellVSVG.setValue('WellNumber', i, int(wnumber))
rtallcellPM.setValue('WellNumber', i, int(wnumber))
return rtallcellPM, rtjnucVSVG, rtallcellVSVG