@Override public Rectangle getRoi() { record("getRoi"); return proc.getRoi(); }
@Override public Rectangle getRoi() { record("getRoi"); return proc.getRoi(); }
/** Fits an ellipse to the current ROI. The 'stats' argument, currently not used, can be null. The fit parameters are returned in public fields. */ public void fit(ImageProcessor ip, ImageStatistics stats) { this.ip = ip; mask = ip.getMaskArray(); Rectangle r = ip.getRoi(); left = r.x; top = r.y; width = r.width; height = r.height; getEllipseParam(); }
/** Fits an ellipse to the current ROI. The 'stats' argument, currently not used, can be null. The fit parameters are returned in public fields. */ public void fit(ImageProcessor ip, ImageStatistics stats) { this.ip = ip; mask = ip.getMaskArray(); Rectangle r = ip.getRoi(); left = r.x; top = r.y; width = r.width; height = r.height; getEllipseParam(); }
/** This method is invoked for each slice during execution * @param ip The image subject to filtering. It must have a valid snapshot if * the height of the roi is less than the full image height. */ public void run(ImageProcessor ip) { double sigmaX = sigmaScaled ? sigma/imp.getCalibration().pixelWidth : sigma; double sigmaY = sigmaScaled ? sigma/imp.getCalibration().pixelHeight : sigma; double accuracy = (ip instanceof ByteProcessor || ip instanceof ColorProcessor) ? 0.002 : 0.0002; Rectangle roi = ip.getRoi(); blurGaussian(ip, sigmaX, sigmaY, accuracy); }
/** This method is invoked for each slice during execution * @param ip The image subject to filtering. It must have a valid snapshot if * the height of the roi is less than the full image height. */ public void run(ImageProcessor ip) { double sigmaX = sigmaScaled ? sigma/imp.getCalibration().pixelWidth : sigma; double sigmaY = sigmaScaled ? sigma/imp.getCalibration().pixelHeight : sigma; double accuracy = (ip instanceof ByteProcessor || ip instanceof ColorProcessor) ? 0.002 : 0.0002; Rectangle roi = ip.getRoi(); blurGaussian(ip, sigmaX, sigmaY, accuracy); }
/** Set the processed pixels above and below the roi rectangle back to their * previous value (i.e., snapshot buffer). This is necessary since ImageJ * only restores out-of-roi pixels inside the enclosing rectangle of the roi * (If the roi is non-rectangular and the SUPPORTS_MASKING flag is set). * @param ip The image to be processed * @param radius The range above and below the roi that should be processed */ public static void resetOutOfRoi(ImageProcessor ip, int radius) { Rectangle roi = ip.getRoi(); int width = ip.getWidth(); int height = ip.getHeight(); Object pixels = ip.getPixels(); Object snapshot = ip.getSnapshotPixels(); int y0 = roi.y-radius; // the first line that should be reset if (y0<0) y0 = 0; for (int y=y0,p=width*y+roi.x; y<roi.y; y++,p+=width) System.arraycopy(snapshot, p, pixels, p, roi.width); int yEnd = roi.y+roi.height+radius; // the last line + 1 that should be reset if (yEnd>height) yEnd = height; for (int y=roi.y+roi.height,p=width*y+roi.x; y<yEnd; y++,p+=width) System.arraycopy(snapshot, p, pixels, p, roi.width); }
/** Gaussian Filtering of an ImageProcessor. This method is for compatibility with the * previous code (before 1.38r) and uses a low-accuracy kernel, only slightly better * than the previous ImageJ code. * The 'radius' in this call is different from the one used in ImageJ 1.38r and later. * Therefore, use blurGaussian(ip, sigma, sigma, accuracy), where 'sigma' is equivalent * to the 'sigma (radius)' of the Menu, and accuracy should be 0.02 unless better * accuracy is desired. */ @Deprecated public boolean blur(ImageProcessor ip, double radius) { Rectangle roi = ip.getRoi(); if (roi.height!=ip.getHeight() && ip.getMask()==null) ip.snapshot(); // a snapshot is needed for out-of-Rectangle pixels blurGaussian(ip, 0.4*radius, 0.4*radius, 0.01); return true; }
/** Gaussian Filtering of an ImageProcessor. This method is for compatibility with the * previous code (before 1.38r) and uses a low-accuracy kernel, only slightly better * than the previous ImageJ code. * The 'radius' in this call is different from the one used in ImageJ 1.38r and later. * Therefore, use blurGaussian(ip, sigma, sigma, accuracy), where 'sigma' is equivalent * to the 'sigma (radius)' of the Menu, and accuracy should be 0.02 unless better * accuracy is desired. */ @Deprecated public boolean blur(ImageProcessor ip, double radius) { Rectangle roi = ip.getRoi(); if (roi.height!=ip.getHeight() && ip.getMask()==null) ip.snapshot(); // a snapshot is needed for out-of-Rectangle pixels blurGaussian(ip, 0.4*radius, 0.4*radius, 0.01); return true; }
/** Creates a ResultsTable from an image or image selection. */ public static ResultsTable createTableFromImage(ImageProcessor ip) { ResultsTable rt = new ResultsTable(); Rectangle r = ip.getRoi(); for (int y=r.y; y<r.y+r.height; y++) { rt.incrementCounter(); rt.addLabel(" ", "Y"+y); for (int x=r.x; x<r.x+r.width; x++) rt.addValue("X"+x, ip.getPixelValue(x,y)); } return rt; }
/** Creates a ResultsTable from an image or image selection. */ public static ResultsTable createTableFromImage(ImageProcessor ip) { ResultsTable rt = new ResultsTable(); Rectangle r = ip.getRoi(); for (int y=r.y; y<r.y+r.height; y++) { rt.incrementCounter(); rt.addLabel(" ", "Y"+y); for (int x=r.x; x<r.x+r.width; x++) rt.addValue("X"+x, ip.getPixelValue(x,y)); } return rt; }
/** Restore image outside non-rectangular roi. */ void doMasking(ImagePlus imp, ImageProcessor ip) { ImageProcessor mask = imp.getMask(); if (mask!=null) { Rectangle r = ip.getRoi(); if (mask.getWidth()!=r.width||mask.getHeight()!=r.height) { ip.setRoi(imp.getRoi()); mask = ip.getMask(); } ip.reset(mask); } }
/** Restore image outside non-rectangular roi. */ void doMasking(ImagePlus imp, ImageProcessor ip) { ImageProcessor mask = imp.getMask(); if (mask!=null) { Rectangle r = ip.getRoi(); if (mask.getWidth()!=r.width||mask.getHeight()!=r.height) { ip.setRoi(imp.getRoi()); mask = ip.getMask(); } ip.reset(mask); } }
public void add(ImageProcessor ip, double percent) { Rectangle roi = ip.getRoi(); int n = (int)(percent*roi.width*roi.height); byte[] pixels = (byte[])ip.getPixels(); int rx, ry; int width = ip.getWidth(); int xmin = roi.x; int xmax = roi.x+roi.width; int ymin = roi.y; int ymax = roi.y+roi.height; for (int i=0; i<n/2; i++) { rx = rand(xmin, xmax); ry = rand(ymin, ymax); pixels[ry*width+rx] = (byte)255; rx = rand(xmin, xmax); ry = rand(ymin, ymax); pixels[ry*width+rx] = (byte)0; } } }
public void clear(ImageProcessor ip) { if (instanceFont==null) ip.fill(); else { ip.setFont(instanceFont); ip.setAntialiasedText(antialiasedText); int i=0, width=0; while (i<MAX_LINES && theText[i]!=null) { int w = ip.getStringWidth(theText[i]); if (w>width) width = w; i++; } Rectangle r = ip.getRoi(); if (width>r.width) { r.width = width; ip.setRoi(r); } ip.fill(); } }
public void clear(ImageProcessor ip) { if (instanceFont==null) ip.fill(); else { ip.setFont(instanceFont); ip.setAntialiasedText(antialiasedText); int i=0, width=0; while (i<MAX_LINES && theText[i]!=null) { int w = ip.getStringWidth(theText[i]); if (w>width) width = w; i++; } Rectangle r = ip.getRoi(); if (width>r.width) { r.width = width; ip.setRoi(r); } ip.fill(); } }
private void applyRoiAsFilter() { Rectangle roi = this.imp.getProcessor().getRoi(); int left = max(frame.x, roi.x) - frame.x; int right = min((frame.x + frame.width - 1), (roi.x + roi.width - 1)) - frame.x; int indexLeft = (int) (left * ((double) histogram.length) / HIST_WIDTH); int indexRight = (int) (right * ((double) histogram.length) / HIST_WIDTH); double leftVal = cal.getCValue(stats.histMin + indexLeft * stats.binSize); // param > val double rightVal = cal.getCValue(stats.histMin + indexRight * stats.binSize); // param < val IJResultsTable.getResultsTable().tableWindow.getFilter().addNewFilter(paramName, leftVal, rightVal); } }
/** Fills outside an Roi. */ public void fillOutside(Roi roi) { if (roi==null || !roi.isArea()) return; ImageProcessor m = getMask(); Rectangle r = getRoi(); ShapeRoi s1, s2; if (roi instanceof ShapeRoi) s1 = (ShapeRoi)roi; else s1 = new ShapeRoi(roi); s2 = new ShapeRoi(new Roi(0,0, width, height)); setRoi(s1.xor(s2)); fill(getMask()); setMask(m); setRoi(r); }
/** Fills the ROI with the current fill/draw value. * @see #setColor(Color) * @see #setValue(double) * @see #fill(Roi) */ public void fill(Roi roi) { if (roi!=null && roi.isLine()) { if ((roi instanceof Line) && roi.getStrokeWidth()>1 && !(roi instanceof Arrow)) fillPolygon(roi.getPolygon()); else roi.drawPixels(this); return; } ImageProcessor m = getMask(); Rectangle r = getRoi(); setRoi(roi); fill(getMask()); setMask(m); setRoi(r); }
/** Fills outside an Roi. */ public void fillOutside(Roi roi) { if (roi==null || !roi.isArea()) return; ImageProcessor m = getMask(); Rectangle r = getRoi(); ShapeRoi s1, s2; if (roi instanceof ShapeRoi) s1 = (ShapeRoi)roi; else s1 = new ShapeRoi(roi); s2 = new ShapeRoi(new Roi(0,0, width, height)); setRoi(s1.xor(s2)); fill(getMask()); setMask(m); setRoi(r); }