public void killStack() { setStackNull(); trimProcessor(); }
public void killStack() { setStackNull(); trimProcessor(); }
public synchronized void trimProcessor() { if (!locked) { try { ImagePlus imp = patch[currentSlice-1].getProject().getLoader().fetchImagePlus(patch[currentSlice-1]); imp.trimProcessor(); } catch (Exception e) { e.printStackTrace(); } } }
/** Converts an RGB image to a HSB (hue, saturation and brightness) stack. */ public void convertToHSB() { if (type!=ImagePlus.COLOR_RGB) throw new IllegalArgumentException("Image must be RGB");; ColorProcessor cp; if (imp.getType()==ImagePlus.COLOR_RGB) cp = (ColorProcessor)imp.getProcessor(); else cp = new ColorProcessor(imp.getImage()); ImageStack stack = cp.getHSBStack(); imp.trimProcessor(); imp.setStack(null, stack); imp.setDimensions(3, 1, 1); }
/** Makes the image contained in the specified window the active image. */ public static void setCurrentWindow(ImageWindow win) { if (win==null || win.isClosed() || win.getImagePlus()==null) // deadlock-"wait to lock" return; //IJ.log("setCurrentWindow: "+win.getImagePlus().getTitle()+" ("+(currentWindow!=null?currentWindow.getImagePlus().getTitle():"null") + ")"); setWindow(win); tempImageTable.remove(Thread.currentThread()); if (win==currentWindow || imageList.size()==0) return; if (currentWindow!=null) { // free up pixel buffers used by current window ImagePlus imp = currentWindow.getImagePlus(); if (imp!=null ) { if (!Prefs.keepUndoBuffers) imp.trimProcessor(); imp.saveRoi(); } } Undo.reset(); currentWindow = win; activations.remove(win); activations.add(win); Menus.updateMenus(); if (Recorder.record && !IJ.isMacro()) Recorder.record("selectWindow", win.getImagePlus().getTitle()); }
/** Converts an RGB image to a HSB (hue, saturation and brightness) stack. */ public void convertToHSB() { if (type!=ImagePlus.COLOR_RGB) throw new IllegalArgumentException("Image must be RGB");; ColorProcessor cp; if (imp.getType()==ImagePlus.COLOR_RGB) cp = (ColorProcessor)imp.getProcessor(); else cp = new ColorProcessor(imp.getImage()); ImageStack stack = cp.getHSBStack(); imp.trimProcessor(); imp.setStack(null, stack); imp.setDimensions(3, 1, 1); }
/** Makes the image contained in the specified window the active image. */ public static void setCurrentWindow(ImageWindow win) { if (win==null || win.isClosed() || win.getImagePlus()==null) // deadlock-"wait to lock" return; //IJ.log("setCurrentWindow: "+win.getImagePlus().getTitle()+" ("+(currentWindow!=null?currentWindow.getImagePlus().getTitle():"null") + ")"); setWindow(win); tempImageTable.remove(Thread.currentThread()); if (win==currentWindow || imageList.size()==0) return; if (currentWindow!=null) { // free up pixel buffers used by current window ImagePlus imp = currentWindow.getImagePlus(); if (imp!=null ) { if (!Prefs.keepUndoBuffers) imp.trimProcessor(); imp.saveRoi(); } } Undo.reset(); currentWindow = win; activations.remove(win); activations.add(win); Menus.updateMenus(); if (Recorder.record && !IJ.isMacro()) Recorder.record("selectWindow", win.getImagePlus().getTitle()); }
/** Converts this ImagePlus to 16-bit grayscale. */ public void convertToGray16() { if (type==ImagePlus.GRAY16) return; if (!(type==ImagePlus.GRAY8||type==ImagePlus.GRAY32||type==ImagePlus.COLOR_RGB)) throw new IllegalArgumentException("Unsupported conversion"); if (imp.getStackSize()>1) { new StackConverter(imp).convertToGray16(); return; } ImageProcessor ip = imp.getProcessor(); if (type==ImagePlus.GRAY32) record(); imp.trimProcessor(); imp.setProcessor(null, ip.convertToShort(doScaling)); imp.setCalibration(imp.getCalibration()); //update calibration }
/** Converts an RGB image to 8-bits indexed color. 'nColors' must be greater than 1 and less than or equal to 256. */ public void convertRGBtoIndexedColor(int nColors) { if (type!=ImagePlus.COLOR_RGB) throw new IllegalArgumentException("Image must be RGB"); if (nColors<2) nColors = 2; if (nColors>256) nColors = 256; // get RGB pixels IJ.showProgress(0.1); IJ.showStatus("Grabbing pixels"); int width = imp.getWidth(); int height = imp.getHeight(); ImageProcessor ip = imp.getProcessor(); ip.snapshot(); int[] pixels = (int[])ip.getPixels(); imp.trimProcessor(); // convert to 8-bits long start = System.currentTimeMillis(); MedianCut mc = new MedianCut(pixels, width, height); ImageProcessor ip2 = mc.convertToByte(nColors); imp.setProcessor(null, ip2); }
/** Converts an RGB image to 8-bits indexed color. 'nColors' must be greater than 1 and less than or equal to 256. */ public void convertRGBtoIndexedColor(int nColors) { if (type!=ImagePlus.COLOR_RGB) throw new IllegalArgumentException("Image must be RGB"); if (nColors<2) nColors = 2; if (nColors>256) nColors = 256; // get RGB pixels IJ.showProgress(0.1); IJ.showStatus("Grabbing pixels"); int width = imp.getWidth(); int height = imp.getHeight(); ImageProcessor ip = imp.getProcessor(); ip.snapshot(); int[] pixels = (int[])ip.getPixels(); imp.trimProcessor(); // convert to 8-bits long start = System.currentTimeMillis(); MedianCut mc = new MedianCut(pixels, width, height); ImageProcessor ip2 = mc.convertToByte(nColors); imp.setProcessor(null, ip2); }
/** Converts this ImagePlus to 16-bit grayscale. */ public void convertToGray16() { if (type==ImagePlus.GRAY16) return; if (!(type==ImagePlus.GRAY8||type==ImagePlus.GRAY32||type==ImagePlus.COLOR_RGB)) throw new IllegalArgumentException("Unsupported conversion"); if (imp.getStackSize()>1) { new StackConverter(imp).convertToGray16(); return; } ImageProcessor ip = imp.getProcessor(); if (type==ImagePlus.GRAY32) record(); imp.trimProcessor(); imp.setProcessor(null, ip.convertToShort(doScaling)); imp.setCalibration(imp.getCalibration()); //update calibration }
/** Converts this ImagePlus to 32-bit grayscale. */ public void convertToGray32() { if (type==ImagePlus.GRAY32) return; if (!(type==ImagePlus.GRAY8||type==ImagePlus.GRAY16||type==ImagePlus.COLOR_RGB)) throw new IllegalArgumentException("Unsupported conversion"); Calibration cal = imp.getCalibration(); double min = cal.getCValue(imp.getDisplayRangeMin()); double max = cal.getCValue(imp.getDisplayRangeMax()); if (imp.getStackSize()>1) { new StackConverter(imp).convertToGray32(); IJ.setMinAndMax(imp, min, max); return; } ImageProcessor ip = imp.getProcessor(); imp.trimProcessor(); imp.setProcessor(null, ip.convertToFloat()); imp.setCalibration(cal); //update calibration IJ.setMinAndMax(imp, min, max); }
/** Converts this ImagePlus to 32-bit grayscale. */ public void convertToGray32() { if (type==ImagePlus.GRAY32) return; if (!(type==ImagePlus.GRAY8||type==ImagePlus.GRAY16||type==ImagePlus.COLOR_RGB)) throw new IllegalArgumentException("Unsupported conversion"); Calibration cal = imp.getCalibration(); double min = cal.getCValue(imp.getDisplayRangeMin()); double max = cal.getCValue(imp.getDisplayRangeMax()); if (imp.getStackSize()>1) { new StackConverter(imp).convertToGray32(); IJ.setMinAndMax(imp, min, max); return; } ImageProcessor ip = imp.getProcessor(); imp.trimProcessor(); imp.setProcessor(null, ip.convertToFloat()); imp.setCalibration(cal); //update calibration IJ.setMinAndMax(imp, min, max); }
/** Converts a 3-slice (hue, saturation, brightness) 8-bit stack to RGB. */ public void convertHSBToRGB() { if (imp.getStackSize()!=3) throw new IllegalArgumentException("3-slice 8-bit stack required"); ImageStack stack = imp.getStack(); byte[] H = (byte[])stack.getPixels(1); byte[] S = (byte[])stack.getPixels(2); byte[] B = (byte[])stack.getPixels(3); int width = imp.getWidth(); int height = imp.getHeight(); imp.trimProcessor(); ColorProcessor cp = new ColorProcessor(width, height); cp.setHSB(H, S, B); imp.setImage(cp.createImage()); imp.killStack(); if (IJ.isLinux()) imp.setTitle(imp.getTitle()); }
/** Converts a 3-slice (hue, saturation, brightness) 8-bit stack to RGB. */ public void convertHSBToRGB() { if (imp.getStackSize()!=3) throw new IllegalArgumentException("3-slice 8-bit stack required"); ImageStack stack = imp.getStack(); byte[] H = (byte[])stack.getPixels(1); byte[] S = (byte[])stack.getPixels(2); byte[] B = (byte[])stack.getPixels(3); int width = imp.getWidth(); int height = imp.getHeight(); imp.trimProcessor(); ColorProcessor cp = new ColorProcessor(width, height); cp.setHSB(H, S, B); imp.setImage(cp.createImage()); imp.killStack(); if (IJ.isLinux()) imp.setTitle(imp.getTitle()); }
/** Converts an RGB image to an RGB (red, green and blue) stack. */ public void convertToRGBStack() { if (type!=ImagePlus.COLOR_RGB) throw new IllegalArgumentException("Image must be RGB"); //convert to RGB Stack ColorProcessor cp; if (imp.getType()==ImagePlus.COLOR_RGB) cp = (ColorProcessor)imp.getProcessor(); else cp = new ColorProcessor(imp.getImage()); int width = imp.getWidth(); int height = imp.getHeight(); byte[] R = new byte[width*height]; byte[] G = new byte[width*height]; byte[] B = new byte[width*height]; cp.getRGB(R, G, B); imp.trimProcessor(); // Create stack and select Red channel ColorModel cm = LookUpTable.createGrayscaleColorModel(false); ImageStack stack = new ImageStack(width, height, cm); stack.addSlice("Red", R); stack.addSlice("Green", G); stack.addSlice("Blue", B); imp.setStack(null, stack); imp.setDimensions(3, 1, 1); if (imp.isComposite()) ((CompositeImage)imp).setMode(IJ.GRAYSCALE); }
/** Converts a 2 or 3 slice 8-bit stack to RGB. */ public void convertRGBStackToRGB() { int stackSize = imp.getStackSize(); if (stackSize<2 || stackSize>3 || type!=ImagePlus.GRAY8) throw new IllegalArgumentException("2 or 3 slice 8-bit stack required"); int width = imp.getWidth(); int height = imp.getHeight(); ImageStack stack = imp.getStack(); byte[] R = (byte[])stack.getPixels(1); byte[] G = (byte[])stack.getPixels(2); byte[] B; if (stackSize>2) B = (byte[])stack.getPixels(3); else B = new byte[width*height]; imp.trimProcessor(); ColorProcessor cp = new ColorProcessor(width, height); cp.setRGB(R, G, B); if (imp.isInvertedLut()) cp.invert(); imp.setImage(cp.createImage()); imp.killStack(); if (IJ.isLinux()) imp.setTitle(imp.getTitle()); }
/** Converts a 2 or 3 slice 8-bit stack to RGB. */ public void convertRGBStackToRGB() { int stackSize = imp.getStackSize(); if (stackSize<2 || stackSize>3 || type!=ImagePlus.GRAY8) throw new IllegalArgumentException("2 or 3 slice 8-bit stack required"); int width = imp.getWidth(); int height = imp.getHeight(); ImageStack stack = imp.getStack(); byte[] R = (byte[])stack.getPixels(1); byte[] G = (byte[])stack.getPixels(2); byte[] B; if (stackSize>2) B = (byte[])stack.getPixels(3); else B = new byte[width*height]; imp.trimProcessor(); ColorProcessor cp = new ColorProcessor(width, height); cp.setRGB(R, G, B); if (imp.isInvertedLut()) cp.invert(); imp.setImage(cp.createImage()); imp.killStack(); if (IJ.isLinux()) imp.setTitle(imp.getTitle()); }
public void run(String arg) { ImagePlus imp = IJ.getImage(); stackSize = imp.getStackSize(); imp.trimProcessor(); if (!showDialog(imp)) return; Roi roi = imp.getRoi(); if (roi!=null) roi.endPaste(); if (stackSize==1) Undo.setup(Undo.TRANSFORM, imp); else Undo.reset(); if (equalize) equalize(imp); else stretchHistogram(imp, saturated); if (normalize) { ImageProcessor ip = imp.getProcessor(); ip.setMinAndMax(0,ip.getBitDepth()==32?1.0:ip.maxValue()); } imp.updateAndDraw(); }
public void run(String arg) { ImagePlus imp = IJ.getImage(); stackSize = imp.getStackSize(); imp.trimProcessor(); if (!showDialog(imp)) return; Roi roi = imp.getRoi(); if (roi!=null) roi.endPaste(); if (stackSize==1) Undo.setup(Undo.TRANSFORM, imp); else Undo.reset(); if (equalize) equalize(imp); else stretchHistogram(imp, saturated); if (normalize) { ImageProcessor ip = imp.getProcessor(); ip.setMinAndMax(0,ip.getBitDepth()==32?1.0:ip.maxValue()); } imp.updateAndDraw(); }