Exemplo n.º 1
0
    def opencsv(self, name):
        # Return if the csv object was not set.
        # if self.trackscsv == None: return None TODO: some errorchecking for false csv input.

        # Open the csv file and return it as ResultsTable object.
        try:
            csv = IJ.getFilePath("Choose the {} file".format(name))

            if csv.endswith(".csv"):
                rt = ResultsTable.open(csv)
            else:
                IJ.log("{} was not a .csv file".format(csv))
                raise ValueError

            columns = rt.getHeadings()
            table = [{column: rt.getValue(column, row)
                      for column in columns} for row in range(rt.size())]

            if rt.columnExists("Label"):
                for i in range(len(table)):
                    table[i]["Label"] = rt.getStringValue("Label", i)

            IJ.log("Read {} rows in {}.".format(len(table), name))
            return table

        except Exception as ex:
            IJ.log("Something in opencsv() went wrong: {}".format(
                type(ex).__name__, ex.args))
Exemplo n.º 2
0
def opencsv():
    """Simply imports .csv file in ImageJ.

    Ask the user for the location of a .csv file.

    Returns:
        A ResultsTable object from the input file.
    """

    csv = IJ.getFilePath("Choose a .csv file")

    # Open the csv file and return it as ResultsTable object.
    try:
        if csv.endswith(".csv"):
            res = ResultsTable.open(csv)
            return res
        else:
            raise TypeError()
    except TypeError:
        IJ.log("The chosen file was not a .csv file.")
    except Exception as ex:
        IJ.log("Something in opencsv() went wrong: {}".format(type(ex).__name__, ex.args))
Exemplo n.º 3
0
    # Process list of images
    for (counter, f) in enumerate(files):

        # Display progress
        IJ.showStatus("Processing file "+ str(counter+1) +"/"+ str(len(files)))

        # Open each image and process it
        imp = IJ.openImage(f)
        myRoutines(imp)

        # Save processed image in out_dir (enforcing .tif extension)
        newpath = os.path.splitext(out_dir + imp.getTitle())[0] +".tif"
        IJ.saveAsTiff(imp, newpath)
        imp.close()

        # Log paths of processed files
        csvWriter.writerow([f, newpath])

    # Display CSV log
    csvFile.close()
    rt = ResultsTable.open(csvPath)
    rt.show("_ProcessedFileList.csv")

    # Proudly inform that processing terminated
    if IJ.showMessageWithCancel("All done","Reveal output directory?"):
        Utils.revealFile(out_dir);

else:
    # Inform no filtered files were found
    IJ.error("No matches for the selected extension(s).")
Exemplo n.º 4
0
# IJ BAR: https://github.com/tferr/Scripts#scripts
#
# Imports numeric values copied to the clipboard into the Results table. It is
# now deprecated. It was of utility prior to BAR v1.1.7, when BARs that analyzed
# tabular data could only read values from the main IJ "Results" table. It is
# included here as a programming example.
#
# Requirements: Requires BAR_-XX.jar to be installed in the plugins folder of IJ
#
# NB: When copying data from withing IJ (e.g., lists from histograms or plot profiles),
# Use Edit>Options>Input/Output... to specify if column headers/row numbers should be
# copied to the clipboard

import os, tempfile
from bar import Utils as barUtils
from ij import IJ
from ij.plugin.filter import Analyzer
import ij.measure.ResultsTable as RT

fd, path = tempfile.mkstemp()
try:
    os.write(fd, barUtils.getClipboardText())
    os.close(fd)
    rt = RT.open(path)  #IOException if getClipboardText()==""
    if Analyzer.resetCounter():
        rt.show("Results")
except:
    IJ.showMessage("Could not place clipboard into Results table.")
finally:
    os.remove(path)
Exemplo n.º 5
0
# IJ BAR: https://github.com/tferr/Scripts#scripts
#
# Imports numeric values copied to the clipboard into the Results table. Useful, since
# BARs that analyze tabular data can only read values from the main IJ "Results" table
#
# Requirements: Requires BAR_-XX.jar to be installed in the plugins folder of IJ
#
# NB: When copying data from withing IJ (e.g., lists from histograms or plot profiles),
# Use Edit>Options>Input/Output... to specify if column headers/row numbers should be
# copied to the clipboard


import os, sys, tempfile
from bar import Utils as barUtils
from ij import IJ
from ij.plugin.filter import Analyzer
import ij.measure.ResultsTable as RT


fd, path = tempfile.mkstemp()
try:
    os.write(fd, barUtils.getClipboardText())
    os.close(fd)
    rt = RT.open(path) #IOException if getClipboardText()==""
    if Analyzer.resetCounter():
        rt.show("Results")
except:
    IJ.error("Could not place clipboard into Results table.")
finally:
    os.remove(path)
Exemplo n.º 6
0
	image_two = HyperStackConverter.toHyperStack(image,2,z_slices,1)
	image = CompositeImage(image_two)
	image.show()
	
	rt = run_comdet(image)
	rt.save(directory+"/"+filename+"_results.csv" )
	
	image = IJ.getImage()
	if auto_cell:
		
		mask = generate_mask(image_green, auto_cell_thresh)
		fs = FileSaver(mask)
		filepath = directory + "/" + filename + "_mask.tiff" 
		
		fs.saveAsTiff(filepath) 
		rest = ResultsTable.open(directory+"/"+filename+"_results.csv")
		
		#print(rest.getColumnHeadings())
		remove_outside_cell(rest,mask)
		rest.save(directory+"/"+filename+"_results.csv" )
	else:
		rest = rt

	
	
	
	
	
	
	image.setDimensions(2, z_slices, 1)
	image.setOpenAsHyperStack(True)
Exemplo n.º 7
0
    image_two = HyperStackConverter.toHyperStack(image, 2, z_slices, 1)
    image = CompositeImage(image_two)
    image.show()

    rt = run_comdet(image)
    rt.save(directory + "/" + filename + "_results.csv")

    image = IJ.getImage()
    if auto_cell:

        mask = generate_mask(image_green, auto_cell_thresh)
        fs = FileSaver(mask)
        filepath = directory + "/" + filename + "_mask.tiff"

        fs.saveAsTiff(filepath)
        rest = ResultsTable.open(directory + "/" + filename + "_results.csv")

        #print(rest.getColumnHeadings())
        remove_outside_cell(rest, mask)
        rest.save(directory + "/" + filename + "_results.csv")
    else:
        rest = rt

    image.setDimensions(2, z_slices, 1)
    image.setOpenAsHyperStack(True)
    print(image.isHyperStack(), image.getNChannels(), image.getOverlay())
    #image.flattenStack()
    image.show()
    fs = FileSaver(image)
    filepath = directory + "/" + filename + "_coloc.tiff"