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; } }
/** Adds the image in 'ip' to the end of the stack, setting the string 'sliceLabel' as the slice metadata. */ public void addSlice(String sliceLabel, ImageProcessor ip) { if (ip.getWidth()!=width || ip.getHeight()!=height) throw new IllegalArgumentException("ImageStack.addSlice(): dimensions do not match"); if (nSlices==0) { cm = ip.getColorModel(); min = ip.getMin(); max = ip.getMax(); } addSlice(sliceLabel, ip.getPixels()); }
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); } }
final boolean inParticle(int x, int y, double level1, double level2) { if (isFloat) return ip.getPixelValue(x,y)>=level1 && ip.getPixelValue(x,y)<=level2; else { int v = ip.getPixel(x,y); return v>=level1 && v<=level2; } }
ImageProcessor createNewImage(ImageProcessor ip1, ImageProcessor ip2) { int width = Math.min(ip1.getWidth(), ip2.getWidth()); int height = Math.min(ip1.getHeight(), ip2.getHeight()); ImageProcessor ip3 = ip1.createProcessor(width, height); if (floatResult) { ip1 = ip1.convertToFloat(); ip3 = ip3.convertToFloat(); } ip3.insert(ip1, 0, 0); return ip3; }
/** * bag class for getting the result of the loaded classifier */ private static class LoadedClassifier { private AbstractClassifier newClassifier = null; private Instances newHeader = null; }
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."); }
public void mouseMoved(MouseEvent e) { int x = cc.offScreenX(e.getX()); int y = cc.offScreenY(e.getY()); double posX, posY, posZ; int voxelValue; int materialID; String materialName; if(x<imp.getWidth() && y<imp.getHeight()) { Calibration cal = imp.getCalibration(); posX = cal.getX(x); posX = Double.valueOf(IJ.d2s(posX)).doubleValue(); posY = cal.getY(y); posY = Double.valueOf(IJ.d2s(posY)).doubleValue(); int z = imp.getCurrentSlice()-1; posZ = cal.getZ(z); posZ = Double.valueOf(IJ.d2s(posZ)).doubleValue(); voxelValue = imp.getProcessor().get(x, y); materialID = cc.getLabels().getStack().getProcessor(z+1).get(x,y); materialName = sidebar.getMaterials() .params.getMaterialName(materialID); IJ.showStatus("x=" + posX + ", y=" + posY + ", z=" + posZ + ", value=" + voxelValue + ", material=" + materialName); } }
void invert16BitStack(ImagePlus imp) { imp.deleteRoi(); imp.getCalibration().disableDensityCalibration(); ImageStatistics stats = new StackStatistics(imp); ImageStack stack = imp.getStack(); int nslices = stack.getSize(); int min=(int)stats.min, range=(int)(stats.max-stats.min); int n = imp.getWidth()*imp.getHeight(); for (int slice=1; slice<=nslices; slice++) { ImageProcessor ip = stack.getProcessor(slice); short[] pixels = (short[])ip.getPixels(); for (int i=0; i<n; i++) { int before = pixels[i]&0xffff; pixels[i] = (short)(range-((pixels[i]&0xffff)-min)); } } imp.setStack(null, stack); imp.setDisplayRange(0, range); imp.updateAndDraw(); }
/** Flattens Overlay 'overlay' on slice 'slice' of ImageStack 'stack'. * Copied from OverlayCommands by Marcel Boeglin 2014.01.08. */ private void flattenImage(ImageStack stack, int slice, Overlay overlay, boolean showAll) { ImageProcessor ips = stack.getProcessor(slice); ImagePlus imp1 = new ImagePlus("temp", ips); int w = imp1.getWidth(); int h = imp1.getHeight(); for (int i=0; i<overlay.size(); i++) { Roi r = overlay.get(i); int roiPosition = r.getPosition(); //IJ.log(slice+" "+i+" "+roiPosition+" "+showAll+" "+overlay.size()); if (!(roiPosition==0 || roiPosition==slice || showAll)) r.setLocation(w, h); } imp1.setOverlay(overlay); ImagePlus imp2 = imp1.flatten(); stack.setPixels(imp2.getProcessor().getPixels(), slice); }
void setStackDisplayRange(ImagePlus imp) { ImageStack stack = imp.getStack(); double min = Double.MAX_VALUE; double max = -Double.MAX_VALUE; int n = stack.getSize(); for (int i=1; i<=n; i++) { if (!silentMode) IJ.showStatus("Calculating stack min and max: "+i+"/"+n); ImageProcessor ip = stack.getProcessor(i); ip.resetMinAndMax(); if (ip.getMin()<min) min = ip.getMin(); if (ip.getMax()>max) max = ip.getMax(); } imp.getProcessor().setMinAndMax(min, max); imp.updateAndDraw(); }
public ImageStack straightenStack(ImagePlus imp, Roi roi, int width) { int current = imp.getCurrentSlice(); int n = imp.getStackSize(); ImageStack stack2 = null; for (int i=1; i<=n; i++) { IJ.showProgress(i, n); imp.setSlice(i); ImageProcessor ip2 = straighten(imp, roi, width); if (stack2==null) stack2 = new ImageStack(ip2.getWidth(), ip2.getHeight()); stack2.addSlice(null, ip2); } imp.setSlice(current); return stack2; }
public static void addFrames(ImagePlus imp, int slice, int num) { ImageStack stack = imp.getStack(); int w = imp.getWidth(), h = imp.getHeight(); ImageProcessor frame = stack.getProcessor(slice). createProcessor(w, h); frame.setValue(0); frame.fill(); 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); } }
/** Flattens Overlay 'overlay' on slice 'slice' corresponding to * coordinates 'z' and 't' in RGB-HyperStack 'stack' */ private void flattenImage(ImageStack stack, int slice, Overlay overlay, boolean showAll, int z, int t) { ImageProcessor ips = stack.getProcessor(slice); ImagePlus imp1 = new ImagePlus("temp", ips); int w = imp1.getWidth(); int h = imp1.getHeight(); for (int i=0; i<overlay.size(); i++) { Roi r = overlay.get(i); int cPos = r.getCPosition();// 0 or 1 (RGB-HyperStack) int zPos = r.getZPosition(); int tPos = r.getTPosition(); if (!((cPos==1 || cPos==0) && (zPos==z || zPos==0) && (tPos==t || tPos==0) || showAll)) r.setLocation(w, h); } imp1.setOverlay(overlay); ImagePlus imp2 = imp1.flatten(); stack.setPixels(imp2.getProcessor().getPixels(), slice); }
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; }
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(); }
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 ""; } }
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 calculateSizes(){ if(showStatus) IJ.showStatus("calculate class sizes..."); ImageStack resStack = result.getStack(); sizes = new int[classes.length]; for(int d=1;d<=z;d++){ int[] classPixels = (int[])resStack .getProcessor(d).getPixels(); for(int i=0;i<w*h;i++){ if(classPixels[i] != -1) sizes[classPixels[i]]++; } if(showStatus) IJ.showProgress(d,z); } }