ImageProcessor duplicateProcessor(ImageProcessor ip, Rectangle roi) { ImageProcessor ip2 = (ImageProcessor)ip.clone(); ip2.setRoi(roi); return ip2; }
/** Defines a rectangular region of interest and sets the mask to null if this ROI is not the same size as the previous one. @see ImageProcessor#resetRoi */ public void setRoi(Rectangle roi) { if (roi==null) resetRoi(); else setRoi(roi.x, roi.y, roi.width, roi.height); }
/** Defines a rectangular region of interest and sets the mask to null if this ROI is not the same size as the previous one. @see ImageProcessor#resetRoi */ public void setRoi(Rectangle roi) { if (roi==null) resetRoi(); else setRoi(roi.x, roi.y, roi.width, roi.height); }
public void setRoi(int x, int y, int rwidth, int rheight) { record("setRoi", new Object[] {new Integer(x), new Integer(y), new Integer(rwidth), new Integer(rheight)}, new Class[] {int.class, int.class, int.class, int.class}); proc.setRoi(x, y, rwidth, rheight); }
public void setRoi(int x, int y, int rwidth, int rheight) { record("setRoi", new Object[] {new Integer(x), new Integer(y), new Integer(rwidth), new Integer(rheight)}, new Class[] {int.class, int.class, int.class, int.class}); proc.setRoi(x, y, rwidth, rheight); }
public void setRoi(Polygon roi) { record("setRoi", roi, Polygon.class); proc.setRoi(roi); }
/** Fills a rectangle. */ public void fillRect(int x, int y, int width, int height) { setRoi(x, y, width, height); fill(); resetRoi(); }
void drawFilledParticle(ImageProcessor ip, Roi roi, ImageProcessor mask) { ip.setRoi(roi.getBounds()); ip.fill(mask); }
private void drawRoundedRect(ImageProcessor ip) { int margin = (int)getStrokeWidth()/2; BufferedImage bi = new BufferedImage(width+margin*2+1, height+margin*2+1, BufferedImage.TYPE_BYTE_GRAY); Graphics2D g = bi.createGraphics(); if (stroke!=null) g.setStroke(stroke); g.drawRoundRect(margin, margin, width, height, cornerDiameter, cornerDiameter); ByteProcessor mask = new ByteProcessor(bi); ip.setRoi(x-margin, y-margin, width+margin*2+1, height+margin*2+1); ip.fill(mask); }
// works all the same for: byte, short, int float[] myData; // create a new image. change 32 to 16 for short or 8 for byte ImageStack stack = ImageStack.create(width, height, 1, 32); stack.setPixels(myData, 1); ImageProcessor processor = new ImagePlus("", stack).getProcessor(); // crop and scale processor.setRoi(x, y, rwidth, rheight); ImageProcessor result = processor.crop().resize(newWidth, newHeight); // retrieve results float[] myScaledData = (float[]) result.getPixels();
public ImageStatistics getRawStatistics() { if (roi!=null && roi.isArea()) ip.setRoi(roi); else ip.resetRoi(); return ImageStatistics.getStatistics(ip, AREA+MEAN+MODE+MIN_MAX, null); }
/** Fills a polygon. */ public void fillPolygon(Polygon p) { setRoi(p); fill(getMask()); resetRoi(); }
void drawRoiFilledParticle(ImageProcessor ip, Roi roi, ImageProcessor mask, int count) { int grayLevel = (count < 65535) ? count : 65535; ip.setValue((double) grayLevel); ip.setRoi(roi.getBounds()); ip.fill(mask); }
/** Performs a convolution operation using the specified kernel. */ public void convolve(float[] kernel, int kernelWidth, int kernelHeight) { ImageProcessor ip2 = convertToFloat(); ip2.setRoi(getRoi()); new ij.plugin.filter.Convolver().convolve(ip2, kernel, kernelWidth, kernelHeight); ip2 = ip2.convertToByte(false); byte[] pixels2 = (byte[])ip2.getPixels(); System.arraycopy(pixels2, 0, pixels, 0, pixels.length); }
ImageStatistics getRedirectStats(int measurements, Roi roi) { ImagePlus redirectImp = getRedirectImageOrStack(imp); if (redirectImp==null) return null; ImageProcessor ip = redirectImp.getProcessor(); if (imp.getTitle().equals("mask") && imp.getBitDepth()==8) { ip.setMask(imp.getProcessor()); ip.setRoi(0, 0, imp.getWidth(), imp.getHeight()); } else ip.setRoi(roi); return ImageStatistics.getStatistics(ip, measurements, redirectImp.getCalibration()); }
ImageStatistics getRedirectStats(int measurements, Roi roi) { ImagePlus redirectImp = getRedirectImageOrStack(imp); if (redirectImp==null) return null; ImageProcessor ip = redirectImp.getProcessor(); if (imp.getTitle().equals("mask") && imp.getBitDepth()==8) { ip.setMask(imp.getProcessor()); ip.setRoi(0, 0, imp.getWidth(), imp.getHeight()); } else ip.setRoi(roi); return ImageStatistics.getStatistics(ip, measurements, redirectImp.getCalibration()); }
/** Performs a convolution operation using the specified kernel. */ public void convolve(float[] kernel, int kernelWidth, int kernelHeight) { ImageProcessor ip2 = convertToFloat(); ip2.setRoi(getRoi()); new ij.plugin.filter.Convolver().convolve(ip2, kernel, kernelWidth, kernelHeight); ip2 = ip2.convertToShort(false); short[] pixels2 = (short[])ip2.getPixels(); System.arraycopy(pixels2, 0, pixels, 0, pixels.length); }
/** Creates a new stack by cropping this one. */ public ImageStack crop(int x, int y, int z, int width, int height, int depth) { if (x<0||y<0||z<0||x+width>this.width||y+height>this.height||z+depth>getSize()) throw new IllegalArgumentException("Argument out of range"); ImageStack stack2 = new ImageStack(width, height, getColorModel()); for (int i=z; i<z+depth; i++) { ImageProcessor ip2 = this.getProcessor(i+1); ip2.setRoi(x, y, width, height); ip2 = ip2.crop(); stack2.addSlice(this.getSliceLabel(i+1), ip2); } return stack2; }
double getColorValue(Color color) { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null || imp.getBitDepth()==24) return color.getRGB()&0xffffff; ImageProcessor ip = imp.getProcessor(); ip.setRoi(0,0,1,1); ip = ip.crop(); ip.setColor(color); ip.drawDot(0,0); return ip.getf(0,0); }
/** 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); } }