ij.text.TextWindow Java Examples

The following examples show how to use ij.text.TextWindow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IJUtils.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Iterates on the list of TextWindows, and keeps only the ones containing a
 * non-null ResultsTable
 * 
 * @return an array containing the list of open TextWindows
 */
public static final TextWindow[] getTableWindows() 
{
    Frame[] frames = WindowManager.getNonImageWindows();
    
    ArrayList<TextWindow> windows = new ArrayList<TextWindow>(frames.length);
    
    for (Frame frame : frames) 
    {
        if (frame instanceof TextWindow) 
        {
            TextWindow tw = (TextWindow) frame;
            if (tw.getTextPanel().getResultsTable() != null) 
            {
                windows.add(tw);
            }
        }
    }
    
    return windows.toArray(new TextWindow[0]);
}
 
Example #2
Source File: LabelToValuePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Iterates on the list of TextWindows, and keeps only the ones containing a
 * non-null ResultsTable
 */
private static final TextWindow[] getTableWindows() 
{
	Frame[] frames = WindowManager.getNonImageWindows();
	
	ArrayList<TextWindow> windows = new ArrayList<TextWindow>(frames.length);
	
	for (Frame frame : frames) 
	{
		if (frame instanceof TextWindow) 
		{
			TextWindow tw = (TextWindow) frame;
			if (tw.getTextPanel().getResultsTable() != null) 
			{
				windows.add(tw);
			}
		}
	}
	
	return windows.toArray(new TextWindow[0]);
}
 
Example #3
Source File: DrawTableValuesPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void run(String arg0) 
{
	// Work on current image, and exit if no one is open
	this.targetImagePlus = IJ.getImage();

	// Check that a table window is open
	TextWindow[] textWindows = IJUtils.getTableWindows();
       if (textWindows.length == 0)
       {
           IJ.error("Requires at least one Table window");
           return;
       }
 		
	// Opens dialog to choose options
	createDialog();
	this.gd.showDialog();
	
	// parse dialog
	if (gd.wasCanceled())
		return;
	parseDialogOptions();
	saveDialogOptions();
	
	drawValues(this.targetImagePlus);
}
 
Example #4
Source File: DrawTableValuesPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * analyse dialog, and setup inner fields of the class.
 */
private void parseDialogOptions() 
{
    // select the result table from its name
	String tableName = this.gd.getNextChoice();
	Frame tableFrame = WindowManager.getFrame(tableName);
	this.table = ((TextWindow) tableFrame).getTextPanel().getResultsTable();

       this.calibratedPosition = this.gd.getNextBoolean();
       this.xPosHeaderName = this.gd.getNextChoice();
       this.yPosHeaderName = this.gd.getNextChoice();
       this.xOffset = (int) this.gd.getNextNumber();
       this.yOffset = (int) this.gd.getNextNumber();
       this.valueHeaderName = this.gd.getNextChoice();
       this.pattern = this.gd.getNextString();
}
 
Example #5
Source File: SingleWindowDisplay.java    From Colocalisation_Analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * If the currently selected ImageResult is an HistrogramResult, a table of
 * x-values, y-values and the counts.
 */
protected void showList() {
	/*
	 * check if we are dealing with an histogram result or a generic image
	 * result
	 */
	if (isHistogram(currentlyDisplayedImageResult)) {
		Histogram2D<T> hr = mapOf2DHistograms.get(currentlyDisplayedImageResult);
		double xBinWidth = 1.0 / hr.getXBinWidth();
		double yBinWidth = 1.0 / hr.getYBinWidth();
		// check if we have bins of size one or other ones
		boolean xBinWidthIsOne = Math.abs(xBinWidth - 1.0) < 0.00001;
		boolean yBinWidthIsOne = Math.abs(yBinWidth - 1.0) < 0.00001;
		// configure table headings accordingly
		String vHeadingX = xBinWidthIsOne ? "X value" : "X bin start";
		String vHeadingY = yBinWidthIsOne ? "Y value" : "Y bin start";
		// get the actual histogram data
		String histogramData = hr.getData();

		TextWindow tw = new TextWindow(getTitle(), vHeadingX + "\t" + vHeadingY + "\tcount", histogramData, 250,
				400);
		tw.setVisible(true);
	}
}
 
Example #6
Source File: LabelToValuePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
private GenericDialog createDialog()
	{
		// Get the list of windows containing tables
		TextWindow[] textWindows = getTableWindows();
		if (textWindows.length == 0)
		{
			IJ.error("Requires at least one Table window");
			return null;
		}
		String[] tableNames = new String[textWindows.length];
		for (int i = 0; i < textWindows.length; i++) {
			tableNames[i] = textWindows[i].getTitle();
//			IJ.log("Found table: " + tableNames[i]);
		}
		
		// Choose current table
		TextPanel tp = textWindows[0].getTextPanel();
		ResultsTable table = tp.getResultsTable();
		this.table = table;
		
		// Choose current heading
		String[] headings = table.getHeadings();
		String defaultHeading = headings[0];
		if (defaultHeading.equals("Label") && headings.length > 1)
		{
			defaultHeading = headings[1];
		}

		double[] extent = computeColumnExtent(table, defaultHeading);

		this.gd = new GenericDialog("Assign Measure to Label");
		gd.addChoice("Results Table:", tableNames, tableNames[0]);
		gd.addChoice("Column:", headings, defaultHeading);
		gd.addNumericField("Min Value", extent[0], this.nDigits, 10, null);
		gd.addNumericField("Max Value", extent[1], this.nDigits, 10, null);
		gd.addDialogListener(this);
		
		return gd;
	}
 
Example #7
Source File: LabelToValuePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * analyse dialog, and setup inner fields of the class.
 */
private void parseDialogOptions() 
{
	String tableName = this.gd.getNextChoice();
	Frame tableFrame = WindowManager.getFrame(tableName);
	this.table = ((TextWindow) tableFrame).getTextPanel().getResultsTable();
	
	this.selectedHeaderName = this.gd.getNextChoice();
	
	this.minValue = this.gd.getNextNumber();
	this.maxValue = this.gd.getNextNumber();
}
 
Example #8
Source File: DrawTableValuesPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean dialogItemChanged(GenericDialog gd, AWTEvent evt) 
{
	if (gd.wasCanceled() || gd.wasOKed()) 
	{
		return true;
	}
	
	@SuppressWarnings({ "unchecked" })
       Vector<Choice> choices = gd.getChoices();
	if (choices == null) 
	{
		IJ.log("empty choices array...");
		return false;
	}
	
	// Change of the data table
       if (evt.getSource() == choices.get(0)) 
	{
		String tableName = ((Choice) evt.getSource()).getSelectedItem();
		Frame tableFrame = WindowManager.getFrame(tableName);
		this.table = ((TextWindow) tableFrame).getTextPanel().getResultsTable();
		
		// Choose current headings
		String[] headings = this.table.getHeadings();		
		replaceStrings(choices.get(1), headings, chooseDefaultHeading(headings, xPosHeaderName));
           replaceStrings(choices.get(2), headings, chooseDefaultHeading(headings, yPosHeaderName));
           replaceStrings(choices.get(3), headings, chooseDefaultHeading(headings, valueHeaderName));
	}
	
	return true;
}
 
Example #9
Source File: HSV_Histogram_ComparisonJ_.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
    int stacksize = imp.getStack().getSize();

    if (imp.getStack().getSize() == 1) {
        IJ.error("You need a stack of images");
        return;
    }

    // Converter
    ImagePlusMatVectorConverter isc = new ImagePlusMatVectorConverter();
    opencv_core.MatVector mvec = isc.convert(imp,opencv_core.MatVector.class);

    if (!showDialog()) {
        return;
    }

    double[][] comparison = new double[4][stacksize * (stacksize - 1) / 2];

    opencv_core.Mat mask = new opencv_core.Mat();
    IntPointer intPtrChannels = new IntPointer(0, 1, 2);
    IntPointer intPtrHistSize = new IntPointer(hueBins, saturationBins, valueBins);
    FloatPointer fltPtrRanges = new FloatPointer(0.0f, 179.0f, 0.0f, 255.0f, 0.0f, 255.0f);
    PointerPointer ptptranges = new PointerPointer(fltPtrRanges, fltPtrRanges, fltPtrRanges);

    opencv_core.Mat hist1 = new opencv_core.Mat();
    opencv_core.Mat hist2 = new opencv_core.Mat();
    int n = 0;
    
    Mat hsv = new Mat();
    for (int i = 0; i < mvec.size() - 1; i++) {
        calcHist(mvec.get(i), 1, intPtrChannels, mask, hist1, 3, intPtrHistSize, ptptranges, true, false);
        opencv_core.normalize(hist1, hist1);
        for (int j = i + 1; j < mvec.size(); j++) {
            opencv_imgproc.cvtColor(mvec.get(j),hsv,opencv_imgproc.COLOR_BGR2HSV);
            calcHist(hsv, 1, intPtrChannels, mask, hist2, 3, intPtrHistSize, ptptranges, true, false);
            opencv_core.normalize(hist2, hist2);
            comparison[0][n] = opencv_imgproc.compareHist(hist1, hist2, opencv_imgproc.CV_COMP_CORREL);
            comparison[1][n] = opencv_imgproc.compareHist(hist1, hist2, opencv_imgproc.CV_COMP_CHISQR);
            comparison[2][n] = opencv_imgproc.compareHist(hist1, hist2, opencv_imgproc.CV_COMP_INTERSECT);
            comparison[3][n] = opencv_imgproc.compareHist(hist1, hist2, opencv_imgproc.CV_COMP_BHATTACHARYYA);
            n++;
        }
    }

    String headings = "Method\t";
    for (int i = 0; i < mvec.size() - 1; i++) {
        for (int j = i + 1; j < mvec.size(); j++) {
            headings = headings + (i + 1) + "-" + (j + 1) + "\t";
        }
    }
    headings = headings.substring(0, headings.lastIndexOf("\t"));
    ArrayList list = new ArrayList();

    String row1 = "Correlation\t";
    String row2 = "CHI Square\t";
    String row3 = "Intersection\t";
    String row4 = "BHATTACHARYYA\t";
    for (int i = 0; i < comparison[0].length - 1; i++) {
        row1 = row1 + comparison[0][i] + "\t";
        row2 = row2 + comparison[1][i] + "\t";
        row3 = row3 + comparison[2][i] + "\t";
        row4 = row4 + comparison[3][i] + "\t";

    }
    row1 = row1 + comparison[0][comparison[0].length - 1] ;
    row2 = row2 + comparison[1][comparison[0].length - 1];
    row3 = row3 + comparison[2][comparison[0].length - 1];
    row4 = row4 + comparison[3][comparison[0].length - 1];
    
    list.add(row1);
    list.add(row2);
    list.add(row3);
    list.add(row4);

    TextWindow textWindow = new TextWindow("Similarity Table", headings, list, 600, 400);
    textWindow.setVisible(true);

}
 
Example #10
Source File: BGR_Histogram_ComparisonJ_.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
    int stacksize = imp.getStack().getSize();

    if (imp.getStack().getSize() == 1) {
        IJ.error("You need a stack of images");
        return;
    }

    // Converter
    ImagePlusMatVectorConverter isc = new ImagePlusMatVectorConverter();
    opencv_core.MatVector mvec = isc.convert(imp,MatVector.class);

    if (!showDialog()) {
        return;
    }

    double[][] comparison = new double[4][stacksize * (stacksize - 1) / 2];

    opencv_core.Mat mask = new opencv_core.Mat();
    IntPointer intPtrChannels = new IntPointer(0, 1, 2);
    IntPointer intPtrHistSize = new IntPointer(blueBins, greenBins, redBins);
    FloatPointer fltPtrRanges = new FloatPointer(0.0f, 255.0f, 0.0f, 255.0f, 0.0f, 255.0f);
    PointerPointer ptptranges = new PointerPointer(fltPtrRanges, fltPtrRanges, fltPtrRanges);

    opencv_core.Mat hist1 = new opencv_core.Mat();
    opencv_core.Mat hist2 = new opencv_core.Mat();
    int n = 0;
    for (int i = 0; i < mvec.size() - 1; i++) {
        calcHist(mvec.get(i), 1, intPtrChannels, mask, hist1, 3, intPtrHistSize, ptptranges, true, false);
        opencv_core.normalize(hist1, hist1);
        for (int j = i + 1; j < mvec.size(); j++) {
            calcHist(mvec.get(j), 1, intPtrChannels, mask, hist2, 3, intPtrHistSize, ptptranges, true, false);
            opencv_core.normalize(hist2, hist2);
            comparison[0][n] = opencv_imgproc.compareHist(hist1, hist2, opencv_imgproc.CV_COMP_CORREL);
            comparison[1][n] = opencv_imgproc.compareHist(hist1, hist2, opencv_imgproc.CV_COMP_CHISQR);
            comparison[2][n] = opencv_imgproc.compareHist(hist1, hist2, opencv_imgproc.CV_COMP_INTERSECT);
            comparison[3][n] = opencv_imgproc.compareHist(hist1, hist2, opencv_imgproc.CV_COMP_BHATTACHARYYA);
            n++;
        }
    }

    String headings = "Method\t";
    for (int i = 0; i < mvec.size() - 1; i++) {
        for (int j = i + 1; j < mvec.size(); j++) {
            headings = headings + (i + 1) + "-" + (j + 1) + "\t";
        }
    }
    headings = headings.substring(0, headings.lastIndexOf("\t"));
    ArrayList list = new ArrayList();

    String row1 = "Correlation\t";
    String row2 = "CHI Square\t";
    String row3 = "Intersection\t";
    String row4 = "BHATTACHARYYA\t";
    for (int i = 0; i < comparison[0].length - 1; i++) {
        row1 = row1 + comparison[0][i] + "\t";
        row2 = row2 + comparison[1][i] + "\t";
        row3 = row3 + comparison[2][i] + "\t";
        row4 = row4 + comparison[3][i] + "\t";

    }
    row1 = row1 + comparison[0][comparison[0].length - 1] ;
    row2 = row2 + comparison[1][comparison[0].length - 1];
    row3 = row3 + comparison[2][comparison[0].length - 1];
    row4 = row4 + comparison[3][comparison[0].length - 1];
    
    list.add(row1);
    list.add(row2);
    list.add(row3);
    list.add(row4);

    TextWindow textWindow = new TextWindow("Similarity Table", headings, list, 600, 400);
    textWindow.setVisible(true);

}
 
Example #11
Source File: KMeans_ClusteringJ.java    From IJ-OpenCV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
    int stacksize = imp.getStack().getSize();

    if (imp.getStack().getSize() == 1) {
        IJ.error("You need a stack of images");
        return;
    }

    // Converters
    ImagePlusMatVectorConverter isc = new ImagePlusMatVectorConverter();

    opencv_core.MatVector mvec = isc.convert(imp, MatVector.class);

    if (!showDialog()) {
        return;
    }

    // feature data
    FloatPointer featuresData = new FloatPointer((int) mvec.size() * 512);

    // Compute the histograms
    Mat mask = new Mat();
    IntPointer intPtrChannels = new IntPointer(0, 1, 2);
    IntPointer intPtrHistSize = new IntPointer(8, 8, 8);
    FloatPointer fltPtrRanges = new FloatPointer(0.0f, 255.0f, 0.0f, 255.0f, 0.0f, 255.0f);
    PointerPointer ptptranges = new PointerPointer(fltPtrRanges, fltPtrRanges, fltPtrRanges);

    Mat hist1 = new Mat();
    int n = 0;
    for (int i = 0; i < mvec.size(); i++) {
        calcHist(mvec.get(i), 1, intPtrChannels, mask, hist1, 3, intPtrHistSize, ptptranges, true, false);
        opencv_core.normalize(hist1, hist1);
        for (int j = 0; j < 512; j++) {
            featuresData.put(n, hist1.getFloatBuffer().get(j));
            n++;
        }

    }

    Mat data = new Mat((int) mvec.size(), 512, CV_32F, featuresData);

    Mat labels = new Mat();
    Mat centers = new Mat();

    opencv_core.TermCriteria tc = new opencv_core.TermCriteria(opencv_core.TermCriteria.EPS + opencv_core.TermCriteria.COUNT, 10, 1.0);

    kmeans(data, nclusters, labels, tc, 1, KMEANS_PP_CENTERS);

    String headings = "Image\t Cluster";
    ArrayList list = new ArrayList();

    String row = "";

    for (int i = 0; i < labels.rows(); i++) {
        row = imp.getStack().getSliceLabel(i + 1) + "\t" + labels.getIntBuffer().get(i);
        list.add(row);

    }

    TextWindow textWindow = new TextWindow("Clustering Table", headings, list, 600, 400);
    textWindow.setVisible(true);

}
 
Example #12
Source File: LabelToValuePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void run(String arg0) 
{
	// Work on current image, and exit if no one is open
	this.labelImagePlus = IJ.getImage();

	// Check that a table window is open
	TextWindow[] textWindows = getTableWindows();
       if (textWindows.length == 0)
       {
           IJ.error("Requires at least one Table window");
           return;
       }
       
	// Create empty result image
	initResultImage();
	
	// Opens dialog to choose options
	createDialog();
	this.gd.showDialog();
	
	// parse dialog
	if (gd.wasCanceled())
		return;
	parseDialogOptions();
	
	ImagePlus resultPlus = computeResultImage();
	if( null == resultPlus )
		return;
	
	this.resultPlus.copyScale(this.labelImagePlus);

	String newName = this.labelImagePlus.getShortTitle() + "-" + selectedHeaderName;
	resultPlus.setTitle(newName);
	resultPlus.show();
	
	// set up display 
	if (labelImagePlus.getStackSize() > 1) 
	{
		resultPlus.setSlice(labelImagePlus.getCurrentSlice());
	}
}
 
Example #13
Source File: LabelToValuePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean dialogItemChanged(GenericDialog gd, AWTEvent evt) 
{
	if (gd.wasCanceled() || gd.wasOKed()) 
	{
		return true;
	}
	
	@SuppressWarnings("rawtypes")
	Vector choices = gd.getChoices();
	if (choices == null) 
	{
		IJ.log("empty choices array...");
		return false;
	}
	
	// Change of the data table
       if (evt.getSource() == choices.get(0)) 
	{
		String tableName = ((Choice) evt.getSource()).getSelectedItem();
		Frame tableFrame = WindowManager.getFrame(tableName);
		this.table = ((TextWindow) tableFrame).getTextPanel().getResultsTable();
		
		// Choose current heading
		String[] headings = this.table.getHeadings();
		String defaultHeading = headings[0];
		if (defaultHeading.equals("Label") && headings.length > 1) 
		{
			defaultHeading = headings[1];
		}
		
		Choice headingChoice = (Choice) choices.get(1);
		headingChoice.removeAll();
		for (String heading : headings) 
		{
			headingChoice.add(heading);
		}
		headingChoice.select(defaultHeading);

		changeColumnHeader(defaultHeading);
	}
	
	// Change of the column heading
	if (evt.getSource() == choices.get(1)) 
	{
		String headerName = ((Choice) evt.getSource()).getSelectedItem();
           changeColumnHeader(headerName);
	}
	
	return true;
}
 
Example #14
Source File: DrawTableValuesPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
private GenericDialog createDialog()
{
	// Get the list of windows containing tables
	TextWindow[] textWindows = IJUtils.getTableWindows();
	if (textWindows.length == 0)
	{
		IJ.error("Requires at least one Table window");
		return null;
	}
	String[] tableNames = new String[textWindows.length];
	for (int i = 0; i < textWindows.length; i++) {
		tableNames[i] = textWindows[i].getTitle();
	}
	
	// Choose current table
	TextPanel tp = textWindows[0].getTextPanel();
	ResultsTable table = tp.getResultsTable();
	this.table = table;
	
	// Choose current heading
	String[] headings = table.getHeadings();
	String defaultHeading = headings[0];
	if (defaultHeading.equals("Label") && headings.length > 1)
	{
		defaultHeading = headings[1];
	}

	this.gd = new GenericDialog("Draw Text from Column");
	gd.addChoice("Results Table:", tableNames, tableNames[0]);
       gd.addCheckbox("Calibrated Position:", false);
       gd.addChoice("X-Position:", headings, defaultHeading);
       gd.addChoice("Y-Position:", headings, defaultHeading);
       gd.addNumericField("X-Offset:", this.xOffset, 0, 5, "pixels");
       gd.addNumericField("Y-Offset:", this.yOffset, 0, 5, "pixels");
       gd.addChoice("Values:", headings, defaultHeading);
       gd.addStringField("Pattern:", "%5.2f", 10);
       
       @SuppressWarnings("unchecked")
       Vector<Choice> choices = gd.getChoices();
       replaceStrings(choices.get(1), headings, chooseDefaultHeading(headings, xPosHeaderName));
       replaceStrings(choices.get(2), headings, chooseDefaultHeading(headings, yPosHeaderName));
       replaceStrings(choices.get(3), headings, chooseDefaultHeading(headings, valueHeaderName));

       gd.addDialogListener(this);
	
	return gd;
}
 
Example #15
Source File: Utils.java    From Scripts with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Opens a tab or comma delimited text file.
 *
 * @param path
 *            The absolute pathname string of the file. A file open dialog
 *            is displayed if path is {@code null} or an empty string.
 * @param title
 *            The title of the window in which data is displayed. The
 *            filename is used if title is null or an empty string. To avoid
 *            windows with duplicated titles, title is made unique by
 *            {@link WindowManager} .
 * @param listener
 *            The {@link WindowListener} to be added to the window
 *            containing data if retrieval was successful. It is ignored
 *            when {@code null}.
 * @throws IOException
 *             if file could not be opened
 * @return A reference to the opened {link ResultsTable} or {@code null} if
 *         table was empty.
 *
 * @see #getTable()
 * @see ij.io.Opener#openTable(String)
 */
public static ResultsTable openAndDisplayTable(final String path, final String title, final WindowListener listener)
		throws IOException {
	ResultsTable rt = null;
	rt = ResultsTable.open(path);
	if (rt == null || rt.getCounter() == 0) // nothing to be displayed
		return null;
	rt.showRowNumbers(false);
	String rtTitle = (title != null && !title.isEmpty()) ? title : OpenDialog.getLastName();
	rtTitle = WindowManager.makeUniqueName(rtTitle);
	rt.show(rtTitle);
	final TextWindow rtWindow = (TextWindow) WindowManager.getFrame(rtTitle);
	if (rtWindow != null && listener != null)
		rtWindow.addWindowListener(listener);
	return rt;
}