コード例 #1
0
ファイル: BacteriaCell.py プロジェクト: leec13/MorphoBactPy
	def makeCell(cellfile) :

		filetemp = open(cellfile,"r")
		linestemp=filetemp.readlines()
		for line in linestemp :
			params=line.split("=")
			values=params[1].split("\n")
			if params[0] == "NAMECELL" :
				celltemp=Bacteria_Cell(str(values[0]))
			if params[0] == "PATHROIS" :
				pathtemp = str(values[0])
			if params[0] == "NSLICES" : 
				for i in range(int(values[0])) :
					celltemp.getListRoi().append("")
			if params[0] == "SLICEINIT" :
				celltemp.setSlideInit(int(values[0]))
				#for i in range(int(values[0])-2) :
				#	celltemp.setRoi("NOT HERE YET",i)
			if params[0] == "SLICEEND" :
				celltemp.setSlideEnd(int(values[0]))
				#for i in range(int(values[0])) :
				#	celltemp.setRoi("LOST",i)
				
			if params[0] == "COLOR" :
				colorstemp=values[0].split(";")
				celltemp.setColor(Color(int(colorstemp[0]),int(colorstemp[1]),int(colorstemp[2])))

		rm = RoiManager.getInstance()
		if (rm==None): rm = RoiManager()
		rm.runCommand("reset")
		rm.runCommand("Open", pathtemp)
		rois=rm.getSelectedRoisAsArray()
		celltemp.setlistRois(rois)
		rm.runCommand("UseNames", "true")
		rm.runCommand("Associate", "true")

		return celltemp
コード例 #2
0
ファイル: MeasuresCells_.py プロジェクト: leec13/MorphoBactPy
	def __ImportCells(self, imagesnames) :

		#self.__dictCells[imgName]={}
		
		rm = RoiManager.getInstance()
		if (rm==None): rm = RoiManager()
		rm.runCommand("reset")

		listpaths = []
		listfilescells=[]

		if self.__optionImages :
			IJ.showMessage("Select the folder 'Cells' containing the cells to import")
			selectdir=IJ.getDirectory("image")
			selectdir=IJ.getDirectory("")
			listfilescells.extend(glob.glob(selectdir+os.path.sep+"*"))
			listpaths.append("")

		else : 
			IJ.showMessage("Select the text file containing the list cell paths (listpaths.txt)")
			selectdir=IJ.getDirectory("current")
			frame = Frame("Text file settings ?")
			fd = FileDialog(frame)
			fd.setDirectory(selectdir)
			fd.show()
			selectdir = fd.getDirectory() 
			textfile = fd.getFile()
			fichier = open(selectdir+textfile,"r")
			listpaths=[ glob.glob(f.split("\n")[0]+"Selected-Cells"+os.path.sep+"*") for f in fichier.readlines()]

			#for f in templist : 
			#	listpaths.append(f.split("\n")+"Cells")
				
			listfilescells.append("")

		if listfilescells[0]=="" : importmode = True
		else : importmode = False
		
		for j in range(len(listpaths)) :
			self.__dictCells[imagesnames[j]]={}
			if importmode : listfilescells = listpaths[j]
			pathtemp = []
			for cellfile in listfilescells :
				filetemp = open(cellfile,"r")
				linestemp=filetemp.readlines()
				for line in linestemp :
					params=line.split("=")
					values=params[1].split("\n")
					if params[0] == "NAMECELL" :
						celltemp=Bacteria_Cell(str(values[0]))
						self.__dictCells[imagesnames[j]][values[0]]=celltemp
						self.__dictMeasures[self.__dictCells[imagesnames[j]][values[0]]]={} 


					if params[0] == "PATHROIS" :
						pathtemp.append(str(values[0]))
						
					if params[0] == "NSLICES" : 
						for i in range(int(values[0])) :
							celltemp.getListRoi().append("")
				
					if params[0] == "SLICEINIT" :
						celltemp.setSlideInit(int(values[0]))
						for i in range(int(values[0])-2) :
							celltemp.setRoi("NOT HERE YET",i)
				
					if params[0] == "SLICEEND" :
						celltemp.setSlideEnd(int(values[0]))
						for i in range(int(values[0])) :
							celltemp.setRoi("LOST",i)
				
					if params[0] == "COLOR" :
						colorstemp=values[0].split(";")
						celltemp.setColor(Color(int(colorstemp[0]),int(colorstemp[1]),int(colorstemp[2])))
		
		
			indiceroi=0
			ind=0
			tempimp = WindowManager.getImage(imagesnames[j])
			if tempimp is not None : 
				IJ.selectWindow(imagesnames[j])
				tempimp.show()
			else : 
				if imagesnames[j][-4:]==".tif" : 
					IJ.selectWindow(imagesnames[j][:-4])
					tempimp = IJ.getImage()
				else : 
					IJ.selectWindow(imagesnames[j]+".tif")
					tempimp = IJ.getImage()
					
			rm.runCommand("reset")
			
			for cellname in self.__dictCells[imagesnames[j]].keys() :
				rm.runCommand("Open", pathtemp[ind])
				ind+=1
				nbtemp=self.__dictCells[imagesnames[j]][cellname].getLifeTime()
				for i in range(nbtemp) :
					rm.select(tempimp, indiceroi)
					roi=rm.getSelectedRoisAsArray()[0]
					self.__dictCells[imagesnames[j]][cellname].setRoi(roi,i+self.__dictCells[imagesnames[j]][cellname].getSlideInit()-1)
					indiceroi+=1

			IJ.run("Show Overlay", "")
			rm.runCommand("UseNames", "true")
			rm.runCommand("Associate", "true")
			IJ.run(tempimp, "Labels...", "color=red font=12 show use")
			if rm.getCount()>0 : IJ.run(tempimp, "From ROI Manager", "")
			rm.runCommand("Show None")
			rm.runCommand("Show All")

			roipath = os.path.split(pathtemp[0])[0]+os.path.sep
			rootpath = roipath.rsplit(os.path.sep, 2)[0]+os.path.sep

			self.__listpaths[j] = rootpath
			self.__rootpath=rootpath