def findclearcell(inDir, currentDir, fileName):
  print "Opening", fileName
  file_path= os.path.join(currentDir, fileName)
  options = ImporterOptions()
  options.setId(file_path)
  options.setSplitChannels(True)
  imps = BF.openImagePlus(options)
  for imp in imps:
  	imp.show()
  if not imps:
  	return
  IJ.selectWindow(fileName + " - C=2")
  IJ.run("Close")
  IJ.selectWindow(fileName + " - C=1")
  IJ.run("Close")
  IJ.selectWindow(fileName + " - C=0")
  IJ.run("Close")
  IJ.selectWindow(fileName + " - C=3")
  IJ.run("8-bit")
  IJ.run("Options...", "iterations=1 count=1 black edm=8-bit")
  IJ.setThreshold(62, 255)
  IJ.run("Convert to Mask", "method=Default backgorund=Dark black")
  Macro.setOptions("Stack position")
  for n in range(4,15):
	n+=1
	IJ.setSlice(n)
	IJ.run(imp, "Analyze Particles...", "size=7.2-9 circularity=0.7-0.95 display")
Exemplo n.º 2
0
def analyzeImage(passImage, passModel, passChannel, passProbability,
                 passPixels, passOutput):
    retResults = list()
    windows = set()

    # Register current window
    registerWindow(passImage.title, windows)

    # Extract the requested channel
    IJ.run("Z Project...", "projection=[Max Intensity]")
    registerWindow("MAX_" + passImage.title, windows)
    IJ.run("Duplicate...", "title=temp")
    registerWindow("temp", windows)

    # Apply WEKA training model to image
    wekaSeg = WekaSegmentation(WindowManager.getCurrentImage())
    wekaSeg.loadClassifier(passModel)
    wekaSeg.applyClassifier(True)

    # Extract first slice of probability map
    wekaImg = wekaSeg.getClassifiedImage()
    wekaImg.show()
    registerWindow("Probability maps", windows)
    IJ.setSlice(1)
    IJ.run("Duplicate...", "title=temp2")
    registerWindow("temp2", windows)

    # Apply threshold and save
    IJ.setThreshold(passProbability, 1, "Black & White")
    fileParts = passImage.getTitle().split(".")
    IJ.save(
        os.path.join(
            passOutput, "{0}-probmap.png".format(fileParts[0],
                                                 '.'.join(fileParts[1:]))))

    # Perform particle analysis and save
    IJ.run("Analyze Particles...",
           "size={0}-Infinity show=Outlines pixel clear".format(passPixels))
    registerWindow("Drawing of temp2", windows)
    IJ.save(
        os.path.join(
            passOutput, "{0}-particles.png".format(fileParts[0],
                                                   '.'.join(fileParts[1:]))))

    # Get measurements
    tableResults = ResultsTable.getResultsTable()
    for rowIdx in range(tableResults.size()):
        retResults.append(tableResults.getRowAsString(rowIdx).split())
        retResults[-1].insert(
            0,
            WindowManager.getCurrentImage().getCalibration().unit)
        retResults[-1].append(
            float(retResults[-1][4]) / float(retResults[-1][3]))

    # Close windows
    closeWindows(windows)

    return retResults
Exemplo n.º 3
0
def analyzeImage(passImage, passModel, passProbability, passPixels,
                 passOutput):
    retResults = list()

    # Apply WEKA training model to image
    wekaSeg = WekaSegmentation(passImage)
    wekaSeg.loadClassifier(passModel)
    wekaSeg.applyClassifier(True)

    # Extract first slice of probability map
    wekaImg = wekaSeg.getClassifiedImage()
    wekaImg.show()

    IJ.selectWindow("Probability maps")
    IJ.setSlice(1)
    IJ.run("Duplicate...", "title=temp")

    # Apply threshold and save
    IJ.setThreshold(passProbability, 1, "Black & White")
    fileParts = passImage.getTitle().split(".")
    IJ.save(
        os.path.join(
            passOutput, "{0}-probmap.png".format(fileParts[0],
                                                 '.'.join(fileParts[1:]))))

    # Perform particle analysis and save
    IJ.run("Analyze Particles...",
           "size={0}-Infinity show=Outlines pixel clear".format(passPixels))
    IJ.selectWindow("Drawing of temp")
    IJ.save(
        os.path.join(
            passOutput, "{0}-particles.png".format(fileParts[0],
                                                   '.'.join(fileParts[1:]))))

    # Get measurements (skip final row, this will correspond to legend)
    tableResults = ResultsTable.getResultsTable()
    for rowIdx in range(tableResults.size() - 1):
        retResults.append(tableResults.getRowAsString(rowIdx).split())

    # Close interim windows
    IJ.run("Close")
    IJ.selectWindow("temp")
    IJ.run("Close")
    IJ.selectWindow("Probability maps")
    IJ.run("Close")

    return retResults
Exemplo n.º 4
0
def mkMask(imp,prePick,numRep,nStacks):
	file_name = imp.getTitle()			
	IJ.selectWindow(file_name)
	IJ.setSlice(prePick)
	tempFileNames=[]
	for pp in range(0,numRep):
		tempFileNames.append('temp'+str(pp))
		IJ.run(imp,"Duplicate...", "title=" +tempFileNames[pp])
		IJ.run("8-bit", "")
	cont_imgs = " ".join('image%d=%s' %(c+1,w) for c,w in enumerate(tempFileNames))
	IJ.run("Concatenate...", "title=tempStack " +cont_imgs)
	tempStack = IJ.getImage()
	IJ.run(tempStack,"Make Montage...", "columns="+str(numRep/nStacks)+" rows="+str(nStacks)+" scale=1 first=1 last="+str(numRep)+" increment=1 border=1 font=12")
	m2_imp=IJ.getImage()
	m2_imp.setTitle("Mask")
	tempStack.close()
	return m2_imp
Exemplo n.º 5
0
def mkMask(imp,prePick,numRep,nStacks):
	file_name = imp.getTitle()			
	IJ.selectWindow(file_name)
	IJ.setSlice(prePick)
	tempFileNames=[]
	for pp in range(0,numRep):
		tempFileNames.append('temp'+str(pp))
		IJ.run(imp,"Duplicate...", "title=" +tempFileNames[pp])
		IJ.run("8-bit", "")
	cont_imgs = " ".join('image%d=%s' %(c+1,w) for c,w in enumerate(tempFileNames))
	IJ.run("Concatenate...", "title=tempStack " +cont_imgs)
	tempStack = IJ.getImage()
	IJ.run(tempStack,"Make Montage...", "columns="+str(numRep/nStacks)+" rows="+str(nStacks)+" scale=1 first=1 last="+str(numRep)+" increment=1 border=1 font=12")
	m2_imp=IJ.getImage()
	m2_imp.setTitle("Mask")
	tempStack.close()
	return m2_imp
Exemplo n.º 6
0
                  anno_width, anno_height, t_a + t_b + t_c)

# Add leading texts
labelTextAll(start=0, interval=1, x=10, y=40, fontsize=36,
             text='[Flow:L--->R]')

# Add timestamps for each segment
x_ts, y_ts, fs_ts = 325, 30, 36  # x, y, and font_size
labelTimestamps(start=0, interval=sample_rate,
                x=x_ts, y=y_ts, fontsize=fs_ts,
                range0=1, range1=t_a)
labelTimestamps(start=int(t0_b - t0_a), interval=sample_rate,
                x=x_ts, y=y_ts, fontsize=fs_ts,
                range0=(t_a + 1), range1=(t_a + t_b))
labelTimestamps(start=int(t0_c - t0_a), interval=sample_rate,
                x=x_ts, y=y_ts, fontsize=fs_ts,
                range0=(t_a + t_b + 1), range1=(t_a + t_b + t_c))

# Add scale bar
labelTextAll(start=0, interval=1, x=700, y=20, fontsize=36,
             text=(str(sbar_um) + um))
IJ.setBackgroundColor(255, 255, 255)
for i in range(1, t_a + t_b + t_c + 1):
    IJ.setSlice(i)
    IJ.makeRectangle(anno_width - 120 - sbar_px, 14, sbar_px, 16)
    IJ.run('Cut')

# Save annotation banner
path = SaveDialog(title, title, '.tif').getDirectory()
IJ.run('Save', 'save=[' + path + title + ']')
def analyzeImage(passImage, passModel, passProbability, passOutput):
    retResults = list()

    # Apply weka training model to image
    wekaSeg = WekaSegmentation(passImage)
    wekaSeg.loadClassifier(passModel)
    wekaSeg.applyClassifier(True)

    # Extract probability map
    wekaImg = wekaSeg.getClassifiedImage()
    wekaImg.show()
    IJ.run("Clear Results")

    # Process each slice
    for sliceIdx in range(ROW_BACKGROUND + 1):
        # Select slice and duplicate
        IJ.selectWindow("Probability maps")
        IJ.setSlice(sliceIdx + 1)
        IJ.run("Duplicate...", "title=temp")

        # Apply threshold to probability
        IJ.setThreshold(passProbability, 1, "Black & White")

        # For background, take inverse
        if sliceIdx == ROW_BACKGROUND: IJ.run("Invert")

        # Change background to NaN for area, then measure
        IJ.run("NaN Background", ".")
        IJ.run("Measure")

        # Save image to output directory
        fileParts = passImage.getTitle().split(".")
        IJ.save(
            os.path.join(
                passOutput,
                "{0}-{1}.{2}".format(fileParts[0], FILE_TYPE[sliceIdx],
                                     '.'.join(fileParts[1:]))))

        IJ.selectWindow("temp")
        IJ.run("Close")

    # Close probability maps
    IJ.selectWindow("Probability maps")
    IJ.run("Close")

    # Obtain results
    tempResults = list()
    tableResults = ResultsTable.getResultsTable()
    for rowIdx in range(tableResults.size()):
        tempResults.append(
            [float(x) for x in tableResults.getRowAsString(rowIdx).split()])

    # Compile image statistics as M/(M+F), F/(M+F), M/total, F/total, U/total, E/total, M+F, total
    mfTotal = tempResults[ROW_MALE][FIELD_AREA] + tempResults[ROW_FEMALE][
        FIELD_AREA]
    total = tempResults[ROW_BACKGROUND][FIELD_AREA]

    retResults.append(tempResults[ROW_MALE][FIELD_AREA] / mfTotal)
    retResults.append(tempResults[ROW_FEMALE][FIELD_AREA] / mfTotal)
    retResults.append(tempResults[ROW_MALE][FIELD_AREA] / total)
    retResults.append(tempResults[ROW_FEMALE][FIELD_AREA] / total)
    retResults.append(tempResults[ROW_UNDIF][FIELD_AREA] / total)
    retResults.append(tempResults[ROW_EXTRA][FIELD_AREA] / total)
    retResults.append(mfTotal)
    retResults.append(total)

    return retResults
Exemplo n.º 8
0
def setSlice(index):
    IJ.setSlice(index)
Exemplo n.º 9
0
IJ.run("Set Measurements...",
       "area integrated display redirect=None decimal=3")
IJ.run("Clear Results")
IJ.run("Split Channels")
myelin = "C" + str(myelinCH) + "-" + title
points = "C" + str(pointsCH) + "-" + title
rt = ResultsTable.getResultsTable(
)  #This object allows us to change the labels in the results table

#Threshold the myelin stack
IJ.selectWindow(myelin)
IJ.run("8-bit")

if interactive == 1:
    for plane in range(1, n_slices + 1):
        IJ.setSlice(plane)
        message = wait(
            "Threshold",
            "Click OK when you have finished selecting a threshold for plane %s"
            % plane)
        message.show()
        IJ.run("Convert to Mask", "method=Default background=Dark only")
    IJ.run("Invert", "stack")
else:
    IJ.run("Convert to Mask", "method=Default background=Dark calculate")

IJ.run("Median...", "radius=%s stack" % median)
IJ.run("Fill Holes", "stack")
IJ.run("Close-", "stack")
for i in range(iterations):
    IJ.run("Dilate", "stack")
Exemplo n.º 10
0
#print r1.getFloatPolygon().xpoints[0]  #get xpoint
#first convert our ROIs to something more useful, a tuple containing the point (x,y) and the Z position => (x,y,z)
for i in range(0, nRois-1):
	roi1 = rm.getRoi(i)
	roi2 = rm.getRoi(i+1)
	pt1 = (roi1.getFloatPolygon().xpoints[0],roi1.getFloatPolygon().ypoints[0],roi1.getPosition())
	pt2 = (roi2.getFloatPolygon().xpoints[0],roi2.getFloatPolygon().ypoints[0],roi2.getPosition())
	startSlice = pt1[2]
	endSlice = pt2[2]
	nSlices = (endSlice - startSlice)
	xcorrect = (pt1[0]-pt2[0]);
   	ycorrect = (pt1[1]-pt2[1]);
   	print "Point pair: "
   	print pt1
   	print pt2
   	IJ.setSlice(pt1[2]) #set starting slice
	driftx = xcorrect/nSlices; 
	offsetx = 0;
	print "startSlice: %s ;endSlice: %s" % (startSlice, endSlice)
	print "nSlices: %s" % (nSlices,)
	for j in range(startSlice, totSlices+1): 
		IJ.setSlice(j)
		if j <= endSlice:
			offsetx += driftx
		IJ.run("Translate...", "interpolation=Bicubic slice y=0 x="+str(offsetx)); 

	drifty = ycorrect/nSlices; 
	offsety = 0; 
	for k in range(startSlice, totSlices+1):
		IJ.setSlice(k)
		if k <= endSlice:
def to_golgi_channel():
    if golgi_c != "-":
        IJ.setSlice(int(golgi_c))
    else:
        pass
def to_transport_channel():
    if transport_c != "-":
        IJ.setSlice(int(transport_c))
    else:
        pass
    imp = IJ.getImage()
    image_name = imp.title
    bit_depth = bit_tester(image_name)
    colorscale()

    #set a manual background value#
    if man_bck_det is True:
        if current_image != image_name:
            IJ.setTool("oval")
            region = "Select Background"
            selection(region)
            to_transport_channel()
            man_bck_list=[]
            for channel in channel_iterator:
            	channel_first = int(channel)
            	IJ.setSlice(channel_first)
            	man_bck_list.append(selection_mean())
           	background = man_bck_list[0]
           	to_transport_channel()

    if mean_max_det is True:
        IJ.setTool("polygon")
    else:
        IJ.setTool("rectangle")
    count_options = 0
    if count_options == 1:  # asks if we are looking at a new image
        getOptions(dest)

    region = "select cell"
    selection(region)
    IJ.run("Duplicate...", "duplicate")
num_tracks = track_model.nTracks(true)
trackID = track_model.trackIDs(true).toArray()
track_position_list = []

if num_tracks > 1:
    warning_blurb = 'WARNING: Multiple tracks passing thresholds were found in image C1_'
    warning_fileID.write(warning_blurb + image_stack + "\n")

if num_tracks == 0:
    warning_blurb = 'WARNING: No tracks passing thresholds were found in image C1_'
    warning_fileID.write(warning_blurb + image_stack + "\n")

IJ.selectWindow(file_name)
IJ.run('Z Project...', 'projection=[Max Intensity] all')
IJ.run('Duplicate...', 'duplicate frames=1')
IJ.setSlice(1)
IJ.run('Enhance Contrast', 'saturated=0.05')
IJ.setSlice(2)
IJ.run('Enhance Contrast', 'saturated=0.05')
IJ.run('RGB Color')
imp_max = IJ.getImage()
save_filename = image_directory + 'Track_Labels/' + file_name + '/Max_' + file_name
IJ.save(save_filename)

if len(trackID) > 0:
    for i in trackID:
        ## Initialize variables
        track_max_frame = 0
        min_frame = max_frames
        vis_track = i
        track_spots = track_model.trackSpots(