ij.gui.OvalRoi Java Examples
The following examples show how to use
ij.gui.OvalRoi.
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: Utils.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
/** Paints an approximation of the pipe into the set of slices. */ static public void paint(final Pipe pipe, final Map<Layer,ImageProcessor> slices, final int value, final float scale) { final VectorString3D vs = pipe.asVectorString3D(); vs.resample(1); // one pixel final double[] px = vs.getPoints(0); final double[] py = vs.getPoints(1); final double[] pz = vs.getPoints(2); final double[] pr = vs.getDependent(0); // For each point for (int i=0; i<px.length-1; i++) { final ImageProcessor ip = slices.get(pipe.getLayerSet().getNearestLayer(pz[i])); if (null == ip) continue; final OvalRoi ov = new OvalRoi((int)((px[i] - pr[i]) * scale), (int)((py[i] - pr[i]) * scale), (int)(pr[i]*2*scale), (int)(pr[i]*2*scale)); ip.setRoi(ov); ip.setValue(value); ip.fill(ip.getMask()); } }
Example #2
Source File: MatListOvalRoiConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 6 votes |
@Override public < T> T convert(Object o, Class< T> type) { Mat circles = (Mat) o; opencv_core.MatVector xyr = new opencv_core.MatVector(3); split(circles, xyr); int num = circles.size().height(); ArrayList<OvalRoi> result = new ArrayList<OvalRoi>(); for (int i = 0; i < num; i++) { int cx = (int) xyr.get(0).getFloatBuffer().get(i); int cy = (int) xyr.get(1).getFloatBuffer().get(i); int r = (int) xyr.get(2).getFloatBuffer().get(i); OvalRoi or = new OvalRoi(cx - r, cy - r, r * 2, r * 2); result.add(or); } return (T) result; }
Example #3
Source File: ListOvalRoiMatConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 6 votes |
@Override public boolean canConvert(Object src, Type dest) { if(!(src instanceof ArrayList<?>)){ return false; } ArrayList<OvalRoi> alor = (ArrayList<OvalRoi>) src; for (int i = 0; i < alor.size(); i++) { Rectangle rect = alor.get(i).getBounds(); if (rect.width != rect.height) { return false; } } return true; }
Example #4
Source File: DetectCirclesJ_.java From IJ-OpenCV with GNU General Public License v3.0 | 6 votes |
@Override public void run() { // Converters ImagePlusMatConverter ic = new ImagePlusMatConverter(); opencv_core.Mat m = ic.convert(imp, Mat.class); MatListOvalRoiConverter cc = new MatListOvalRoiConverter(); Mat gray = new Mat(); opencv_imgproc.cvtColor(m, gray, opencv_imgproc.COLOR_BGR2GRAY); Mat circles = new Mat(); opencv_imgproc.HoughCircles(gray, circles, opencv_imgproc.CV_HOUGH_GRADIENT, 1.2, 100); ArrayList<OvalRoi> or = new ArrayList<OvalRoi>(); or = cc.convert(circles, or.getClass()); RoiManager rm = new RoiManager(); for (int i = 0; i < or.size(); i++) { rm.add(imp, or.get(i), i); } }
Example #5
Source File: ListOvalRoiMatConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public < T> T convert(Object o, Class< T> type) { ArrayList<OvalRoi> alor = (ArrayList<OvalRoi>) o; float[] xpoints = new float[alor.size()]; float[] ypoints = new float[alor.size()]; float[] radiuses = new float[alor.size()]; for (int i = 0; i < alor.size(); i++) { Rectangle rect = alor.get(i).getBounds(); CircleCV c = new CircleCV(new opencv_core.Point(rect.x + rect.width / 2, rect.y + rect.height / 2), rect.width / 2); xpoints[i] = rect.x + rect.width / 2; ypoints[i] = rect.y + rect.height / 2; radiuses[i] = rect.width / 2; } Mat mx = new Mat(xpoints); Mat my = new Mat(ypoints); Mat mr = new Mat(radiuses); opencv_core.MatVector mxyr = new opencv_core.MatVector(3); mxyr.put(0, mx); mxyr.put(1, my); mxyr.put(2, mr); Mat m = new Mat(); merge(mxyr, m); return (T) m; }
Example #6
Source File: AreaWrapper.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** This method could get tones of improvement, which should be pumped upstream into ImageJ's RoiBrush class which is creating it at every while(true) {} iteration!!! * The returned area has its coordinates centered around 0,0 */ static public Area makeBrush(int diameter, double mag) { if (diameter < 1) return null; if (mag >= 1) return new Area(new OvalRoi(-diameter/2, -diameter/2, diameter, diameter).getPolygon()); // else, create a smaller brush and transform it up, i.e. less precise, less points to store -but precision matches what the eye sees, and allows for much better storage -less points. int screen_diameter = (int)(diameter * mag); if (0 == screen_diameter) return null; // can't paint at this mag with this diameter Area brush = new Area(new OvalRoi(-screen_diameter/2, -screen_diameter/2, screen_diameter, screen_diameter).getPolygon()); // scale to world coordinates AffineTransform at = new AffineTransform(); at.scale(1/mag, 1/mag); return brush.createTransformedArea(at); // smooth out edges /* Polygon pol = new OvalRoi(-diameter/2, -diameter/2, diameter, diameter).getPolygon(); Polygon pol2 = new Polygon(); // cheap and fast: skip every other point, since all will be square angles for (int i=0; i<pol.npoints; i+=2) { pol2.addPoint(pol.xpoints[i], pol.ypoints[i]); } return new Area(pol2); // the above works nice, but then the fill and fill-remove don't work properly (there are traces in the edges) // Needs a workround: before adding/substracting, enlarge the polygon to have square edges */ }
Example #7
Source File: Circle2fOvalRoiConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public < T> T convert(Object o, Class< T> type) { Circle2fCV c = (Circle2fCV)o; OvalRoi or = new OvalRoi(c.getCenter().x() - c.getRadius(), c.getCenter().y() - c.getRadius(), c.getRadius() * 2, c.getRadius() * 2); return (T)or; }
Example #8
Source File: CircleOvalRoiConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public < T> T convert(Object o, Class< T> type) { CircleCV c = (CircleCV)o; OvalRoi or = new OvalRoi(c.getCenter().x() - c.getRadius(), c.getCenter().y() - c.getRadius(), c.getRadius() * 2, c.getRadius() * 2); return (T)or; }
Example #9
Source File: OvalRoiCircle2fConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public boolean canConvert(Object src, Type dest) { if(!(src instanceof OvalRoi)){ return false; } OvalRoi or = (OvalRoi)src; Rectangle rect = or.getPolygon().getBounds(); if (rect.width != rect.height) { return false; } return true; }
Example #10
Source File: OvalRoiCircle2fConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public < T> T convert(Object o, Class< T> type) { OvalRoi or = (OvalRoi) o; Rectangle rect = or.getPolygon().getBounds(); Circle2fCV c = new Circle2fCV(new opencv_core.Point2f(rect.x + rect.width / 2, rect.y + rect.height / 2), rect.width / 2); return (T) c; }
Example #11
Source File: OvalRoiCircleCVConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public boolean canConvert(Object src, Type dest) { if(!(src instanceof OvalRoi)){ return false; } OvalRoi or = (OvalRoi)src; Rectangle rect = or.getPolygon().getBounds(); if (rect.width != rect.height) { return false; } return true; }
Example #12
Source File: OvalRoiCircleCVConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public < T> T convert(Object o, Class< T> type) { OvalRoi or = (OvalRoi) o; Rectangle rect = or.getPolygon().getBounds(); CircleCV c = new CircleCV(new opencv_core.Point(rect.x + rect.width / 2, rect.y + rect.height / 2), rect.width / 2); return (T) c; }
Example #13
Source File: OvalRoiCircle2fConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 4 votes |
@Override public Class< OvalRoi> getInputType() { return OvalRoi.class; }
Example #14
Source File: ListOvalRoiMatConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 4 votes |
@Override public Class< List<OvalRoi>> getInputType() { return (Class<List<OvalRoi>>) (Object) List.class; }
Example #15
Source File: OvalRoiCircleCVConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 4 votes |
@Override public Class< OvalRoi> getInputType() { return OvalRoi.class; }
Example #16
Source File: OvalRoiRotatedRectConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 4 votes |
@Override public Class< OvalRoi> getInputType() { return OvalRoi.class; }
Example #17
Source File: CircleOvalRoiConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 4 votes |
@Override public Class< OvalRoi> getOutputType() { return OvalRoi.class; }
Example #18
Source File: MatListOvalRoiConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 4 votes |
@Override public Class< List<OvalRoi>> getOutputType() { return (Class<List<OvalRoi>>) (Object) List.class; }
Example #19
Source File: Circle2fOvalRoiConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 4 votes |
@Override public Class< OvalRoi> getOutputType() { return OvalRoi.class; }
Example #20
Source File: measureOxidationJ_.java From IJ-OpenCV with GNU General Public License v3.0 | 4 votes |
public double computeOxidation(ImagePlus imp, OvalRoi or) throws Exception { ImagePlusMatConverter ic = new ImagePlusMatConverter(); OvalRoiCircleCVConverter cc = new OvalRoiCircleCVConverter(); opencv_core.Mat newImage = ic.convert(imp,Mat.class); // Create mask opencv_core.Mat mask = new opencv_core.Mat(newImage.size(), CV_8UC1, opencv_core.Scalar.all(0)); CircleCV c = cc.convert(or,CircleCV.class); opencv_imgproc.circle(mask, c.getCenter(), c.getRadius(), new opencv_core.Scalar(255, 255, 255, 0), -1, 8, 0); // Image in LUV colorspace opencv_core.Mat imageLUV = new opencv_core.Mat(); opencv_imgproc.cvtColor(newImage, imageLUV, opencv_imgproc.COLOR_BGR2Luv); opencv_core.Mat hist = new opencv_core.Mat(); opencv_core.Mat blackHist = new opencv_core.Mat(); // Since C++ `calcHist` is using arrays of arrays we need wrap to do some wrapping // in `IntPointer` and `PointerPointer` objects. int[] channels = {0, 1, 2}; int[] bins = {8, 8, 8}; float[] ranges = {0.0f, 255.0f}; 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); opencv_imgproc.calcHist(imageLUV, 1, intPtrChannels, mask, hist, 3, intPtrHistSize, ptptranges, true, false); opencv_core.normalize(hist, hist); opencv_core.Mat newImage2 = new opencv_core.Mat(newImage.size(), CV_8UC1, opencv_core.Scalar.all(0)); opencv_imgproc.cvtColor(newImage2, newImage2, opencv_imgproc.COLOR_GRAY2BGR); opencv_imgproc.calcHist(newImage2, 1, intPtrChannels, mask, blackHist, 3, intPtrHistSize, ptptranges, true, false); opencv_core.normalize(blackHist, blackHist); return opencv_imgproc.compareHist(hist, blackHist, opencv_imgproc.CV_COMP_CHISQR); }
Example #21
Source File: measureOxidationJ_.java From IJ-OpenCV with GNU General Public License v3.0 | 4 votes |
@Override public void run() { try { OvalRoi or = (OvalRoi)imp.getRoi(); double oxidation = computeOxidation(imp, or); IJ.error("Oxidation level", ""+oxidation); } catch (Exception ex) { Logger.getLogger(measureOxidationJ_.class.getName()).log(Level.SEVERE, null, ex); } }
Example #22
Source File: DetectOxidationJ_.java From IJ-OpenCV with GNU General Public License v3.0 | 3 votes |
public OvalRoi detectROI(ImagePlus imp){ // Converter ImagePlusMatConverter ic = new ImagePlusMatConverter(); opencv_core.Mat newImage = ic.convert(imp,opencv_core.Mat.class); opencv_core.Mat hsv = new opencv_core.Mat(); opencv_imgproc.cvtColor(newImage,hsv,opencv_imgproc.COLOR_BGR2HSV); opencv_core.MatVector mv = new opencv_core.MatVector(3); split(hsv, mv); opencv_core.Mat thres = new opencv_core.Mat(); opencv_imgproc.threshold(mv.get(1), thres, 0, 255, opencv_imgproc.CV_THRESH_BINARY_INV + opencv_imgproc.CV_THRESH_OTSU); opencv_core.MatVector contours = new opencv_core.MatVector(); opencv_imgproc.findContours(thres,contours,opencv_imgproc.RETR_TREE,opencv_imgproc.CHAIN_APPROX_SIMPLE); opencv_core.Point2f c = new opencv_core.Point2f(); FloatPointer r = new FloatPointer(); opencv_imgproc.minEnclosingCircle(contours.get(1),c,r); // Circle converter Circle2fOvalRoiConverter cc =new Circle2fOvalRoiConverter(); OvalRoi or = cc.convert(new Circle2fCV(c,r.get(0)),OvalRoi.class); return or; }
Example #23
Source File: DetectOxidationJ_.java From IJ-OpenCV with GNU General Public License v3.0 | 3 votes |
@Override public void run() { OvalRoi or = detectROI(imp); imp.setRoi(or); }