private ImageRoi getOverlayImage(ImagePlus imp) { if (!paintOnOverlay) return null; Overlay overlay = imp.getOverlay(); if (overlay==null) return null; Roi roi = overlay.get("[Brush]"); if (roi==null||!(roi instanceof ImageRoi)) return null; Rectangle bounds = roi.getBounds(); if (bounds.x!=0||bounds.y!=0||bounds.width!=imp.getWidth()||bounds.height!=imp.getHeight()) return null; return (ImageRoi)roi; }
void showInternalClipboard() { ImagePlus clipboard = ImagePlus.getClipboard(); if (clipboard!=null) { ImageProcessor ip = clipboard.getProcessor(); ImagePlus imp2 = new ImagePlus("Clipboard", ip.duplicate()); Roi roi = clipboard.getRoi(); imp2.deleteRoi(); if (roi!=null && roi.isArea() && roi.getType()!=Roi.RECTANGLE) { roi = (Roi)roi.clone(); roi.setLocation(0, 0); imp2.setRoi(roi); IJ.run(imp2, "Clear Outside", null); imp2.deleteRoi(); } WindowManager.checkForDuplicateName = true; imp2.show(); } else IJ.error("The internal clipboard is empty."); }
void sixteenBitsToRGB(ImagePlus imp) { Roi roi = imp.getRoi(); int width, height; Rectangle r; if (roi!=null) { r = roi.getBounds(); width = r.width; height = r.height; } else r = new Rectangle(0,0,imp.getWidth(),imp.getHeight()); ImageProcessor ip; ImageStack stack1 = imp.getStack(); ImageStack stack2 = new ImageStack(r.width, r.height); for (int i=1; i<=stack1.getSize(); i++) { ip = stack1.getProcessor(i); ip.setRoi(r); ImageProcessor ip2 = ip.crop(); ip2 = ip2.convertToByte(true); stack2.addSlice(null, ip2); } ImagePlus imp2 = imp.createImagePlus(); imp2.setStack(imp.getTitle()+" (RGB)", stack2); ImageConverter ic = new ImageConverter(imp2); ic.convertRGBStackToRGB(); imp2.show(); }
float [][] a = new float[imp.getStackSize()][]; try{ int width = imp.getWidth(); int height = imp.getHeight(); int x = 0; int y = 0; if (imp.getRoi() != null) Rectangle roiRect = imp.getRoi().getBoundingRect(); width = roiRect.width; height = roiRect.height; x = roiRect.x; y = roiRect.y; IJ.showStatus("reading images "+width+" x "+height); for (int i = 0; i < imp.getStackSize(); i++) ImageProcessor ipp = imp.getStack().getProcessor(i+1); if (imp.getRoi() != null) ipp.setRoi(x, y, width, height); ipp = ipp.crop(); a[i] = (float []) (ipp.convertToFloat()).getPixels(); }catch (Exception e) { CharArrayWriter c = new CharArrayWriter(); e.printStackTrace(new PrintWriter(c)); IJ.write(c.toString()); } return a;
@Override final protected void init() switch( imp.getType() ) integral = new DoubleIntegralImage( imp.getProcessor() ); break; case ImagePlus.GRAY8: case ImagePlus.GRAY16: integral = new LongIntegralImage( imp.getProcessor() ); break; case ImagePlus.COLOR_RGB: break; default: IJ.error( "Type not yet supported." ); return; ipCopy = imp.getProcessor().duplicate(); else roi = new Roi( imp.getWidth() / 4, imp.getHeight() / 4, imp.getWidth() / 2, imp.getHeight() / 2 ); imp.setRoi( roi );
if (imp.getStackSize() > 1) ipp = imp.getStack().getProcessor(i+1); else ipp = imp.getProcessor(); float [] a = null; try if (imp.getRoi() != null) Rectangle roiRect = imp.getRoi().getBoundingRect(); width = roiRect.width; height = roiRect.height; x = roiRect.x; y = roiRect.y; ipp.setRoi(x, y, width, height); ipp = ipp.crop(); a = getFloatPixels(ipp.getPixels()); catch (Exception e) { CharArrayWriter c = new CharArrayWriter(); e.printStackTrace(new PrintWriter(c)); IJ.write(c.toString()); } return a;
if (ip==null) return; int width = ip.getWidth(); int height = ip.getHeight(); if (width!=2 || height<3) { IJ.showMessage("XY Reader", "Two column text file required"); return; double length = 0.0; for (int i=0; i<height; i++) { x[i] = ip.getf(0, i); y[i] = ip.getf(1, i); if ((int)x[i]!=x[i] || (int)y[i]!=y[i]) int type = length/x.length>10?Roi.POLYGON:Roi.FREEROI; if (allIntegers) roi = new PolygonRoi(Roi.toIntR(x), Roi.toIntR(y), height, type); else roi = new PolygonRoi(x, y, height, type); Rectangle r = roi.getBoundingRect(); ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null || imp.getWidth()<r.x+r.width || imp.getHeight()<r.y+r.height) { new ImagePlus(tr.getName(), new ByteProcessor(Math.abs(r.x)+r.width+10, Math.abs(r.y)+r.height+10)).show(); imp = WindowManager.getCurrentImage();
public void run(ImagePlus image, Roi[] rois) { w = image.getWidth(); h = image.getHeight(); ImageStack stack = new ImageStack(w, h); int firstIndex = -1, lastIndex = -1; for(int i = 1; i < rois.length; i++) { IJ.error("There must be at least one selection in order to interpolate."); return; ByteProcessor bp = new ByteProcessor(w, h); if(rois[i] != null) { bp.copyBits(rois[i].getMask(), rois[i].getBounds().x, rois[i].getBounds().y, ij.process.Blitter.ADD); stack.addSlice("", bp); ImagePlus roiImage = new ImagePlus("bla", stack); ImageProcessor bp = stack.getProcessor(1); stack.deleteSlice(1); int threshold = 255; bp.setThreshold(threshold, threshold, ImageProcessor.NO_LUT_UPDATE); ts.run(bp); rois[i] = roiImage.getRoi();
ImageProcessor getSlice(ImagePlus imp, double x1, double y1, double x2, double y2, String status) { Roi roi = imp.getRoi(); int roiType = roi!=null?roi.getType():0; ImageStack stack = imp.getStack(); int stackSize = stack.getSize(); ImageProcessor ip,ip2=null; float[] line = null; for (int i=0; i<stackSize; i++) { ip = stack.getProcessor(i+1); line = getLine(ip, x1, y1, x2, y2, line); if (i==0) ip2 = ip.createProcessor(line.length, stackSize); putRow(ip2, 0, i, line, line.length); if (status!=null) IJ.showStatus("Slicing: "+status +i+"/"+stackSize); } Calibration cal = imp.getCalibration(); double zSpacing = inputZSpacing/cal.pixelWidth; if (zSpacing!=1.0) { ip2.setInterpolate(true); ip2 = ip2.resize(line.length, (int)(stackSize*zSpacing)); } return ip2; }
public void openRoi(String dir, String name) throws IOException { String path = dir+name; RoiDecoder rd = new RoiDecoder(path); Roi roi = rd.getRoi(); Rectangle r = roi.getBounds(); ImagePlus img = WindowManager.getCurrentImage(); if (img==null || img.getWidth()<(r.x+r.width) || img.getHeight()<(r.y+r.height)) { ImageProcessor ip = new ByteProcessor(r.x+r.width+10, r.y+r.height+10); img = new ImagePlus(name, ip); img.show(); } img.setRoi(roi); }
if (getStackSize()>1 && getStack().isVirtual()) return; FileInfo fi = getOriginalFileInfo(); boolean isFileInfo = fi!=null && fi.fileFormat!=FileInfo.UNKNOWN; if (!isFileInfo && url==null) if (fi.directory==null && url==null) return; if (ij!=null && changes && isFileInfo && !Interpreter.isBatchMode() && !IJ.isMacro() && !IJ.altKeyDown()) { if (!IJ.showMessageWithCancel("Revert?", "Revert to saved version of\n\""+getTitle()+"\"?")) return; roi.endPaste(); saveRoi = (Roi)roi.clone(); trimProcessor(); new FileOpener(fi).revertToSaved(this); if (Prefs.useInvertingLut && getBitDepth()==8 && ip!=null && !ip.isInvertedLut()&& !ip.isColorLut()) invertLookupTable(); if (getProperty("FHT")!=null) {
@Override public void run(int i) { ImageProcessor ip = stack.getProcessor(i); ip.setRoi(roi.getBounds()); FloatProcessor fp = (FloatProcessor) ip.crop().convertToFloat(); fp.setMask(roi.getMask()); Thresholder.setCurrentImage(fp); List<Molecule> fits = threadLocalEstimatorUI.getThreadLocalImplementation().estimateParameters(fp, Point.applyRoiMask(roi, selectedDetectorUI.getThreadLocalImplementation().detectMoleculeCandidates(selectedFilterUI.getThreadLocalImplementation().filterImage(fp)))); framesProcessed.incrementAndGet(); for (Molecule psf : fits) { double s1 = psf.getParam(LABEL_SIGMA1); double s2 = psf.getParam(LABEL_SIGMA2); double ratio = s1 / s2; if (ratio > 2 || ratio < 0.5) { continue; } if (ratio < 1.2 && ratio > 0.83) { continue; } angles.add(psf.getParam(LABEL_ANGLE)); } IJ.showProgress(0.45 * (double) framesProcessed.intValue() / (double) stack.getSize()); IJ.showStatus("Determining angle: frame " + framesProcessed + " of " + stack.getSize() + "..."); } });
public static String getAverageCIELAB() { Average_Color t = new Average_Color(); try { t.image = WindowManager.getCurrentImage(); t.pixels = (int[])t.image.getProcessor().getPixels(); t.w = t.image.getWidth(); t.h = t.image.getHeight(); Roi roi = t.image.getRoi(); if (roi == null) roi = new Roi(0, 0, t.w, t.h); float[] result = t.getAverageColor(roi, true); return "" + result[0] + " " + result[1] + " " + result[2]; } catch (Exception e) { return ""; } }
void invert(ImagePlus imp) { Roi roi = imp.getRoi(); if (roi==null || !roi.isArea()) {IJ.error("Inverse", "Area selection required"); return;} ShapeRoi s1, s2; if (roi instanceof ShapeRoi) s1 = (ShapeRoi)roi; else s1 = new ShapeRoi(roi); s2 = new ShapeRoi(new Roi(0,0, imp.getWidth(), imp.getHeight())); Undo.setup(Undo.ROI, imp); imp.setRoi(s1.xor(s2)); }
private FloatProcessor getRoiProcessor(ImagePlus imp, Roi roi, int index) { ImageProcessor ip = imp.getStack().getProcessor(index); ip.setRoi(roi.getBounds()); FloatProcessor fp = subtract(ip.crop().convertToFloatProcessor(), (float) CameraSetupPlugIn.getOffset()); float minVal = VectorMath.min((float[]) fp.getPixels()); if(minVal < 0) { IJ.log("\\Update:Camera base level is set higher than values in the image!"); fp = add(-minVal, fp); } fp.setMask(roi.getMask()); return fp; }
public void mouseReleased(MouseEvent e) { super.mouseReleased(e); Roi roi = imp.getRoi(); if (roi!=null && roi.getType()==Roi.LINE) { Undo.setup(Undo.FILTER, imp); imp.getProcessor().snapshot(); roi.drawPixels(); imp.updateAndDraw(); imp.deleteRoi(); } }