Ejemplo n.º 1
0
			fileout = 	os.path.join(analyzeDir, os.path.basename(filepath))	
			IJ.saveAs(impOut, "Jpeg", fileout)

def createOutputImg(image, roim, centPart, metaphase):
	#maximal projection
	imp = image
	if image.getNSlices() > 1:
		zp = ZProjector()
		zp.setMethod(zp.MAX_METHOD)
		zp.setImage(image)
		zp.doProjection()
		imp = zp.getProjection()
	else:
		imp = image
	IJ.run(imp,"Enhance Contrast", "saturated=0.35")
	IJ.setForegroundColor(255,0,0)
	#need to show the image to draw overlay
	imp.show()
	IJ.run(imp,"RGB Color", "");
	for i in range(roim.getCount()):
		roim.select(imp, i)
		roim.runCommand("Draw")
	if metaphase:
		IJ.setForegroundColor(0,255,255)
	else:
		IJ.setForegroundColor(0,255,0)	
	roim.select(imp, centPart)
 def do_projection(self, channel, proj_type=None):
     proj = ZProjector()  ## create projection class
     if proj_type is None:
         if self.do_z[channel] == "MAX":
             proj.setMethod(ZProjector.MAX_METHOD)
         elif self.do_z[channel] == "AVG":
             proj.setMethod(ZProjector.AVG_METHOD)
         else:
             print "Dont know how to project this way"
             print "Just using a single slice for images!!"
             return None
     else:
         if proj_type == "MAX":
             proj.setMethod(ZProjector.MAX_METHOD)
         elif proj_type == "AVG":
             proj.setMethod(ZProjector.AVG_METHOD)
         else:
             print "Dont know how to project this way"
             print "Just using a single slice for images!!"
             return None
     proj.setImage(self.stack_imps[channel])
     proj.doProjection()
     projection = proj.getProjection()
     conv = ImageConverter(projection)
     conv.convertToGray16()
     conv.setDoScaling(False)
     self.projections[channel] = projection
     self.projections_done[channel] = self.do_z[channel]
def zproj(imp):
	zpimp = ZP()
	zpimp.setImage(imp)
	zpimp.setMethod(zpimp.MAX_METHOD)
	zpimp.setStartSlice(1)
	zpimp.setStopSlice(imp.getNSlices())
	zpimp.doHyperStackProjection(True)
	zpedimp = zpimp.getProjection()
	return zpedimp
Ejemplo n.º 4
0
    return runCamR, runCamL, CamRScale, CamLScale, BackgroundWindowStart, BackgroundWindowEnd, GridSize, TranslateR, TranslateL  # a tuple with the parameters


options = getOptions()
if options is not None:
    runCamR, runCamL, CamRScale, CamLScale, BackgroundWindowStart, BackgroundWindowEnd, GridSize, TranslateR, TranslateL = options  # unpack each parameter
    print runCamR, runCamL, CamRScale, CamLScale, BackgroundWindowStart, BackgroundWindowEnd, GridSize, TranslateR, TranslateL

if runCamR:
    impR1 = FolderOpener.open(folder, "file=CamR sort")
    UID = impR1.title
    filepath = folder.strip(UID + '/')

    projectR = ZProjector(impR1)
    projectR.setMethod(ZProjector.AVG_METHOD)
    projectR.setImage(impR1)
    projectR.setStartSlice(int(BackgroundWindowStart))
    projectR.setStopSlice(int(BackgroundWindowEnd))
    projectR.doProjection()
    projectionR = projectR.getProjection()

    impR2 = ImageCalculator().run("Subtract create stack", impR1, projectionR)
    IJ.run(impR2, "Enhance Contrast", "saturated=0.4 process_all")
    IJ.run(impR2, "Set Scale...",
           "distance=" + str(CamRScale) + " known=1 unit=cm")
    IJ.run(impR2, "Grid...",
           "grid=Lines area=" + str(GridSize) + " color=Cyan")
    IJ.run(impR2, "Translate...",
           "x=" + str(TranslateR) + " y=0 interpolation=None stack")

    savepath = path.join(folder, UID + "_CR.tif")
Ejemplo n.º 5
0
# the metadata. Stops otherwise.
# TODO : Should work fine for CZIs but could be
# improved with default values or min/max values.
emissionWL = [0]
try:
    for x in xrange(1,nbrChannels+1,1):
        WL = int(imp.getNumericProperty("Information|Image|Channel|EmissionWavelength #" + str(x).zfill(2)))
        emissionWL.append(WL)
except ValueError:
    raise Exception("Couldn't find the EmissionWavelength info in the metadata")

# Make the maximum intensity projection
# and show it for user input.
project = ZProjector()
project.setMethod(ZProjector.MAX_METHOD)
project.setImage(imp)
project.doProjection()
projection = project.getProjection()
projection.show()

# Wait for the user to draw a line
# and check if line ROI.
IJ.setTool("line");
myWait = WaitForUserDialog ("waitForUser", "Make a line with the region of interest and press OK")
myWait.show()

roi = projection.getRoi()

# Check if roi is a line
# otherwise exit
if not (roi.isLine()):
Ejemplo n.º 6
0
def imageprojector(channels, timelist_unsorted, dirs):
	""" Projects .lif timepoints and saves in a common directory,
	    as well as channel separated directories. """
	
	# Defines in path
	path = str(Experiment)

	# BF Importer
	options = ImporterOptions()
	
	try:
		options.setId(path)
	except Exception(e):
		print str(e)
		
	options.setOpenAllSeries(True)
	options.setSplitTimepoints(True)
	options.setSplitChannels(True)
	imps = BF.openImagePlus(options)

	timelist = [x for item in timelist_unsorted for x in repeat(item, channels)]
	timelist, imps = zip(*sorted(zip(timelist, imps)))

	
	counter_C0 = -1
	counter_C1 = -1
	counter_C2 = -1
	# Opens all images, splits channels, z-projects and saves to disk
	for imp in (imps):
		# Projection, Sum Intensity
   		project = ZProjector()
		project.setMethod(ZProjector.SUM_METHOD)
		project.setImage(imp)
		project.doProjection()
		impout = project.getProjection()
		projection = impout.getTitle()

		try:
			# Saves channels to disk, 
			# add more channels here if desired, 
			# remember to define new counters.
			if "C=0" in projection:
				counter_C0 += 1
				IJ.saveAs(impout, "TIFF", os.path.join(dirs["Projections"],
				          "Scan" + str(counter_C0).zfill(3) + "C0"))
                
				IJ.saveAs(impout, "TIFF", os.path.join(dirs["Projections_C0"],
				          "Scan" + str(counter_C0).zfill(3) + "C0"))		
			
			elif "C=1" in projection:
				counter_C1 += 1
				IJ.saveAs(impout, "TIFF", os.path.join(dirs["Projections"],
				          "Scan" + str(counter_C1).zfill(3) + "C1"))
                         
				IJ.saveAs(impout, "TIFF", os.path.join(dirs["Projections_C1"],
				          "Scan" + str(counter_C1).zfill(3) + "C1"))

			elif "C=2" in projection:
				counter_C2 += 1
				IJ.saveAs(impout, "TIFF", os.path.join(dirs["Projections"],
				          "Scan" + str(counter_C2).zfill(3) + "C2"))
                         
				IJ.saveAs(impout, "TIFF", os.path.join(dirs["Projections_C2"],
				          "Scan" + str(counter_C2).zfill(3) + "C2"))
		
		except IOException:
			print "Directory does not exist"
			raise

	IJ.log("Images projected and saved to disk")
Ejemplo n.º 7
0
def CheckMoment(image):
	
	#Perform a maximum projection on the stack	
	stack = image.getStack()
	NSlices=image.getNSlices()
	#Take a fixed number of central slices
	i=float(NSlices-SimulationCharacteristics['CentralZSlices']) 
	i1=math.floor(i/2)
	i2=math.ceil(i/2)	
	startSlice=int(1+i1)
	stopSlice=int(NSlices-i2)
	p=bool(1)
	proj = ZProjector()
	proj.setMethod(ZProjector.MAX_METHOD)
	proj.setImage(image)
	proj.setStartSlice(startSlice)
	proj.setStopSlice(stopSlice)
	proj.doHyperStackProjection(p)
	imageMax = proj.getProjection()
	imageMax.show()
	stack = imageMax.getStack()
	n_slices= stack.getSize()
	

	#Get a Segmentation Mask List for every frame in the stack
	RoiList=[]
	RoiRatioList=[]
	for index in range(1, n_slices+1):
		ip = stack.getProcessor(index).convertToFloat()
		boundRoi=SegmentMask(ip)
		mask=boundRoi.getMask()
		PixelsMask=mask.getPixels()
		r=(-1)*float(sum(PixelsMask))/(ip.height*ip.width)
		RoiList.append(boundRoi)
		RoiRatioList.append(r)
#	print(RoiRatioList)		

	#Optimize the Roi List. No 1.0 ratios 
	AllRois1=all(item == 1.0 for  item in RoiRatioList)
	NFrames=len(RoiRatioList)
	if not AllRois1:
		for i in range(NFrames):
			if RoiRatioList[i]==1.0 or RoiList[i]==None:
				#Find the next value that is not 1.0
				NearestNot1=-1 
				prevIndex=i-1
				nextIndex=i+1
				Token=True #To run through the list alternating positions
				while prevIndex>=0 or nextIndex<NFrames:
					if prevIndex>0 and Token:
						if RoiRatioList[prevIndex]<0.9999:
							NearestNot1=prevIndex
							break
						else: 
							prevIndex-=1
							if nextIndex<NFrames:Token=False
							continue
					if nextIndex<NFrames:
					  
						if RoiRatioList[nextIndex]<0.9999:
							NearestNot1=nextIndex
							break
						else:
							nextIndex+=1
							if prevIndex>0: Token=True
							continue
				
				if NearestNot1!=-1:
					#Change RoiList and RoiRationList for the NearestNot1 element
					RoiList[i]=RoiList[NearestNot1]
					RoiRatioList[i]=RoiRatioList[NearestNot1]
				else:
					AllRois1=True
					print("No avaliable segmentation")
	
	if not AllRois1:
		RoiListMin=ModifyRoiList(RoiRatioList,RoiList)
	else:
		RoiListMin=[ None for i in range(len(RoiList))]
	

	#Find Optimum Scale for the Wavelet
	Gamma=endosomeCharacteristics['Gamma_media']
	To=endosomeCharacteristics['A_media']
	index=1 #Image 1
	ipOrig = stack.getProcessor(index).convertToFloat()	
	boundRoi=RoiListMin[0]
	MaxAmp,Ropt=AmplificationCurveMax(ipOrig,To,Gamma,boundRoi)
	print("Choosen Scale",Ropt)
		
	Moment3Array=[]
	for index in range(1,n_slices+1):
		print("time:"+str(index))
		ip = stack.getProcessor(index).convertToFloat()
		boundRoi=RoiListMin[index-1]
		Skew=GetSigmaWavelet(ip,Ropt,boundRoi)
  		Moment3Array.append(Skew)
		

	return Moment3Array