Java Code Examples for ij.text.TextWindow#setVisible()

The following examples show how to use ij.text.TextWindow#setVisible() . 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: 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 2
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 3
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 4
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);

}