Java Code Examples for ij.gui.Roi#getBounds()
The following examples show how to use
ij.gui.Roi#getBounds() .
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: Segmentation.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
public void moveBlow(int dx, int dy) throws Exception { int x = box.width/2 + dx; int y = box.height/2 + dy; // Keep within bounds if (x < 0) x = 0; if (y < 0) y = 0; if (x > box.width -1) x = box.width -1; if (y > box.height -1) y = box.height -1; lasso.moveBlow(x, y); // extract ROI Roi roi = imp.getRoi(); if (null == roi) Display.getFront().getCanvas().getFakeImagePlus().setRoi(roi); // can't set to null? Java, gimme a break else { Roi sroi = new ShapeRoi(roi); Rectangle b = sroi.getBounds(); sroi.setLocation(box.x + b.x, box.y + b.y); Display.getFront().getCanvas().getFakeImagePlus().setRoi(sroi); } }
Example 2
Source File: RoiRectfConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public < T> T convert(Object o, Class< T> type) { Roi r =(Roi)o; Rectangle r1 = r.getBounds(); opencv_core.Rect2f rect = new opencv_core.Rect2f(r1.x, r1.y, r1.width, r1.height); return (T)rect; }
Example 3
Source File: RoiRectdConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public < T> T convert(Object o, Class< T> type) { Roi r =(Roi)o; Rectangle r1 = r.getBounds(); opencv_core.Rect2d rect = new opencv_core.Rect2d(r1.x, r1.y, r1.width, r1.height); return (T)rect; }
Example 4
Source File: RoiRectConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
@Override public < T> T convert(Object o, Class< T> type) { Roi r =(Roi)o; Rectangle r1 = r.getBounds(); Rect rect = new Rect(r1.x, r1.y, r1.width, r1.height); return (T)rect; }
Example 5
Source File: ResultsFilter.java From thunderstorm with GNU General Public License v3.0 | 5 votes |
public void restrictToROIFilter() { double mag = new EmptyRendererUI().magnification.getValue(); IJResultsTable rt = IJResultsTable.getResultsTable(); ImagePlus preview = rt.getPreviewImage(); Roi roi2 = null; if(preview != null) { roi2 = preview.getRoi(); } if(roi2 == null) { GUI.showBalloonTip(restrictToROIButton, "There is no ROI in the preview image!"); return; } Rectangle2D[] rectangleList; if(roi2 instanceof ShapeRoi) { ShapeRoi shapeRoi = (ShapeRoi) roi2; Roi[] roiList = shapeRoi.getRois(); rectangleList = new Rectangle2D[roiList.length]; for(int i = 0; i < roiList.length; i++) { rectangleList[i] = roiList[i].getBounds(); } } else { rectangleList = new Rectangle2D[]{roi2.getBounds()}; } Units ux = rt.getColumnUnits(LABEL_X); Units uy = rt.getColumnUnits(LABEL_Y); // for(int i = 0; i < rectangleList.length; i++) { rectangleList[i] = convertRectangleUnits(rectangleList[i], ux, uy, mag); } addNewRectanglesFilter(rectangleList); }
Example 6
Source File: Coloc_2.java From Colocalisation_Analysis with GNU General Public License v3.0 | 5 votes |
/** * Returns true if a custom ROI has been selected, i.e if the current ROI does * not have the extent of the whole image. * * @return true if custom ROI selected, false otherwise */ protected boolean hasValidRoi(final ImagePlus imp) { final Roi roi = imp.getRoi(); if (roi == null) return false; final Rectangle theROI = roi.getBounds(); // if the ROI is the same size as the image (default ROI), return false return (theROI.height != imp.getHeight() || theROI.width != imp.getWidth()); }
Example 7
Source File: Coloc_2.java From Colocalisation_Analysis with GNU General Public License v3.0 | 5 votes |
/** * Creates appropriate data structures from the ROI information * passed. If an irregular ROI is found, it will be put into a * frame of its bounding box size and put into an {@code Image<T>}. * * In the end the members ROIs, masks and maskBBs will be * filled if ROIs or masks were found. They will be null * otherwise. */ protected void createMasksAndRois(final Roi[] rois, final int width, final int height) { // create empty list masks.clear(); for (final Roi r : rois) { final MaskInfo mi = new MaskInfo(); // add it to the list of masks/ROIs masks.add(mi); // get the ROIs/masks bounding box final Rectangle rect = r.getBounds(); mi.roi = new BoundingBox(new long[] { rect.x, rect.y }, new long[] { rect.width, rect.height }); final ImageProcessor ipMask = r.getMask(); // check if we got a regular ROI and return if so if (ipMask == null) { continue; } // create a mask processor of the same size as a slice final ImageProcessor ipSlice = ipMask.createProcessor(width, height); // fill the new slice with black ipSlice.setValue(0.0); ipSlice.fill(); // position the mask on the new mask processor ipSlice.copyBits(ipMask, (int) mi.roi.offset[0], (int) mi.roi.offset[1], Blitter.COPY); // create an Image<T> out of it final ImagePlus maskImp = new ImagePlus("Mask", ipSlice); // and remember it and the masks bounding box mi.mask = ImagePlusAdapter.<T> wrap(maskImp); } }
Example 8
Source File: FakeImagePlus.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
public ImageStatistics getStatistics(int mOptions, int nBins, double histMin, double histMax) { Displayable active = display.getActive(); if (null == active || !(active instanceof Patch)) { Utils.log("No patch selected."); return super.getStatistics(mOptions, nBins, histMin, histMax); // TODO can't return null, but something should be done about it. } ImagePlus imp = active.getProject().getLoader().fetchImagePlus((Patch)active); ImageProcessor ip = imp.getProcessor(); // don't create a new onw every time // ((Patch)active).getProcessor(); Roi roi = super.getRoi(); if (null != roi) { // translate ROI to be meaningful for the Patch int patch_x = (int)active.getX(); int patch_y = (int)active.getY(); Rectangle r = roi.getBounds(); roi.setLocation(patch_x - r.x, patch_y - r.y); } ip.setRoi(roi); // even if null, to reset ip.setHistogramSize(nBins); Calibration cal = getCalibration(); if (getType()==GRAY16&& !(histMin==0.0&&histMax==0.0)) {histMin=cal.getRawValue(histMin); histMax=cal.getRawValue(histMax);} ip.setHistogramRange(histMin, histMax); ImageStatistics stats = ImageStatistics.getStatistics(ip, mOptions, cal); ip.setHistogramSize(256); ip.setHistogramRange(0.0, 0.0); return stats; }
Example 9
Source File: MatchIntensities.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
private static Rectangle getRoi( final LayerSet layerset ) { final Roi roi; final Display front = Display.getFront(); if ( front == null ) roi = null; else roi = front.getRoi(); if ( roi == null ) return new Rectangle( 0, 0, ( int ) layerset.getLayerWidth(), ( int ) layerset.getLayerHeight() ); else return roi.getBounds(); }
Example 10
Source File: RankFiltersOrbit.java From orbit-image-analysis with GNU General Public License v3.0 | 4 votes |
public int showDialog(ImagePlus imp, String command, PlugInFilterRunner pfr) { if (filterType == DESPECKLE) { filterType = MEDIAN; radius = 1.0; } else { GenericDialog gd = new GenericDialog(command+"..."); radius = lastRadius[filterType]<=0 ? 2 : lastRadius[filterType]; gd.addNumericField("Radius", radius, 1, 6, "pixels"); int digits = imp.getType() == ImagePlus.GRAY32 ? 2 : 0; if (filterType==OUTLIERS) { gd.addNumericField("Threshold", lastThreshold, digits); gd.addChoice("Which outliers", outlierStrings, outlierStrings[lastWhichOutliers]); gd.addHelp(IJ.URL+"/docs/menus/process.html#outliers"); } else if (filterType==REMOVE_NAN) gd.addHelp(IJ.URL+"/docs/menus/process.html#nans"); gd.addPreviewCheckbox(pfr); //passing pfr makes the filter ready for preview gd.addDialogListener(this); //the DialogItemChanged method will be called on user input gd.showDialog(); //display the dialog; preview runs in the now if (gd.wasCanceled()) return DONE; IJ.register(this.getClass()); //protect static class variables (filter parameters) from garbage collection if (Macro.getOptions() == null) { //interactive only: remember parameters entered lastRadius[filterType] = radius; if (filterType == OUTLIERS) { lastThreshold = threshold; lastWhichOutliers = whichOutliers; } } } this.pfr = pfr; flags = IJ.setupDialog(imp, flags); //ask whether to process all slices of stack (if a stack) if ((flags&DOES_STACKS)!=0) { int size = imp.getWidth() * imp.getHeight(); Roi roi = imp.getRoi(); if (roi != null) { Rectangle roiRect = roi.getBounds(); size = roiRect.width * roiRect.height; } double workToDo = size*(double)radius; //estimate computing time (arb. units) if (filterType==MEAN || filterType==VARIANCE) workToDo *= 0.5; else if (filterType==MEDIAN) workToDo *= radius*0.5; if (workToDo < 1e6 && imp.getImageStackSize()>=numThreads) { numThreads = 1; //for fast operations, avoid overhead of multi-threading in each image flags |= PARALLELIZE_STACKS; } } return flags; }
Example 11
Source File: PairWiseStitchingImgLib.java From Stitching with GNU General Public License v2.0 | 4 votes |
/** * return an {@code Image<T>} as input for the PhaseCorrelation. * * @param imp - the {@link ImagePlus} * @param imgFactory - the {@link ImageFactory} defining wher to put it into * @param channel - which channel (if channel=0 means average all channels) * @param timepoint - which timepoint * * @return - the {@link Image} or null if it was not an ImagePlus.GRAY8, ImagePlus.GRAY16 or ImagePlus.GRAY32 */ public static < T extends RealType<T> > Image<T> getImage( final ImagePlus imp, Roi roi, final ImageFactory<T> imgFactory, final int channel, final int timepoint ) { // first test the roi roi = getOnlyRectangularRoi( roi ); // how many dimensions? final int numDimensions; if ( imp.getNSlices() > 1 ) numDimensions = 3; else numDimensions = 2; // the size of the image final int[] size = new int[ numDimensions ]; final int[] offset = new int[ numDimensions ]; if ( roi == null ) { size[ 0 ] = imp.getWidth(); size[ 1 ] = imp.getHeight(); if ( numDimensions == 3 ) size[ 2 ] = imp.getNSlices(); } else { size[ 0 ] = roi.getBounds().width; size[ 1 ] = roi.getBounds().height; offset[ 0 ] = roi.getBounds().x; offset[ 1 ] = roi.getBounds().y; if ( numDimensions == 3 ) size[ 2 ] = imp.getNSlices(); } // create the Image final Image<T> img = imgFactory.createImage( size ); final boolean success; // copy the content if ( channel == 0 ) { // we need to average all channels success = averageAllChannels( img, offset, imp, timepoint ); } else { // otherwise only copy one channel success = fillInChannel( img, offset, imp, channel, timepoint ); } if ( success ) { return img; } img.close(); return null; }