private static double findMaxStackValue(ImagePlus imp) { Object[] stack = imp.getStack().getImageArray();//getFloatImageArray(imp); double max = 0; for(int i = 0; i < stack.length; i++) { float[] pixels = (float[]) stack[i]; if(pixels != null) { for(int j = 0; j < pixels.length; j++) { double val = pixels[j]; if(val > max) { max = val; } } } } return max; }
/** * Fill this volume from stack s with from slice start. * @param s an ImageJ ImageStack * @param start the first slice to be loaded (starting with slice 1). * @return true if could be loaded, false if wrong volume type. */ public boolean load(ImageStack s, int start) { if (! (s.getImageArray()[0] instanceof byte[] || s.getImageArray()[0] instanceof short [])) { IJ.error("VolumeShort: can only convert 8- and 16-bit images."); return false; } for (int t = start; t < start + depth; t++) loadSlice(v[t-start], s, t+1); return true; } /** Fill the volume with depth 1 with a single image ip. */
private void initializeResult() { // Create result image the same size as the mask image this.result = ImageStack.create(size1, size2, size3, mask.getBitDepth()); Object[] stack = result.getImageArray(); Object[] markerStack = marker.getImageArray(); Object[] maskStack = mask.getImageArray(); byte[] slice; byte[] markerSlice; byte[] maskSlice; // Initialize the result image with the minimum value of marker and mask // images for (int z = 0; z < size3; z++) { slice = (byte[]) stack[z]; maskSlice = (byte[]) maskStack[z]; markerSlice = (byte[]) markerStack[z]; for (int y = 0; y < size2; y++) { for (int x = 0; x < size1; x++) { int index = y * size1 + x; int value = max(markerSlice[index] & 0x00FF, maskSlice[index] & 0x00FF); slice[index] = (byte) value; } } } }
private void initializeResult() { // Create result image the same size as the mask image this.result = ImageStack.create(size1, size2, size3, mask.getBitDepth()); Object[] stack = result.getImageArray(); Object[] markerStack = marker.getImageArray(); Object[] maskStack = mask.getImageArray(); byte[] slice; byte[] markerSlice; byte[] maskSlice; // Initialize the result image with the minimum value of marker and mask // images for (int z = 0; z < size3; z++) { slice = (byte[]) stack[z]; maskSlice = (byte[]) maskStack[z]; markerSlice = (byte[]) markerStack[z]; for (int y = 0; y < size2; y++) { for (int x = 0; x < size1; x++) { int index = y * size1 + x; int value = min(markerSlice[index] & 0x00FF, maskSlice[index] & 0x00FF); slice[index] = (byte) value; } } } }
Object[] stack = result.getImageArray(); Object[] markerStack = marker.getImageArray(); Object[] maskStack = mask.getImageArray(); byte[] slice; byte[] markerSlice;
/** * Extracts the byte arrays corresponding to the slices of a stack * containing instances of ByteProcessor. * * @param image * a 3D image that must contain byte values * @return the array of byte arrays corresponding to each slice */ public static final byte[][] getByteArrays(ImageStack image) { // Check bit depth of input images if (image.getBitDepth() != 8 ) { throw new IllegalArgumentException("Bit depth of input ImageStack must be 8"); } // Initialize result array int nSlices = image.getSize(); byte[][] slices = new byte[nSlices][]; // Extract inner slice array and apply type conversion Object[] array = image.getImageArray(); for (int i = 0; i < nSlices; i++) { slices[i] = (byte[]) array[i]; } // return slices return slices; }
/** * Extracts the short arrays corresponding to the slices of a stack * containing instances of ShortProcessor. * * @param image * a 3D image that must contain short values * @return the array of short arrays corresponding to each slice */ public static final short[][] getShortArrays(ImageStack image) { // Check bit depth of input images if (image.getBitDepth() != 16 ) { throw new IllegalArgumentException("Bit depth of input ImageStack must be 16"); } // Initialize result array int nSlices = image.getSize(); short[][] slices = new short[nSlices][]; // Extract inner slice array and apply type conversion Object[] array = image.getImageArray(); for (int i = 0; i < nSlices; i++) { slices[i] = (short[]) array[i]; } // return slices return slices; }
/** * Extracts the float arrays corresponding to the slices of a stack * containing instances of FloatProcessor. * * @param image * a 3D image that must contain float values * @return the array of float arrays corresponding to each slice */ public static final float[][] getFloatArrays(ImageStack image) { // Check bit depth of input images if (image.getBitDepth() != 32 ) { throw new IllegalArgumentException("Bit depth of input ImageStack must be 32"); } // Initialize result array int nSlices = image.getSize(); float[][] slices = new float[nSlices][]; // Extract inner slice array and apply type conversion Object[] array = image.getImageArray(); for (int i = 0; i < nSlices; i++) { slices[i] = (float[]) array[i]; } // return slices return slices; }
@Override public FileInfo getFileInfo() { final FileInfo fi = super.getFileInfo(); // changes to fileinfo fi.nImages = getImageStackSize(); if (fi.nImages > 1) fi.pixels = getImageStack().getImageArray(); return fi; }
public FloatStackWrapper(ImageStack stack) { // Check type if (stack.getBitDepth() != 32) { throw new IllegalArgumentException("Requires a 32-bits stack"); } // store stack size this.sizeX = stack.getWidth(); this.sizeY = stack.getHeight(); this.sizeZ = stack.getSize(); // Convert slices type this.slices = new float[sizeZ][]; Object[] array = stack.getImageArray(); for (int i = 0; i < sizeZ; i++) { slices[i] = (float[]) array[i]; } }
public ShortStackWrapper(ImageStack stack) { // Check type if (stack.getBitDepth() != 16) { throw new IllegalArgumentException("Requires a 16-bits stack"); } // store stack size this.sizeX = stack.getWidth(); this.sizeY = stack.getHeight(); this.sizeZ = stack.getSize(); // Convert slices type this.slices = new short[sizeZ][]; Object[] array = stack.getImageArray(); for (int i = 0; i < sizeZ; i++) { slices[i] = (short[]) array[i]; } }
public ByteStackWrapper(ImageStack stack) { // Check type if (stack.getBitDepth() != 8) { throw new IllegalArgumentException("Requires a 8-bits stack"); } // store stack size this.sizeX = stack.getWidth(); this.sizeY = stack.getHeight(); this.sizeZ = stack.getSize(); // Convert slices type this.slices = new byte[sizeZ][]; Object[] array = stack.getImageArray(); for (int i = 0; i < sizeZ; i++) { slices[i] = (byte[]) array[i]; } }
/** Creates a wrapper {@code Image} of the given {@code ImagePlus} object. This is done by checking the element type and calling the wrapper constructor of the corresponding {@code Image} subclass. @param imageplus The {@code ImagePlus} object whose image data is to be wrapped. @return A wrapper {@code Image} object of the given {@code ImagePlus} object. The two objects share the actual image data. @throws IllegalArgumentException If the elements of {@code imageplus} are of a non-supported type. @throws NullPointerException If {@code imageplus} is {@code null}. */ public static Image wrap(final ImagePlus imageplus) { final Object[] slices = imageplus.getImageStack().getImageArray(); if (slices[0] instanceof byte[]) return new ByteImage(imageplus); if (slices[0] instanceof short[]) return new ShortImage(imageplus); if (slices[0] instanceof float[]) return new FloatImage(imageplus); if (slices[0] instanceof int[]) return new ColorImage(imageplus); throw new IllegalArgumentException("Non-supported data type"); }
protected void loadSlice(int [][] i, ImageStack s, int io) // Load a slice io from stack s into image i. { if (io < 1 || io > s.getSize()) { IJ.error("loadSlice: slice index out of bounds (" + io+"><1-"+s.getSize()+")"); return; } Object [] stack = s.getImageArray(); // Determine type of image in stack. if (stack[0] instanceof byte[]) loadImage(i, (byte []) s.getPixels(io)); else if (stack[0] instanceof int[]) loadImage(i, (int []) s.getPixels(io)); else IJ.error("loadSlice: image type not supported."); } protected void loadImage(int [][] i, byte [] b)
/** Sets the ImageProcessor, Roi, AWT Image and stack image arrays to null. Does nothing if the image is locked. */ public synchronized void flush() { notifyListeners(CLOSED); if (locked || ignoreFlush) return; ip = null; if (roi!=null) roi.setImage(null); roi = null; if (stack!=null && stack.viewers(-1)<=0) { Object[] arrays = stack.getImageArray(); if (arrays!=null) { for (int i=0; i<arrays.length; i++) arrays[i] = null; } if (isComposite()) ((CompositeImage)this).setChannelsUpdated(); //flush } setStackNull(); img = null; win = null; if (roi!=null) roi.setImage(null); roi = null; properties = null; //calibration = null; overlay = null; flatteningCanvas = null; }
/** Load a slice io from stack s into image i. */ protected void loadSlice(short [][] i, ImageStack s, int io) { if (io < 1 || io > s.getSize()) { IJ.error("loadSlice: slice index out of bounds (" + io+"><1-"+s.getSize()+")"); return; } Object [] stack = s.getImageArray(); // Determine type of image in stack. if (stack[0] instanceof byte[]) loadImage(i, (byte []) s.getPixels(io)); else if (stack[0] instanceof short[]) loadImage(i, (short []) s.getPixels(io)); else IJ.error("loadSlice: image type not supported."); } /** Load an image b into i. */
/** Sets the ImageProcessor, Roi, AWT Image and stack image arrays to null. Does nothing if the image is locked. */ public synchronized void flush() { notifyListeners(CLOSED); if (locked || ignoreFlush) return; ip = null; if (roi!=null) roi.setImage(null); roi = null; if (stack!=null && stack.viewers(-1)<=0) { Object[] arrays = stack.getImageArray(); if (arrays!=null) { for (int i=0; i<arrays.length; i++) arrays[i] = null; } if (isComposite()) ((CompositeImage)this).setChannelsUpdated(); //flush } setStackNull(); img = null; win = null; if (roi!=null) roi.setImage(null); roi = null; properties = null; //calibration = null; overlay = null; flatteningCanvas = null; }
final Object[] slices = imageplus.getImageStack().getImageArray(); if (!(slices[0] instanceof short[])) throw new IllegalArgumentException("Wrong input type");
final Object[] slices = imageplus.getImageStack().getImageArray(); if (!(slices[0] instanceof float[])) throw new IllegalArgumentException("Wrong input type");
final Object[] slices = imageplus.getImageStack().getImageArray(); if (!(slices[0] instanceof byte[])) throw new IllegalArgumentException("Wrong input type");