/** * Performs dilation with a ball structuring element by calling the ImageJ * Filters3D.filter method, using Filters3D.MAX option. * * @param image * the 3D stack to process */ @Override public ImageStack dilation(ImageStack image) { float r = (float) this.radius; ImageStack result = Filters3D.filter(image, Filters3D.MAX, r, r, r); result.setColorModel( image.getColorModel() ); return result; }
/** * Performs erosion with a ball structuring element by calling the ImageJ * Filters3D.filter method, using Filters3D.MIN option. * * @param image * the 3D stack to process */ @Override public ImageStack erosion(ImageStack image) { float r = (float) this.radius; ImageStack result = Filters3D.filter(image, Filters3D.MIN, r, r, r); result.setColorModel( image.getColorModel() ); return result; } }
/** * Performs dilation with a ball structuring element by calling the ImageJ * Filters3D.filter method, using Filters3D.MAX option. * * @param image * the 3D stack to process * @return the result of the dilation */ @Override public ImageStack dilation(ImageStack image) { float rx = (float) this.xRadius; float ry = (float) this.yRadius; float rz = (float) this.zRadius; ImageStack result = Filters3D.filter(image, Filters3D.MAX, rx, ry, rz); result.setColorModel( image.getColorModel() ); return result; }
/** * Performs erosion with a ball structuring element by calling the ImageJ * Filters3D.filter method, using Filters3D.MIN option. * * @param image * the 3D stack to process * @return the result of the erosion */ @Override public ImageStack erosion(ImageStack image) { float rx = (float) this.xRadius; float ry = (float) this.yRadius; float rz = (float) this.zRadius; ImageStack result = Filters3D.filter(image, Filters3D.MIN, rx, ry, rz); result.setColorModel( image.getColorModel() ); return result; } }
/** * Returns a binary image that contains only the largest label. * * @param image * a binary 3D image containing several individual regions * @return a new binary image containing only the largest region from * original image */ public static final ImageStack keepLargestRegion(ImageStack image) { ImageStack labelImage = componentsLabeling(image, 6, 16); ImageStack result = binarize(LabelImages.keepLargestLabel(labelImage)); result.setColorModel(image.getColorModel()); return result; }
/** * Returns a binary image in which the largest region has been replaced by * the background value. * * @param image * a binary 3D image containing several individual particles * @return a new binary image containing all the regions from original image * but the largest one */ public static final ImageStack removeLargestRegion(ImageStack image) { ImageStack labelImage = componentsLabeling(image, 6, 16); LabelImages.removeLargestLabel(labelImage); ImageStack result = binarize(labelImage); result.setColorModel(image.getColorModel()); return result; }
public ImageStack makeSubStack(ImageStack stack, int beginSlice, int endSlice) { ImageStack newStack = new ImageStack(stack.getWidth(), stack.getHeight(), stack.getColorModel()); for(int i = beginSlice; i < endSlice; ++i) { newStack.addSlice(stack.getProcessor(i+1)); } return newStack; }
/** Creates a new stack by cropping this one. */ public ImageStack crop(int x, int y, int z, int width, int height, int depth) { if (x<0||y<0||z<0||x+width>this.width||y+height>this.height||z+depth>getSize()) throw new IllegalArgumentException("Argument out of range"); ImageStack stack2 = new ImageStack(width, height, getColorModel()); for (int i=z; i<z+depth; i++) { ImageProcessor ip2 = this.getProcessor(i+1); ip2.setRoi(x, y, width, height); ip2 = ip2.crop(); stack2.addSlice(this.getSliceLabel(i+1), ip2); } return stack2; }
/** Creates a new stack by cropping this one. */ public ImageStack crop(int x, int y, int z, int width, int height, int depth) { if (x<0||y<0||z<0||x+width>this.width||y+height>this.height||z+depth>getSize()) throw new IllegalArgumentException("Argument out of range"); ImageStack stack2 = new ImageStack(width, height, getColorModel()); for (int i=z; i<z+depth; i++) { ImageProcessor ip2 = this.getProcessor(i+1); ip2.setRoi(x, y, width, height); ip2 = ip2.crop(); stack2.addSlice(this.getSliceLabel(i+1), ip2); } return stack2; }
/** Creates a float version of this stack. */ public ImageStack convertToFloat() { ImageStack stack2 = new ImageStack(width, height, getColorModel()); for (int i=1; i<=getSize(); i++) { ImageProcessor ip2 = this.getProcessor(i); ip2 = ip2.convertToFloat(); stack2.addSlice(this.getSliceLabel(i), ip2); } return stack2; }
public ImageStack makeShuffled(ImageStack stack) { ImageStack newStack = new ImageStack(stack.getWidth(), stack.getHeight(), stack.getColorModel()); for(int channel = 0; channel < nChannels; ++channel) { for(int i = channel; i < stack.getSize(); i += nChannels) { newStack.addSlice(stack.getProcessor(i+1)); } } return newStack; } }
/** Creates a float version of this stack. */ public ImageStack convertToFloat() { ImageStack stack2 = new ImageStack(width, height, getColorModel()); for (int i=1; i<=getSize(); i++) { ImageProcessor ip2 = this.getProcessor(i); ip2 = ip2.convertToFloat(); stack2.addSlice(this.getSliceLabel(i), ip2); } return stack2; }
public ImageStack expandStack(ImageStack stackOld, int wNew, int hNew, int xOff, int yOff) { int nFrames = stackOld.getSize(); ImageProcessor ipOld = stackOld.getProcessor(1); java.awt.Color colorBack = Toolbar.getBackgroundColor(); ImageStack stackNew = new ImageStack(wNew, hNew, stackOld.getColorModel()); ImageProcessor ipNew; for (int i=1; i<=nFrames; i++) { IJ.showProgress((double)i/nFrames); ipNew = ipOld.createProcessor(wNew, hNew); if (zeroFill) ipNew.setValue(0.0); else ipNew.setColor(colorBack); ipNew.fill(); ipNew.insert(stackOld.getProcessor(i), xOff, yOff); stackNew.addSlice(stackOld.getSliceLabel(i), ipNew); } return stackNew; }
int w3 = w1 + w2; int h3 = Math.max(h1, h2); ImageStack stack3 = new ImageStack(w3, h3, stack1.getColorModel()); ImageProcessor ip = stack1.getProcessor(1); ImageProcessor ip1, ip2, ip3;
public ImageStack expandStack(ImageStack stackOld, int wNew, int hNew, int xOff, int yOff) { int nFrames = stackOld.getSize(); ImageProcessor ipOld = stackOld.getProcessor(1); java.awt.Color colorBack = Toolbar.getBackgroundColor(); ImageStack stackNew = new ImageStack(wNew, hNew, stackOld.getColorModel()); ImageProcessor ipNew; for (int i=1; i<=nFrames; i++) { IJ.showProgress((double)i/nFrames); ipNew = ipOld.createProcessor(wNew, hNew); if (zeroFill) ipNew.setValue(0.0); else ipNew.setColor(colorBack); ipNew.fill(); ipNew.insert(stackOld.getProcessor(i), xOff, yOff); stackNew.addSlice(stackOld.getSliceLabel(i), ipNew); } return stackNew; }
private ImageStack shrinkZ(ImageStack stack, int zshrink) { int w = stack.getWidth(); int h = stack.getHeight(); int d = stack.getSize(); int d2 = d/zshrink; ImageStack stack2 = new ImageStack (w, h, stack.getColorModel()); for (int z=1; z<=d2; z++) stack2.addSlice(stack.getProcessor(z).duplicate()); boolean rgb = stack.getBitDepth()==24; ImageProcessor ip = rgb?new ColorProcessor(d, h):new FloatProcessor(d, h); for (int x=0; x<w; x++) { IJ.showProgress(x+1, w); for (int y=0; y<h; y++) { float value; for (int z=0; z<d; z++) { value = (float)stack.getVoxel(x, y, z); ip.setf(z, y, value); } } ImageProcessor ip2 = shrink(ip, zshrink, 1, method); for (int x2=0; x2<d2; x2++) { for (int y2=0; y2<h; y2++) { stack2.setVoxel(x, y2, x2, ip2.getf(x2,y2)); } } } return stack2; }
private ImageStack shrinkZ(ImageStack stack, int zshrink) { int w = stack.getWidth(); int h = stack.getHeight(); int d = stack.getSize(); int d2 = d/zshrink; ImageStack stack2 = new ImageStack (w, h, stack.getColorModel()); for (int z=1; z<=d2; z++) stack2.addSlice(stack.getProcessor(z).duplicate()); boolean rgb = stack.getBitDepth()==24; ImageProcessor ip = rgb?new ColorProcessor(d, h):new FloatProcessor(d, h); for (int x=0; x<w; x++) { IJ.showProgress(x+1, w); for (int y=0; y<h; y++) { float value; for (int z=0; z<d; z++) { value = (float)stack.getVoxel(x, y, z); ip.setf(z, y, value); } } ImageProcessor ip2 = shrink(ip, zshrink, 1, method); for (int x2=0; x2<d2; x2++) { for (int y2=0; y2<h; y2++) { stack2.setVoxel(x, y2, x2, ip2.getf(x2,y2)); } } } return stack2; }
public void flipStack(ImagePlus imp) { ImageStack stack = imp.getStack(); int n = stack.getSize(); if (n==1) return; Calibration cal = imp.getCalibration(); double min = cal.getCValue(imp.getDisplayRangeMin()); double max = cal.getCValue(imp.getDisplayRangeMax()); ImageStack stack2 = new ImageStack(imp.getWidth(), imp.getHeight(), n); for (int i=1; i<=n; i++) { stack2.setPixels(stack.getPixels(i), n-i+1); stack2.setSliceLabel(stack.getSliceLabel(i), n-i+1); } stack2.setColorModel(stack.getColorModel()); imp.setStack(stack2); if (imp.isComposite()) { ((CompositeImage)imp).reset(); imp.updateAndDraw(); } IJ.setMinAndMax(imp, min, max); }
public void flipStack(ImagePlus imp) { ImageStack stack = imp.getStack(); int n = stack.getSize(); if (n==1) return; Calibration cal = imp.getCalibration(); double min = cal.getCValue(imp.getDisplayRangeMin()); double max = cal.getCValue(imp.getDisplayRangeMax()); ImageStack stack2 = new ImageStack(imp.getWidth(), imp.getHeight(), n); for (int i=1; i<=n; i++) { stack2.setPixels(stack.getPixels(i), n-i+1); stack2.setSliceLabel(stack.getSliceLabel(i), n-i+1); } stack2.setColorModel(stack.getColorModel()); imp.setStack(stack2); if (imp.isComposite()) { ((CompositeImage)imp).reset(); imp.updateAndDraw(); } IJ.setMinAndMax(imp, min, max); }
@Override public ImagePlus next() { if (nextFrame == nFrames) return null; final ImageStack oldStack = image.getStack(); final String oldTitle = image.getTitle(); final FileInfo fi = image.getFileInfo(); final ImageStack newStack = new ImageStack(w, h); newStack.setColorModel(oldStack.getColorModel()); for (int j = 0; j < nSlices; j++) { final int index = image.getStackIndex(1, j + 1, nextFrame + 1); Object pixels; if (nChannels > 1) { image.setPositionWithoutUpdate(1, j + 1, nextFrame + 1); pixels = new ColorProcessor(image.getImage()).getPixels(); } else { pixels = oldStack.getPixels(index); } newStack.addSlice(oldStack.getSliceLabel(index), pixels); } final ImagePlus ret = new ImagePlus(oldTitle + " (frame " + nextFrame + ")", newStack); ret.setCalibration(image.getCalibration().copy()); ret.setFileInfo((FileInfo) fi.clone()); nextFrame++; return ret; } }