ij.gui.Line Java Examples
The following examples show how to use
ij.gui.Line.
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: HoughLinesJ_.java From IJ-OpenCV with GNU General Public License v3.0 | 6 votes |
/** * Hough lines detection: Perform line detection on a binary image * @param imp : 8-bit Binary ImagePlus * @param min_length : Minimum number of points lying on a line to return it * @param step_line : Step size (pixels) between parallel lines for iterative line search * @param min_theta : Start looking for lines with orientation corresponding to this Rho angle (degrees) * @param max_theta : Stop looking for lines with orientation corresponding to this Rho angle (degrees) * @param step_theta : Angle step size for line search (degrees) * @return */ public ArrayList<Line> HoughLines(ImagePlus imp, int min_length, double step_line, double min_theta, double max_theta, double step_theta){ // Initialise Imp>Mat Converters ImagePlusMatConverter ic = new ImagePlusMatConverter(); // Convert input imp to Mat opencv_core.Mat m = ic.convert(imp, Mat.class); // Convert from degrees to radians min_theta = Math.toRadians(min_theta); max_theta = Math.toRadians(max_theta); step_theta = Math.toRadians(step_theta); // Do Hough line detection Mat lines = new Mat(); opencv_imgproc.HoughLines(m, lines, step_line, step_theta, min_length, 0, 0, min_theta, max_theta); // Convert lines Mat to ArrayList of ij line MatListLineConverter lc = new MatListLineConverter(); ArrayList<Line> linesIJ = new ArrayList<Line>(); linesIJ = lc.convert(lines, linesIJ.getClass()); return linesIJ; }
Example #2
Source File: MatListLineConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 6 votes |
@Override public < T> T convert(Object o, Class< T> type) { Mat lines = (Mat) o; ArrayList<Line> ijlines = new ArrayList<Line>(); opencv_core.MatVector xy = new opencv_core.MatVector(2); split(lines, xy); for (int i = 0; i < lines.rows(); i++) { float rho = xy.get(0).getFloatBuffer().get(i); float theta = xy.get(1).getFloatBuffer().get(i); double a = cos(theta); double b = sin(theta); double x0 = a * rho, y0 = b * rho; opencv_core.Point pt1 = new opencv_core.Point(cvRound(x0 + 1000 * (-b)), cvRound(y0 + 1000 * (a))), pt2 = new opencv_core.Point(cvRound(x0 - 1000 * (-b)), cvRound(y0 - 1000 * (a))); Line line = new Line(x0 + 1000 * (-b), y0 + 1000 * (a), x0 - 1000 * (-b), y0 - 1000 * (a)); ijlines.add(line); } return (T) ijlines; }
Example #3
Source File: EquivalentEllipsePlugin.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private final static Roi createMajorAxisRoi(Ellipse ellipse) { // Coordinates of ellipse, in pixel coordinates Point2D center = ellipse.center(); double xc = center.getX(); double yc = center.getY(); double r1 = ellipse.radius1(); double theta = Math.toRadians(ellipse.orientation()); double cot = Math.cos(theta); double sit = Math.sin(theta); double x1 = xc + r1 * cot; double y1 = yc + r1 * sit; double x2 = xc - r1 * cot; double y2 = yc - r1 * sit; return new Line(x1, y1, x2, y2); }
Example #4
Source File: EquivalentEllipsePlugin.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private final static Roi createMinorAxisRoi(Ellipse ellipse) { // Coordinates of ellipse, in pixel coordinates Point2D center = ellipse.center(); double xc = center.getX(); double yc = center.getY(); double r2 = ellipse.radius2(); double theta = Math.toRadians(ellipse.orientation() + 90); double cot = Math.cos(theta); double sit = Math.sin(theta); double x1 = xc + r2 * cot; double y1 = yc + r2 * sit; double x2 = xc - r2 * cot; double y2 = yc - r2 * sit; return new Line(x1, y1, x2, y2); }
Example #5
Source File: InertiaEllipsePlugin.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private final static Roi createMajorAxisRoi(Ellipse ellipse) { // Coordinates of ellipse, in pixel coordinates Point2D center = ellipse.center(); double xc = center.getX(); double yc = center.getY(); double r1 = ellipse.radius1(); double theta = Math.toRadians(ellipse.orientation()); double cot = Math.cos(theta); double sit = Math.sin(theta); double x1 = xc + r1 * cot; double y1 = yc + r1 * sit; double x2 = xc - r1 * cot; double y2 = yc - r1 * sit; return new Line(x1, y1, x2, y2); }
Example #6
Source File: InertiaEllipsePlugin.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private final static Roi createMinorAxisRoi(Ellipse ellipse) { // Coordinates of ellipse, in pixel coordinates Point2D center = ellipse.center(); double xc = center.getX(); double yc = center.getY(); double r2 = ellipse.radius2(); double theta = Math.toRadians(ellipse.orientation() + 90); double cot = Math.cos(theta); double sit = Math.sin(theta); double x1 = xc + r2 * cot; double y1 = yc + r2 * sit; double x2 = xc - r2 * cot; double y2 = yc - r2 * sit; return new Line(x1, y1, x2, y2); }
Example #7
Source File: HoughLinesJ_.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public void run() { // Do line detection ArrayList<Line> linesIJ = HoughLines(imp, min_length, step_line, min_theta, max_theta, step_theta); // Add lines to RoiManager RoiManager rm = new RoiManager(); rm.setVisible(true); for (int i = 0; i < linesIJ.size(); i++) { rm.add(imp, linesIJ.get(i), i); } }
Example #8
Source File: LineCVLineConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public < T> T convert(Object o, Class< T> type) { LineCV l = (LineCV) o; double a = cos(l.getTheta()); double b = sin(l.getTheta()); double x0 = a * l.getRho(), y0 = b * l.getRho(); opencv_core.Point pt1 = new opencv_core.Point(cvRound(x0 + 1000 * (-b)), cvRound(y0 + 1000 * (a))), pt2 = new opencv_core.Point(cvRound(x0 - 1000 * (-b)), cvRound(y0 - 1000 * (a))); Line line = new Line(pt1.x(), pt1.y(), pt2.x(), pt2.y()); return (T) line; }
Example #9
Source File: RegionAdjacencyGraphPlugin.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
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 #10
Source File: PDFWriter.java From Colocalisation_Analysis with GNU General Public License v3.0 | 5 votes |
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 #11
Source File: MatListLineConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 4 votes |
@Override public Class< List<Line>> getOutputType() { return (Class<List<Line>>) (Object) List.class; }
Example #12
Source File: LineCVLineConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 4 votes |
@Override public Class< Line> getOutputType() { return Line.class; }
Example #13
Source File: SingleWindowDisplay.java From Colocalisation_Analysis with GNU General Public License v3.0 | 4 votes |
/** * 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); }