/** @deprecated */ public Roi(int x, int y, int width, int height, ImagePlus imp) { this(x, y, width, height); setImage(imp); }
/** This method should only be called from an ImageWindow. */ public void setWindow(ImageWindow win) { this.win = win; if (roi!=null) roi.setImage(this); // update roi's 'ic' field }
/** This method should only be called from an ImageWindow. */ public void setWindow(ImageWindow win) { this.win = win; if (roi!=null) roi.setImage(this); // update roi's 'ic' field }
/** @deprecated */ public Roi(int x, int y, int width, int height, ImagePlus imp) { this(x, y, width, height); setImage(imp); }
void drawPreviousRoi(Graphics g) { if (previousRoi!=null && previousRoi!=this && previousRoi.modState!=NO_MODS) { if (type!=POINT && previousRoi.getType()==POINT && previousRoi.modState!=SUBTRACT_FROM_ROI) return; previousRoi.setImage(imp); previousRoi.draw(g); } }
void drawPreviousRoi(Graphics g) { if (previousRoi!=null && previousRoi!=this && previousRoi.modState!=NO_MODS) { if (type!=POINT && previousRoi.getType()==POINT && previousRoi.modState!=SUBTRACT_FROM_ROI) return; previousRoi.setImage(imp); previousRoi.draw(g); } }
/** Workaround for ImageJ's ImagePlus.flush() method which calls the System.gc() unnecessarily. * <p> * A null pointer as argument is accepted. * </p> */ static public final void flush(final ImagePlus imp) { if (null == imp) return; final Roi roi = imp.getRoi(); if (null != roi) roi.setImage(null); //final ImageProcessor ip = imp.getProcessor(); // the nullifying makes no difference, and in low memory situations some bona fide imagepluses may end up failing on the calling method because of lack of time to grab the processor etc. //if (null != ip) ip.setPixels(null); ipa.notifyListeners(imp, ipa.CLOSE); }
/**Returns the perimeter if this ShapeRoi can be decomposed into simple ROIs, otherwise returns zero. */ public double getLength() { if (width==0 && height==0) return 0.0; if (paPerim>0.0) return paPerim; double length = 0.0; Roi[] rois = getRois(); ImagePlus imp2 = getImage(); if (rois!=null) { for (int i=0; i<rois.length; i++) { Roi roi = rois[i]; if (roi instanceof ShapeRoi) return 0.0; roi.setImage(imp2); length += roi.getLength(); roi.setImage(null); } } return length; }
/** Draws the specified ROI on this image using the stroke width, stroke color and fill color defined by roi.setStrokeWidth, roi.setStrokeColor() and roi.setFillColor(). Works with RGB images. Does not work with 16-bit and float images. @see ImageProcessor#draw @see ImageProcessor#drawOverlay */ public void drawRoi(Roi roi) { Image img = createImage(); Graphics g = img.getGraphics(); ij.ImagePlus imp = roi.getImage(); if (imp!=null) { roi.setImage(null); roi.drawOverlay(g); roi.setImage(imp); } else roi.drawOverlay(g); }
/** Draws the specified ROI on this image using the stroke width, stroke color and fill color defined by roi.setStrokeWidth, roi.setStrokeColor() and roi.setFillColor(). Works with RGB images. Does not work with 16-bit and float images. @see ImageProcessor#draw @see ImageProcessor#drawOverlay */ public void drawRoi(Roi roi) { Image img = createImage(); Graphics g = img.getGraphics(); ij.ImagePlus imp = roi.getImage(); if (imp!=null) { roi.setImage(null); roi.drawOverlay(g); roi.setImage(imp); } else roi.drawOverlay(g); }
void drawRoi(Graphics g, Roi roi) { int type = roi.getType(); ImagePlus imp2 = roi.getImage(); roi.setImage(imp); Color saveColor = roi.getStrokeColor(); if (saveColor==null) roi.setStrokeColor(Toolbar.getForegroundColor()); if (roi instanceof TextRoi) ((TextRoi)roi).drawOverlay(g); else roi.drawOverlay(g); roi.setStrokeColor(saveColor); if (imp2!=null) roi.setImage(imp2); else roi.setImage(null); }
protected boolean updateROI(ImagePlus image) { Roi roi = image.getRoi(); if (roi == null || !(roi instanceof PolygonRoi)) { if (constructing && this.roi != null) return true; this.roi = null; return false; } if (this.roi == roi) return true; if (roi instanceof PolygonRoiPublic) this.roi = (PolygonRoiPublic)roi; else { this.roi = new PolygonRoiPublic((PolygonRoi)roi); image.setRoi(roi); roi.setImage(image); } return true; }
/** Sets the ImageProcessor, Roi, AWT Image and stack image arrays to null. Does nothing if the image is locked. */ public synchronized void flush() { notifyListeners(CLOSED); if (locked || ignoreFlush) return; ip = null; if (roi!=null) roi.setImage(null); roi = null; if (stack!=null && stack.viewers(-1)<=0) { Object[] arrays = stack.getImageArray(); if (arrays!=null) { for (int i=0; i<arrays.length; i++) arrays[i] = null; } if (isComposite()) ((CompositeImage)this).setChannelsUpdated(); //flush } setStackNull(); img = null; win = null; if (roi!=null) roi.setImage(null); roi = null; properties = null; //calibration = null; overlay = null; flatteningCanvas = null; }
/** Returns a copy of this roi. See Thinking is Java by Bruce Eckel (www.eckelobjects.com) for a good description of object cloning. */ public synchronized Object clone() { try { Roi r = (Roi)super.clone(); r.setImage(null); r.setStroke(getStroke()); r.setFillColor(getFillColor()); r.imageID = getImageID(); if (bounds!=null) r.bounds = (Rectangle2D.Double)bounds.clone(); return r; } catch (CloneNotSupportedException e) {return null;} }
/** Returns a copy of this roi. See Thinking is Java by Bruce Eckel (www.eckelobjects.com) for a good description of object cloning. */ public synchronized Object clone() { try { Roi r = (Roi)super.clone(); r.setImage(null); r.setStroke(getStroke()); r.setFillColor(getFillColor()); r.imageID = getImageID(); if (bounds!=null) r.bounds = (Rectangle2D.Double)bounds.clone(); return r; } catch (CloneNotSupportedException e) {return null;} }
public void select(int index, boolean shiftKeyDown, boolean altKeyDown) { if (!(shiftKeyDown||altKeyDown)) select(index); ImagePlus imp = IJ.getImage(); if (imp==null) return; Roi previousRoi = imp.getRoi(); if (previousRoi==null) { select(index); return; } Roi.previousRoi = (Roi)previousRoi.clone(); Roi roi = (Roi)rois.get(index); if (roi!=null) { roi.setImage(imp); roi.update(shiftKeyDown, altKeyDown); } }
public void select(int index, boolean shiftKeyDown, boolean altKeyDown) { if (!(shiftKeyDown||altKeyDown)) select(index); ImagePlus imp = IJ.getImage(); if (imp==null) return; Roi previousRoi = imp.getRoi(); if (previousRoi==null) { select(index); return; } Roi.previousRoi = (Roi)previousRoi.clone(); Roi roi = (Roi)rois.get(index); if (roi!=null) { roi.setImage(imp); roi.update(shiftKeyDown, altKeyDown); } }
public void restoreRoi() { if (Roi.previousRoi!=null) { Roi pRoi = Roi.previousRoi; Rectangle r = pRoi.getBounds(); if (r.width<=width||r.height<=height||(r.x<width&&r.y<height)||isSmaller(pRoi)) { // will it (mostly) fit in this image? roi = (Roi)pRoi.clone(); roi.setImage(this); if (r.x>=width || r.y>=height || (r.x+r.width)<0 || (r.y+r.height)<0) // does it need to be moved? roi.setLocation((width-r.width)/2, (height-r.height)/2); else if (r.width==width && r.height==height) // is it the same size as the image roi.setLocation(0, 0); draw(); roi.notifyListeners(RoiListener.CREATED); } } }
public void restoreRoi() { if (Roi.previousRoi!=null) { Roi pRoi = Roi.previousRoi; Rectangle r = pRoi.getBounds(); if (r.width<=width||r.height<=height||(r.x<width&&r.y<height)||isSmaller(pRoi)) { // will it (mostly) fit in this image? roi = (Roi)pRoi.clone(); roi.setImage(this); if (r.x>=width || r.y>=height || (r.x+r.width)<0 || (r.y+r.height)<0) // does it need to be moved? roi.setLocation((width-r.width)/2, (height-r.height)/2); else if (r.width==width && r.height==height) // is it the same size as the image roi.setLocation(0, 0); draw(); roi.notifyListeners(RoiListener.CREATED); } } }
public void setRoi(Rectangle r) { if (null==r) { killRoi(); return; } killRoi(); this.roi = new Roi(r.x, r.y, r.width, r.height); this.roi.setImage(this); ImagePlus imp = patch[currentSlice-1].getProject().getLoader().fetchImagePlus(patch[currentSlice-1]); ImageProcessor ip = imp.getProcessor(); if (null != ip) { ip.setMask(null); ip.setRoi(r); } //draw(); // not needed }