Java Code Examples for ij.gui.Overlay#add()

The following examples show how to use ij.gui.Overlay#add() . 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: IJImager.java    From DeconvolutionLab2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void show(RealSignal signal, String title, Imager.Type type, int z, ArrayList<Line2D.Double> overlayLines) {
	ImagePlus imp = build(signal, type);
	if (imp != null) {
		imp.setTitle(title);
		int nz = imp.getStackSize();
		imp.show();
		imp.setSlice(Math.max(1, Math.min(nz, z)));
		imp.getProcessor().resetMinAndMax();
	}
	
	if (imp != null) {
		Overlay overlay = imp.getOverlay() == null ? new Overlay() : imp.getOverlay();
		for(Line2D.Double line : overlayLines) {
			ij.gui.Line roi = new ij.gui.Line(round(line.x1), round(line.y1), round(line.x2), round(line.y2));
			overlay.add(roi);
		}
		imp.setOverlay(overlay);
	}
}
 
Example 2
Source File: IJImager.java    From DeconvolutionLab2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void append(ContainerImage container, RealSignal signal, String title, Imager.Type type, ArrayList<Line2D.Double> overlayLines) {		
	ImagePlus cont = (ImagePlus) container.object;
	if (container.object == null) {
		ImageStack stack = new ImageStack(signal.nx, signal.ny);
		stack.addSlice(build(signal, type).getProcessor());
		stack.addSlice(build(signal, type).getProcessor());
		container.object = new ImagePlus(title, stack);
		((ImagePlus)container.object).show();
	}
	else {
		cont.getStack().addSlice(build(signal, type).getProcessor());
		cont.setSlice(cont.getStack().getSize());
		cont.updateAndDraw();
		cont.getProcessor().resetMinAndMax();
	}
	if (cont != null)  {
		Overlay overlay = cont.getOverlay() == null ? new Overlay() : cont.getOverlay();
		for(Line2D.Double line : overlayLines) {
			ij.gui.Line roi = new ij.gui.Line(round(line.x1), round(line.y1), round(line.x2), round(line.y2));
			overlay.add(roi);
		}
		cont.setOverlay(overlay);
	}		
}
 
Example 3
Source File: Path.java    From SNT with GNU General Public License v3.0 6 votes vote down vote up
private void addPolyLineToOverlay(final FloatPolygon p, final int z_position, final int roi_id,
		final Overlay overlay) {
	if (p.npoints > 0) {
		if (p.npoints == 1) {
			// create 1-pixel length lines for single points
			p.xpoints[0] -= 0.5f;
			p.ypoints[0] -= 0.5f;
			p.addPoint(p.xpoints[0] + 0.5f, p.ypoints[0] + 0.5f);
		}
		final PolygonRoi polyline = new PolygonRoi(p, Roi.FREELINE);
		polyline.enableSubPixelResolution();
		// polyline.fitSplineForStraightening();
		if (name == null)
			setDefaultName();
		polyline.setStrokeColor(getColor());
		polyline.setName(String.format(name + "-%04d-Z%d", roi_id, z_position));
		polyline.setPosition(z_position + 1); // index 1
		overlay.add(polyline);
	}
}
 
Example 4
Source File: PointMatchClientTest.java    From render with GNU General Public License v2.0 6 votes vote down vote up
private static void showMatches(final String imageUrl,
                                final List<CanvasMatches> canvasMatchesList,
                                final boolean isP,
                                final Color[] colors) {

    final ImagePlus imagePlus = IJ.openImage(imageUrl);
    final Overlay overlay = new Overlay();

    int colorIndex = 0;
    for (final CanvasMatches canvasMatches : canvasMatchesList) {
        final double[][] points = isP ? canvasMatches.getMatches().getPs() : canvasMatches.getMatches().getQs();
        final float[] xPoints = toFloat(points[0]);
        final float[] yPoints = toFloat(points[1]);
        final PointRoi pointRoi = new PointRoi(xPoints, yPoints, xPoints.length);
        pointRoi.setStrokeColor(colors[colorIndex]);
        pointRoi.setSize(3); // 0: "Tiny", 1: "Small", 2: "Medium", 3: "Large", 4: "Extra Large"}
        overlay.add(pointRoi);
        colorIndex = (colorIndex + 1) % colors.length;
    }

    imagePlus.setOverlay(overlay);
    imagePlus.updateAndDraw();
    imagePlus.show();

}
 
Example 5
Source File: BoundingBoxPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Display the result of bounding box extraction as overlay on a given
 * image.
 * 
 * @param target
 *            the ImagePlus used to display result
 * @param results
 *            the associative map between region label and bounding box
 */
private void showResultsAsOverlay(Map<Integer, Box2D> results, ImagePlus target)	
{
	// get spatial calibration of target image
	Calibration calib = target.getCalibration();
	
	// create overlay
	Overlay overlay = new Overlay();
	Roi roi;
	
	// add each box to the overlay
	for (int label : results.keySet()) 
	{
		// Coordinates of inscribed circle, in pixel coordinates
		Box2D box = results.get(label);
		box = uncalibrate(box, calib);
		roi = createRoi(box);
		
		// draw inscribed circle
		roi.setStrokeColor(Color.BLUE);
		overlay.add(roi);
	}
	
	target.setOverlay(overlay);
}
 
Example 6
Source File: OrientedBoundingBoxPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Display the result of oriented bounding box extraction as overlay on a
 * given image.
 * 
 * @param target
 *            the ImagePlus used to display result
 * @param results
 *            the associative map between region label and bounding box
 */
private void showResultsAsOverlay(Map<Integer, OrientedBox2D> results, ImagePlus target)	
{
	// get spatial calibration of target image
	Calibration calib = target.getCalibration();
	
	// create overlay
	Overlay overlay = new Overlay();
	Roi roi;
	
	// add each box to the overlay
	for (int label : results.keySet()) 
	{
		// Coordinates of inscribed circle, in pixel coordinates
		OrientedBox2D box = results.get(label);
		roi = createUncalibratedRoi(box, calib);
		
		// draw inscribed circle
		roi.setStrokeColor(Color.GREEN);
		overlay.add(roi);
	}
	
	target.setOverlay(overlay);
}
 
Example 7
Source File: RegionAdjacencyGraphPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void overlayRAG(Set<LabelPair> adjList, ImagePlus imagePlus, ImagePlus targetPlus)
{
	IJ.log("display RAG");
	
	// first compute centroids
	ImageProcessor image = imagePlus.getProcessor();
	int[] labels = LabelImages.findAllLabels(image);
	Map<Integer, Integer> labelMap = LabelImages.mapLabelIndices(labels);
	double[][] centroids = Centroid.centroids(image, labels);
	
	// create an overlay for drawing edges
	Overlay overlay = new Overlay();
	
	// iterate over adjacencies to add edges to overlay
	for (LabelPair pair : adjList)
	{
		// first retrieve index in centroid array
		int ind1 = labelMap.get(pair.label1);
		int ind2 = labelMap.get(pair.label2);
		
		// coordinates of edge extremities
		int x1 = (int) centroids[ind1][0];
		int y1 = (int) centroids[ind1][1];
		int x2 = (int) centroids[ind2][0];
		int y2 = (int) centroids[ind2][1];
		
		// draw current edge
		Roi roi = new Line(x1, y1, x2, y2);
		
		roi.setStrokeColor(Color.GREEN);
		roi.setStrokeWidth(2);
		overlay.add(roi);
	}
	
	targetPlus.setOverlay(overlay);
}
 
Example 8
Source File: GeodesicDiameterPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void drawPaths(ImagePlus target, Map<Integer, GeodesicDiameter.Result> geodDiams)
{
	Overlay overlay = new Overlay();
	Calibration calib = target.getCalibration();
	
	for (GeodesicDiameter.Result result : geodDiams.values())
	{
		Roi roi = createPathRoi(result.path, calib);
	    roi.setStrokeColor(Color.RED);
	    overlay.add(roi);
	}

	target.setOverlay(overlay);
}
 
Example 9
Source File: DrawTableValuesPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void drawValues(ImagePlus target)
	{
	    Overlay overlay = new Overlay();
//	    Calibration calib = target.getCalibration();
	    
        double[] xPos = getColumnValues(this.table, this.xPosHeaderName);
        double[] yPos = getColumnValues(this.table, this.yPosHeaderName);
        if (this.calibratedPosition)
        {
            Calibration calib = target.getCalibration();
            for (int i = 0; i < xPos.length; i++)
            {
                xPos[i] = xPos[i] * calib.pixelWidth  + calib.xOrigin;
                yPos[i] = yPos[i] * calib.pixelHeight + calib.yOrigin;
            }
        }
            
        double[] values = getColumnValues(this.table, this.valueHeaderName);

        for (int i = 0; i < xPos.length; i++)
        {
            Roi roi = new TextRoi(
                    xPos[i] + this.xOffset,
                    yPos[i] + this.yOffset,
                    String.format(this.pattern,  values[i]));
            overlay.add(roi);
        }

	    target.setOverlay(overlay);
	}
 
Example 10
Source File: MaxFeretDiameterPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void drawDiameters(ImagePlus target, Map<Integer, PointPair2D> geodDiams)
{
	Overlay overlay = new Overlay();
	Calibration calib = target.getCalibration();
	
	for (PointPair2D result : geodDiams.values())
	{
		Roi roi = createDiametersRoi(result, calib);
	    roi.setStrokeColor(Color.BLUE);
	    overlay.add(roi);
	}

	target.setOverlay(overlay);
}
 
Example 11
Source File: PDFWriter.java    From Colocalisation_Analysis with GNU General Public License v3.0 5 votes vote down vote up
private void drawLine(Histogram2D<T> histogram, Overlay overlay, long imgWidth, long imgHeight, double slope,
		double intercept) {

	double startX, startY, endX, endY;
	/*
	 * since we want to draw the line over the whole image we can directly
	 * use screen coordinates for x values.
	 */
	startX = 0.0;
	endX = imgWidth;

	// check if we can get some exta information for drawing
	// get calibrated start y coordinates
	double calibratedStartY = slope * histogram.getXMin() + intercept;
	double calibratedEndY = slope * histogram.getXMax() + intercept;
	// convert calibrated coordinates to screen coordinates
	startY = calibratedStartY * histogram.getYBinWidth();
	endY = calibratedEndY * histogram.getYBinWidth();

	/*
	 * since the screen origin is in the top left of the image, we need to
	 * x-mirror our line
	 */
	startY = (imgHeight - 1) - startY;
	endY = (imgHeight - 1) - endY;
	// create the line ROI and add it to the overlay
	Line lineROI = new Line(startX, startY, endX, endY);
	/*
	 * Set drawing width of line to one, in case it has been changed
	 * globally.
	 */
	lineROI.setStrokeWidth(1.0f);
	overlay.add(lineROI);
	
}
 
Example 12
Source File: EquivalentEllipsePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static final void addRoiToOverlay(Overlay overlay, Roi roi, Color color)
{
	roi.setStrokeColor(color);
	overlay.add(roi);
}
 
Example 13
Source File: InertiaEllipsePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static final void addRoiToOverlay(Overlay overlay, Roi roi, Color color)
{
	roi.setStrokeColor(color);
	overlay.add(roi);
}
 
Example 14
Source File: SingleWindowDisplay.java    From Colocalisation_Analysis with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the line on the overlay.
 */
protected void drawLine(Overlay overlay, RandomAccessibleInterval<? extends RealType<?>> img, double slope,
		double intercept) {
	double startX, startY, endX, endY;
	long imgWidth = img.dimension(0);
	long imgHeight = img.dimension(1);
	/*
	 * since we want to draw the line over the whole image we can directly
	 * use screen coordinates for x values.
	 */
	startX = 0.0;
	endX = imgWidth;

	// check if we can get some exta information for drawing
	if (isHistogram(img)) {
		Histogram2D<T> histogram = mapOf2DHistograms.get(img);
		// get calibrated start y coordinates
		double calibratedStartY = slope * histogram.getXMin() + intercept;
		double calibratedEndY = slope * histogram.getXMax() + intercept;
		// convert calibrated coordinates to screen coordinates
		startY = calibratedStartY * histogram.getYBinWidth();
		endY = calibratedEndY * histogram.getYBinWidth();
	} else {
		startY = slope * startX + intercept;
		endY = slope * endX + intercept;
	}

	/*
	 * since the screen origin is in the top left of the image, we need to
	 * x-mirror our line
	 */
	startY = (imgHeight - 1) - startY;
	endY = (imgHeight - 1) - endY;
	// create the line ROI and add it to the overlay
	Line lineROI = new Line(startX, startY, endX, endY);
	/*
	 * Set drawing width of line to one, in case it has been changed
	 * globally.
	 */
	lineROI.setStrokeWidth(1.0f);
	overlay.add(lineROI);
}