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()); }
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..."); }
boolean validDialogValues() { Calibration cal = imp.getCalibration(); double pw=cal.pixelWidth, ph=cal.pixelHeight; if (width/pw<1 || height/ph<1) return false; if (xRoi/pw>imp.getWidth() || yRoi/ph>imp.getHeight()) return false; return true; }
/** Returns the size of this image in bytes. */ public double getSizeInBytes() { double size = ((double)getWidth()*getHeight()*getStackSize()); int type = getType(); switch (type) { case ImagePlus.GRAY16: size *= 2.0; break; case ImagePlus.GRAY32: size *= 4.0; break; case ImagePlus.COLOR_RGB: size *= 4.0; break; } return size; }
static void transfer(final ImagePlus src, final ImagePlus dst) { // Calibration: dst.setCalibration(src.getCalibration()); // Color model: final ColorModel cm = src.getProcessor().getColorModel(); dst.getProcessor().setColorModel(cm); dst.getStack().setColorModel(cm); // Min and max displaying: dst.setDisplayRange(src.getDisplayRangeMin(),src.getDisplayRangeMax()); }
/** * bag class for getting the result of the loaded classifier */ private static class LoadedClassifier { private AbstractClassifier newClassifier = null; private Instances newHeader = null; }
void invertLut() { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) {IJ.noImage(); return;} if (imp.getType()==ImagePlus.COLOR_RGB) {IJ.error("RGB images do not use LUTs"); return;} if (imp.isComposite()) { CompositeImage ci = (CompositeImage)imp; LUT lut = ci.getChannelLut(); if (lut!=null) ci.setChannelLut(lut.createInvertedLut()); } else { ImageProcessor ip = imp.getProcessor(); ip.invertLut(); if (imp.getStackSize()>1) imp.getStack().setColorModel(ip.getColorModel()); } imp.updateAndRepaintWindow(); }
public ImagePlus call(){ final ImagePlus hsb = originalImage.duplicate(); ImageConverter ic = new ImageConverter( hsb ); ic.convertToHSB(); ImageStack is = new ImageStack(originalImage.getWidth(), originalImage.getHeight()); for(int n=1; n<=hsb.getImageStackSize(); n++) is.addSlice(hsb.getImageStack().getSliceLabel(n), hsb.getImageStack().getProcessor(n).convertToRGB()); return new ImagePlus ("HSB", is); } };
private void rename() { ImagePlus imp = IJ.getImage(); GenericDialog gd = new GenericDialog("Rename"); gd.addStringField("Title:", imp.getTitle(), 30); gd.showDialog(); if (!gd.wasCanceled()) imp.setTitle(gd.getNextString()); }
private void writeFourChannelsWithAlpha(ImagePlus imp, String path) throws Exception { ImageStack stack = imp.getStack(); int w=imp.getWidth(), h=imp.getHeight(); ImagePlus imp2 = new ImagePlus("", new ColorProcessor(w,h)); ColorProcessor cp = (ColorProcessor)imp2.getProcessor(); for (int channel=1; channel<=4; channel++) cp.setChannel(channel, (ByteProcessor)stack.getProcessor(channel)); BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); WritableRaster raster = bi.getRaster(); raster.setDataElements(0, 0, w, h, cp.getPixels()); ImageIO.write(bi, "png", new File(path)); }
public static void duplicateFrames(ImagePlus imp, int slice, int num) { ImageStack stack = imp.getStack(); int w = imp.getWidth(), h = imp.getHeight(); ImageProcessor frame = stack.getProcessor(slice).duplicate(); for(int n = 0; n < num; n++) stack.addSlice("", frame, slice + n); // causes the change from image window to stack window imp.setStack(null, stack); } }
public void doit(int PATTERN, int REPLACEMENT) { int w = image.getWidth(), h = image.getHeight(); int d = image.getStackSize(); ImageStack stack = image.getStack(); for(int z = 0; z < d; z++) { byte[] b = (byte[])stack.getProcessor(z+1).getPixels(); for(int i = 0; i < w*h; i++) { if(((int)(b[i] & 0xff)) == PATTERN) b[i] = (byte)REPLACEMENT; } } }
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 ""; } }
@Override public void run(String arg) { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null) {IJ.noImage(); return;} ImageStack stack = imp.getStack(); if (stack.getSize()==1) {IJ.error("Stack Required"); return;} if (!showDialog(stack)) return; title=imp.getTitle(); keepSlices(stack, first, last, inc, imp.getCalibration()); //imp.setStack(null, stack); IJ.register(Slice_Keeper.class); }
void doFHTInverseTransform() { FHT fht = new FHT(imp.getProcessor().duplicate()); fht.inverseTransform(); fht.resetMinAndMax(); String name = WindowManager.getUniqueName(imp.getTitle().substring(7)); new ImagePlus(name, fht).show(); }
ImageStack createOutputStack(ImagePlus imp, ImageProcessor ip) { int bitDepth = imp.getBitDepth(); int w2=ip.getWidth(), h2=ip.getHeight(), d2=outputSlices; int flags = NewImage.FILL_BLACK + NewImage.CHECK_AVAILABLE_MEMORY; ImagePlus imp2 = NewImage.createImage("temp", w2, h2, d2, bitDepth, flags); if (imp2!=null && imp2.getStackSize()==d2) IJ.showStatus("Reslice... (press 'Esc' to abort)"); if (imp2==null) return null; else { ImageStack stack2 = imp2.getStack(); stack2.setColorModel(ip.getColorModel()); return stack2; } }
public static FloatMatrix translateToCenter(ImagePlus image) { Calibration calib = image.getCalibration(); FloatMatrix result = new FloatMatrix(); result.a00 = (float)1; result.a11 = (float)1; result.a22 = (float)1; result.a03 = (float)(calib.xOrigin + calib.pixelWidth * image.getWidth() / 2.0f); result.a13 = (float)(calib.yOrigin + calib.pixelHeight * image.getHeight() / 2.0f); result.a23 = (float)(calib.yOrigin + calib.pixelDepth * image.getStack().getSize() / 2.0f); return result; }
ImageStack convertToRealStack(ImagePlus imp) { ImageStack stack2 = new ImageStack(imageWidth, imageHeight, imp.getProcessor().getColorModel()); int n = this.getSize(); for (int i=1; i<=this.getSize(); i++) { IJ.showProgress(i, n); IJ.showStatus("Opening: "+i+"/"+n); ImageProcessor ip2 = this.getProcessor(i); if (ip2!=null) stack2.addSlice(this.getSliceLabel(i), ip2); } return stack2; }
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)); }