def outputpath(event) : 
			macrodir=IJ.getDirectory("macros")
			frame = Frame("Select the macro file")
			fd = FileDialog(frame)
			fd.setDirectory(macrodir)
			fd.show()
			macrodir = fd.getDirectory() 
			self.__macropath = fd.getFile()
			self.__text.setText(self.__macropath)
			print self.__macropath
	def __ImportPref(self, flag) :
		indiceinterest=5
		
		if len(self.__params) < 1 :
			if flag == 1 :
				IJ.showMessage("Select the text file containing the preferences you want (Track.txt file)")
				self.__selectdir=IJ.getDirectory("image")
				frame = Frame("Text file settings ?")
				fd = FileDialog(frame)
				fd.setDirectory(self.__selectdir)
				fd.show()
				self.__selectdir = fd.getDirectory() 
				self.__textfile = fd.getFile()
				#self.__selectdir=IJ.getDirectory("")
				#listfiles=glob.glob(selectdir+"*DIA_s0001*.tif")
			#fichier = open(self.__selectdir+"Track.txt","r")

			fichier = open(self.__selectdir+self.__textfile,"r")
			lignes=fichier.readlines()
			self.__params=[]
			for i in range(indiceinterest,len(lignes)):						# ATTENTION À CHANGER AVEC PARAM DE RANGEROI
				params=lignes[i].split("=")
				val=params[1].split("\n")
				if params[0]=="SUBBACK" : self.__subback=bool(int(val[0]))
				if params[0]=="SUBBACKRADIUS" : self.__radius=Double(val[0])
				if params[0]=="DISTPARAM_AREA_COEFF" : self.__distparam[0]=int(val[0])
				if params[0]=="DISTPARAM_AREA_MAXDELTA" : self.__distparam[1]=Double(val[0])
				if params[0]=="DISTPARAM_ANGLE_COEFF" : self.__distparam[2]=int(val[0])
				if params[0]=="DISTPARAM_ANGLE_MAXDELTA" : self.__distparam[3]=Double(val[0])
				if params[0]=="DISTPARAM_FERETMAX_COEFF" : self.__distparam[4]=int(val[0])
				if params[0]=="DISTPARAM_FERETMAX_MAXDELTA" : self.__distparam[5]=Double(val[0])
				if params[0]=="DISTPARAM_POSITIONX_COEFF" : self.__distparam[6]=int(val[0])
				if params[0]=="DISTPARAM_POSITIONX_MAXDELTA" : self.__distparam[7]=int(val[0])
				if params[0]=="DISTPARAM_POSITIONY_COEFF" : self.__distparam[8]=int(val[0])
				if params[0]=="DISTPARAM_POSITIONY_MAXDELTA" : self.__distparam[9]=int(val[0])
				if params[0]=="DISTMETHOD" : self.__distmethod=str(val[0])
				if params[0]=="OPTIONMANTHRESH" : self.__manthresh=bool(int(val[0]))
				if params[0]=="THRESHMETHOD" : self.__thresMethod=str(val[0])
				if params[0]=="OPTIONANGLE" : self.__optionAngle=bool(int(val[0]))
				if params[0]=="OPTIONNEWCELLS" : self.__optionNewCells=bool(int(val[0]))
				if params[0]=="OPTIONTIMELAPSE" : self.__optionTimelapse=bool(int(val[0]))
				if params[0]=="TIMELAPSE" : self.__timelapse=int(val[0])

				# imported booleans : self.__subback, self.__manthresh, self.__optionAngle, self.__optionNewCells, self.__optionTimelapse
		
				minmax=val[0].split(";")
				if params[0]=="Area" : self.__params.append(("Area",Double(minmax[0]),Double(minmax[1])))
				if params[0]=="Mean" : self.__params.append(("Mean",Double(minmax[0]),Double(minmax[1])))
				if params[0]=="Angle" : self.__params.append(("Angle",Double(minmax[0]),Double(minmax[1])))
				if params[0]=="Major" : self.__params.append(("Major",Double(minmax[0]),Double(minmax[1])))
				if params[0]=="Minor" : self.__params.append(("Minor",Double(minmax[0]),Double(minmax[1])))
				if params[0]=="Solidity" : self.__params.append(("Solidity",Double(minmax[0]),Double(minmax[1])))
				if params[0]=="AR" : self.__params.append(("AR",Double(minmax[0]),Double(minmax[1])))
				if params[0]=="Round" : self.__params.append(("Round",Double(minmax[0]),Double(minmax[1])))
				if params[0]=="Circ" : self.__params.append(("Circ",Double(minmax[0]),Double(minmax[1])))
from ij import IJ
from ij.plugin.frame import RoiManager
from ij.gui import PolygonRoi
from ij.gui import Roi
from java.awt import FileDialog

fd = FileDialog(IJ.getInstance(), "Open", FileDialog.LOAD)
fd.show()
file_name = fd.getDirectory() + fd.getFile()
print(file_name)

RM = RoiManager()
rm = RM.getRoiManager()

imp = IJ.getImage()

textfile = open(file_name, 'r')
for line in textfile:
    xy = map(int, line.rstrip().split(','))
    X = xy[::2]
    Y = xy[1::2]
    imp.setRoi(PolygonRoi(X, Y, Roi.POLYGON))
    #IJ.run(imp, "Convex Hull", "")
    roi = imp.getRoi()
    print roi
    rm.addRoi(roi)

rm.runCommand("Associate", "true")
rm.runCommand("Show All with labels")
	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
Exemple #5
0
                homeDir = os.environ.get("HOMEPATH")
    except:
        pass

    if not homeDir: homeDir = "?"
    return homeDir


if i_want_popups or fileToImport is None or fileToImport == "":
    if Platform.isOSX():
        System.setProperty(
            "com.apple.macos.use-file-dialog-packages", "true"
        )  # In theory prevents access to app file structure (but doesnt seem to work)
        System.setProperty("apple.awt.fileDialogForDirectories", "false")

    fDialog = FileDialog(None, "Select file for import")
    fDialog.setMultipleMode(False)
    fDialog.setMode(FileDialog.LOAD)
    if fileToImport is None:
        fDialog.setFile("select_your_file")
        fDialog.setDirectory(get_home_dir())
    else:
        fDialog.setFile(fileToImport)
    fDialog.setVisible(True)

    if (fDialog.getFile() is None) or fDialog.getFile() == "":
        raise Exception(
            "User chose to cancel or no file selected >>  So no Import will be performed... "
        )

    fileToImport = os.path.join(fDialog.getDirectory(), fDialog.getFile())