Ejemplo n.º 1
0
	def __mainsettings(self) :
		
		
		# options : 
		#We ask if the user wants to import cells from .cell files
		# we track the cells in a stack that the user has to choose.
		
		def outputpath(event) : 
			self.__pathdir=IJ.getDirectory("image")
			self.__pathdir=IJ.getDirectory("")
			self.__text.setText(self.__pathdir)
			

		panel0=Panel()
		pathbutton=Button("Select output path", actionPerformed = outputpath)
		#pathbutton.actionPerformed = outputpath
		self.__text = TextField(self.__pathdir)
		panel0.add(pathbutton)
		panel0.add(self.__text)

		firstgd=NonBlockingGenericDialog("First choices")
		firstgd.addMessage("------------------  WELCOME  ----------------------")
		firstgd.addMessage("")
		firstgd.addMessage("Please fill the following options")
		firstgd.addMessage("")
		choices=["Already opened images", "Files from hard disk"]
		firstgd.addChoice("Images source : ", choices, choices[0])				# 1 choice
		firstgd.addCheckbox("Run in batch mode ?", False)					# 2 batch 
		firstgd.addMessage("")
		firstgd.addCheckbox("Import a set of cells from hardisk ?", self.__optionImport) 	# 3 import
		firstgd.addMessage("")
		firstgd.addNumericField("Size factor (binning)", 2, 0)					# 4 number
		firstgd.addPanel(panel0)
		firstgd.showDialog()

		
		#self.__optionImages=firstgd.getNextBoolean()
		choice=firstgd.getNextChoiceIndex()							# 1 choice
		self.__batch = firstgd.getNextBoolean()							# 2 batch
		self.__optionImport=firstgd.getNextBoolean()						# 3 import
		self.__binning = firstgd.getNextNumber()						# 4 number
		if choice==0 : self.__optionImages=True
		else : self.__optionImages=False 

		if firstgd.wasCanceled() : return False

		

		#IJ.showMessage("Select a working directory to save results")
		#self.__pathdir=IJ.getDirectory("image")
		#self.__pathdir=IJ.getDirectory("")

		#self.__pathdir=self.__pathdir+imp.getShortTitle()+os.path.sep+time.strftime('%d-%m-%y_%Hh%Mm%Ss',time.localtime())+os.path.sep

		if self.__pathdir is not None : return True
		else : return False
	
	## Opens the options dialog box
	gd = NonBlockingGenericDialog("Select channel...")
	gd.addChoice("Analysis_channel",["Channel "+str(i) for i in range(1,nChannels+1)],"Channel 1")
	gd.addChoice("Bleeding_channel",["Channel "+str(i) for i in range(nChannels+1)],"Channel 0")
	gd.addChoice("Refractive_reference_channel",["Channel "+str(i) for i in range(nChannels+1)],"Channel 0")
	gd.addNumericField("Intensity_threshold",128,0)
	gd.addNumericField("Size_threshold",100,0)
	gd.addChoice("Process_filter",["None","Min","Median"],"None")
	gd.addCheckbox("Operate_on_tile_subset",False)
	gd.addStringField("Which_tile_subset","1-4,9,11",12)
	gd.showDialog()

	## Parses the information from the dialog box
	if (gd.wasOKed()):
		analysisChannel = gd.getNextChoiceIndex()+1
		bleedingChannel = gd.getNextChoiceIndex()
		refChannel = gd.getNextChoiceIndex()
		intThreshold = gd.getNextNumber()
		sizeThreshold = gd.getNextNumber()
		processFilter = gd.getNextChoiceIndex()
		doSubset = gd.getNextBoolean()
		whichTiles = gd.getNextString()
		tileList = []
		parsingFailed = False
		if doSubset:
			try: 
				whichTilesDespaced = whichTiles.replace(" ","")
				tilesListed = whichTilesDespaced.split(",")
				for tile in tilesListed:
					tilesExpanded = tile.split("-")
			calib = calibImage.getCalibration()
			calibImage.close()
			activeImage.updateAndRepaintWindow()
		else:
			calib = activeImage.getCalibration()
		
		## Runs interface that allows to correct for bleedthrough and refraction
		if activeImage is not None:
			gd = NonBlockingGenericDialog("Select channel to operate on...")
			gd.addChoice("Select_channel:",["Channel "+str(i) for i in range(1,activeImage.getNChannels()+1)],"Channel 1")
			gd.addChoice("Bleeding_channel:",["None"] + ["Channel "+str(i) for i in range(1,activeImage.getNChannels()+1)],"None")
			gd.addChoice("Refraction_reference_channel:",["None"] + ["Channel "+str(i) for i in range(1,activeImage.getNChannels()+1)],"None")
			gd.showDialog()
			if (gd.wasOKed()):
				channelImages = ChannelSplitter.split(activeImage)
				channel = gd.getNextChoiceIndex()+1
				bleedingC = gd.getNextChoiceIndex()
				refractRefC = gd.getNextChoiceIndex()
				if (bleedingC > 0):
					params = ("bleeding_channel=" + str(bleedingC) + " bloodied_channel=" + str(channel) + " " +
							"allowable_saturation_percent=1.0 rsquare_threshold=0.50")
					IJ.run("Remove Bleedthrough (automatic)", params)
					dataImage = WindowManager.getImage("Corrected_ch" + str(channel))
					if (refractRefC > 0):
						refractCImage = channelImages[refractRefC-1].duplicate()
						refractCImage.show()
						IJ.run("Merge Channels...", "c1=" + dataImage.getTitle() + " c2=" + refractCImage.getTitle() + " create ignore")
						mergedImage = WindowManager.getImage("Composite")
						params = ("reference_channel=2 application_channel=1 automatic_operation generate_log " +
								"max_slice=43 surface_slice=87")
						IJ.run(mergedImage,"Refractive Signal Loss Correction",params)
from ij.gui import WaitForUserDialog
from ij.plugin import ChannelSplitter
from ij.plugin import ImageCalculator
from ij.measure import ResultsTable
from ij.measure import Measurements
from ij.plugin.filter import Analyzer

## Main body of script
theImage = IJ.getImage()
gd = NonBlockingGenericDialog("Pick parameters...")
gd.addChoice("Analysis_channel",["Channel "+str(i+1) for i in range(theImage.getNChannels())],"Channel 1")
gd.addNumericField("Pick_threshold",50,0)
gd.addCheckbox("Apply_min",True)
gd.showDialog()
if (gd.wasOKed()):
	analysisChannel = gd.getNextChoiceIndex() + 1
	intensityThreshold = gd.getNextNumber()
	doMin = gd.getNextBoolean() 
	splitImage = ChannelSplitter.split(theImage)
	dataImage = splitImage[analysisChannel-1].duplicate()
	if doMin:
		IJ.run(dataImage,"Minimum...", "radius=2 stack")
	goRun = True
	rt = ResultsTable()
	while goRun:
		wfud = WaitForUserDialog("Pick freehand ROI, then hit OK to analyze")
		wfud.show()
		roi = theImage.getRoi()
		if roi is None:
			goRun = False
		else: