public int setup(String arg, ImagePlus imp) { IJ.register(Debayer_Image.class); if (IJ.versionLessThan("1.32c")) return DONE; imp.unlock(); this.imp = imp; this.algorithm = Integer.parseInt(arg); return DOES_16; }
/** * This method draws the rectangle * @param imp the ImagePlus on to which to draw the bounds */ public void drawBounds(ImagePlus imp){ double w = x1-x0+1; double h = y1-y0+1; boolean isLocked = imp.isLocked(); if (isLocked == true) {imp.unlock();} IJ.run("Specify...", "width="+ Math.round(w)+ " height="+ Math.round(h)+ " x="+ Math.round(x0)+ " y="+ Math.round(y0)); IJ.run("Draw"); if (isLocked == true) {imp.lock();} if (bverbose){ IJ.log("w="+w+" h="+h+" x="+ x0+" y="+y0); } }
/** * This method will draw the center of the box * @param imp the ImagePlus onto which to draw the center */ public void drawCenter(ImagePlus imp){ double c[] = getCenter(); boolean isLocked = imp.isLocked(); if (isLocked == true) {imp.unlock();} IJ.setTool(Toolbar.POINT); IJ.makePoint( (int) Math.round(c[0]), (int) Math.round(c[1])); IJ.run("Draw"); if (isLocked == true) {imp.lock();} }
/** Runs the specified macro on the current thread. Macros can retrieve the optional string argument by calling the getArgument() macro function. Returns the string value returned by the macro, null if the macro does not return a value, or "[aborted]" if the macro was aborted due to an error. */ public String runMacro(String macro, String arg) { Interpreter interp = new Interpreter(); try { return interp.run(macro, arg); } catch(Throwable e) { interp.abortMacro(); IJ.showStatus(""); IJ.showProgress(1.0); ImagePlus imp = WindowManager.getCurrentImage(); if (imp!=null) imp.unlock(); String msg = e.getMessage(); if (e instanceof RuntimeException && msg!=null && e.getMessage().equals(Macro.MACRO_CANCELED)) return "[aborted]"; IJ.handleException(e); } return "[aborted]"; }
/** Runs the specified macro on the current thread. Macros can retrieve the optional string argument by calling the getArgument() macro function. Returns the string value returned by the macro, null if the macro does not return a value, or "[aborted]" if the macro was aborted due to an error. */ public String runMacro(String macro, String arg) { Interpreter interp = new Interpreter(); try { return interp.run(macro, arg); } catch(Throwable e) { interp.abortMacro(); IJ.showStatus(""); IJ.showProgress(1.0); ImagePlus imp = WindowManager.getCurrentImage(); if (imp!=null) imp.unlock(); String msg = e.getMessage(); if (e instanceof RuntimeException && msg!=null && e.getMessage().equals(Macro.MACRO_CANCELED)) return "[aborted]"; IJ.handleException(e); } return "[aborted]"; }
/** Closes the window, if any, that is displaying this image. */ public void hide() { if (win==null) { Interpreter.removeBatchModeImage(this); return; } boolean unlocked = lockSilently(); Overlay overlay2 = getOverlay(); changes = false; win.close(); win = null; setOverlay(overlay2); if (unlocked) unlock(); }
/** Closes the window, if any, that is displaying this image. */ public void hide() { if (win==null) { Interpreter.removeBatchModeImage(this); return; } boolean unlocked = lockSilently(); Overlay overlay2 = getOverlay(); changes = false; win.close(); win = null; setOverlay(overlay2); if (unlocked) unlock(); }
private void unlock() { ImagePlus imp = IJ.getImage(); boolean wasUnlocked = imp.lockSilently(); if (wasUnlocked) IJ.showStatus("\""+imp.getTitle()+"\" is not locked"); else { IJ.showStatus("\""+imp.getTitle()+"\" is now unlocked"); IJ.beep(); } imp.unlock(); }
private void unlock() { ImagePlus imp = IJ.getImage(); boolean wasUnlocked = imp.lockSilently(); if (wasUnlocked) IJ.showStatus("\""+imp.getTitle()+"\" is not locked"); else { IJ.showStatus("\""+imp.getTitle()+"\" is now unlocked"); IJ.beep(); } imp.unlock(); }
void enlargeCanvas() { imp.unlock(); IJ.run("Select All"); IJ.run("Rotate...", "angle="+angle); Roi roi = imp.getRoi(); Rectangle r = roi.getBounds(); if (r.width<imp.getWidth()) r.width = imp.getWidth(); if (r.height<imp.getHeight()) r.height = imp.getHeight(); IJ.showStatus("Rotate: Enlarging..."); if (imp.getStackSize()==1) Undo.setup(Undo.COMPOUND_FILTER, imp); IJ.run("Canvas Size...", "width="+r.width+" height="+r.height+" position=Center "+(fillWithBackground?"":"zero")); IJ.showStatus("Rotating..."); }
void del() { if (!imp.lock()) return; ImageStack stack = imp.getStack(); int n = imp.getCurrentSlice(); stack.deleteSlice(n); if (stack.getSize()==1) { imp.setProcessor(null, stack.getProcessor(1)); new ImageWindow(imp); } imp.setStack(null, stack); numSlices--; if (n>numSlices) imp.setSlice(numSlices); else imp.setSlice(n); imp.unlock(); } void delN(){
void enlargeCanvas() { imp.unlock(); IJ.run("Select All"); IJ.run("Rotate...", "angle="+angle); Roi roi = imp.getRoi(); Rectangle r = roi.getBounds(); if (r.width<imp.getWidth()) r.width = imp.getWidth(); if (r.height<imp.getHeight()) r.height = imp.getHeight(); IJ.showStatus("Rotate: Enlarging..."); if (imp.getStackSize()==1) Undo.setup(Undo.COMPOUND_FILTER, imp); IJ.run("Canvas Size...", "width="+r.width+" height="+r.height+" position=Center "+(fillWithBackground?"":"zero")); IJ.showStatus("Rotating..."); }
public void run(String arg) { imp = WindowManager.getCurrentImage(); if (imp!=null) { if (imp.isComposite() && arg.equals("RGB Color") && !imp.getStack().isRGB() && !imp.getStack().isHSB() && !imp.getStack().isLab()) { if (imp.getWindow()==null && !ij.macro.Interpreter.isBatchMode()) RGBStackConverter.convertToRGB(imp); else { (new RGBStackConverter()).run(""); imp.setTitle(imp.getTitle()); // updates size in Window menu } } else if (imp.lock()) { convert(arg); imp.unlock(); imp.setTitle(imp.getTitle()); } else IJ.log("<<Converter: image is locked ("+imp+")>>"); } else IJ.noImage(); }
void deleteSlice() { if (nSlices<2) {IJ.error("\"Delete Slice\" requires a stack"); return;} if (imp.isHyperStack() || (imp.isComposite() && nSlices==imp.getNChannels())) { deleteHyperstackChannelSliceOrFrame(); return; } if (!imp.lock()) return; ImageStack stack = imp.getStack(); int n = imp.getCurrentSlice(); stack.deleteSlice(n); if (stack.getSize()==1) { String label = stack.getSliceLabel(1); if (label!=null) imp.setProperty("Label", label); } imp.setStack(null, stack); if (n--<1) n = 1; imp.setSlice(n); imp.unlock(); imp.changes = true; }
void addSlice() { if (imp.isHyperStack() || imp.isComposite()) { addHyperstackChannelSliceOrFrame(); return; } if (!imp.lock()) return; int id = 0; ImageStack stack = imp.getStack(); if (stack.getSize()==1) { String label = stack.getSliceLabel(1); if (label!=null && label.indexOf("\n")!=-1) stack.setSliceLabel(null, 1); Object obj = imp.getProperty("Label"); if (obj!=null && (obj instanceof String)) stack.setSliceLabel((String)obj, 1); id = imp.getID(); } ImageProcessor ip = imp.getProcessor(); int n = imp.getCurrentSlice(); if (IJ.altKeyDown()) n--; // insert in front of current slice stack.addSlice(null, ip.createProcessor(width, height), n); imp.setStack(null, stack); imp.setSlice(n+1); imp.unlock(); imp.changes = true; if (id!=0) IJ.selectWindow(id); // prevents macros from failing }
public void run(String arg) { imp = WindowManager.getCurrentImage(); if (imp!=null) { if (imp.isComposite() && arg.equals("RGB Color") && !imp.getStack().isRGB() && !imp.getStack().isHSB() && !imp.getStack().isLab()) { if (imp.getWindow()==null && !ij.macro.Interpreter.isBatchMode()) RGBStackConverter.convertToRGB(imp); else { (new RGBStackConverter()).run(""); imp.setTitle(imp.getTitle()); // updates size in Window menu } } else if (imp.lock()) { convert(arg); imp.unlock(); imp.setTitle(imp.getTitle()); } else IJ.log("<<Converter: image is locked ("+imp+")>>"); } else IJ.noImage(); }
void deleteSlice() { if (nSlices<2) {IJ.error("\"Delete Slice\" requires a stack"); return;} if (imp.isHyperStack() || (imp.isComposite() && nSlices==imp.getNChannels())) { deleteHyperstackChannelSliceOrFrame(); return; } if (!imp.lock()) return; ImageStack stack = imp.getStack(); int n = imp.getCurrentSlice(); stack.deleteSlice(n); if (stack.getSize()==1) { String label = stack.getSliceLabel(1); if (label!=null) imp.setProperty("Label", label); } imp.setStack(null, stack); if (n--<1) n = 1; imp.setSlice(n); imp.unlock(); imp.changes = true; }
private void splitRGB(ImagePlus imp) { boolean keepSource = IJ.altKeyDown(); String title = imp.getTitle(); Calibration cal = imp.getCalibration(); int pos = imp.getCurrentSlice(); ImageStack[] channels = splitRGB(imp.getStack(), keepSource); if (!keepSource) {imp.unlock(); imp.changes=false; imp.close();} ImagePlus rImp = new ImagePlus(title+" (red)", channels[0]); rImp.setCalibration(cal); rImp.setIJMenuBar(false); rImp.show(); rImp.setSlice(pos); if (IJ.isMacOSX()) IJ.wait(500); ImagePlus gImp = new ImagePlus(title+" (green)", channels[1]); gImp.setCalibration(cal); gImp.setIJMenuBar(false); gImp.show(); gImp.setSlice(pos); if (IJ.isMacOSX()) IJ.wait(500); ImagePlus bImp = new ImagePlus(title+" (blue)", channels[2]); bImp.setCalibration(cal); bImp.show(); bImp.setSlice(pos); }
private void splitRGB(ImagePlus imp) { boolean keepSource = IJ.altKeyDown(); String title = imp.getTitle(); Calibration cal = imp.getCalibration(); int pos = imp.getCurrentSlice(); ImageStack[] channels = splitRGB(imp.getStack(), keepSource); if (!keepSource) {imp.unlock(); imp.changes=false; imp.close();} ImagePlus rImp = new ImagePlus(title+" (red)", channels[0]); rImp.setCalibration(cal); rImp.setIJMenuBar(false); rImp.show(); rImp.setSlice(pos); if (IJ.isMacOSX()) IJ.wait(500); ImagePlus gImp = new ImagePlus(title+" (green)", channels[1]); gImp.setCalibration(cal); gImp.setIJMenuBar(false); gImp.show(); gImp.setSlice(pos); if (IJ.isMacOSX()) IJ.wait(500); ImagePlus bImp = new ImagePlus(title+" (blue)", channels[2]); bImp.setCalibration(cal); bImp.show(); bImp.setSlice(pos); }