public ImagePlus[] getDisplacementField( ) { ImagePlus[] results = new ImagePlus[3]; ImageStack[] stack = new ImageStack[3]; for (int i = 0; i < 3; i++) stack[i] = new ImageStack(template.w, template.h); for (int k = 0; k < template.d; k++) { float[][] slice = new float[3][]; for (int i = 0; i < 3; i++) slice[i] = new float[template.w * template.h]; for (int j = 0; j < template.w * template.h; j++) //if (getLabel(j % w, j / w, k) != 0) for (int i = 0; i < 3; i++) slice[i][j] = displace[k][3 * j + i]; for (int i = 0; i < 3; i++) stack[i].addSlice("", slice[i]); } for (int i = 0; i < 3; i++) results[i] = new ImagePlus("displace "+i, stack[i]); return results; }
/** * Create an ImageJ ImageStack out of a float matrix. width is the width of each image. * @param a a float[][] matrix with the images as column vectors. * @param width the width of each image in pixels. * @return an ImageStack. */ public static ImageStack imageStackFromMatrix(short [][] a, int width) { ImageStack is = new ImageStack(width, a[0].length / width); for (int j = 0; j < a.length; j++) is.addSlice(""+j, new ShortProcessor(width, a[0].length / width, a[j], null)); return is; } /**
private ImagePlus createBinary(ImagePlus image, int value) { int w = image.getWidth(), h = image.getWidth(); int d = image.getStackSize(); ImageStack stack = new ImageStack(w, h); for(int z = 0; z < d; z++) { byte[] f = new byte[w*h]; byte[] p = (byte[])image.getStack() .getProcessor(z+1).getPixels(); for(int i = 0; i < w*h; i++) f[i] = (int)(p[i]&0xff) == value ? (byte)255 : 0; stack.addSlice("", new ByteProcessor(w, h, f, null)); } return new ImagePlus("Label_" + (int)(value&0xff), stack); }
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; }
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; }
/** This method has been replaced by IJ.createHyperStack(). */ public ImagePlus createHyperStack(String title, int channels, int slices, int frames, int bitDepth) { int size = channels*slices*frames; ImageStack stack2 = new ImageStack(width, height, size); // create empty stack ImageProcessor ip2 = null; switch (bitDepth) { case 8: ip2 = new ByteProcessor(width, height); break; case 16: ip2 = new ShortProcessor(width, height); break; case 24: ip2 = new ColorProcessor(width, height); break; case 32: ip2 = new FloatProcessor(width, height); break; default: throw new IllegalArgumentException("Invalid bit depth"); } stack2.setPixels(ip2.getPixels(), 1); // can't create ImagePlus will null 1st image ImagePlus imp2 = new ImagePlus(title, stack2); stack2.setPixels(null, 1); imp2.setDimensions(channels, slices, frames); imp2.setCalibration(getCalibration()); imp2.setOpenAsHyperStack(true); return imp2; }
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); }
private void doHSRGBProjection(ImagePlus rgbImp) { ImageStack stack = rgbImp.getStack(); ImageStack stack2 = new ImageStack(stack.getWidth(), stack.getHeight()); for (int i=startSlice; i<=stopSlice; i++) stack2.addSlice(null, stack.getProcessor(i)); startSlice = 1; stopSlice = stack2.getSize(); doRGBProjection(stack2); }
public ImagePlus toFloat() { ImageStack stack = new ImageStack(w, h); for(int z = 0; z < d; z++) { stack.addSlice("",new FloatProcessor(w,h,dist[z],null)); } return new ImagePlus("Distance", stack); }
/** 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; }
/** * Create an ImageJ ImageStack out of a float matrix. width is the width of each image. * @param a a float[][] matrix with the images as column vectors. * @param width the width of each image in pixels. * @return an ImageStack. */ public static ImageStack imageStackFromMatrix(float [][] a, int width) { ImageStack is = new ImageStack(width, a[0].length / width); for (int j = 0; j < a.length; j++) is.addSlice(""+j, new FloatProcessor(width, a[j].length / width, a[j], null)); return is; } /**
public ImagePlus compute(ImageStack stack) { w = stack.getWidth(); h = stack.getHeight(); d = stack.getSize(); ImageStack result = new ImageStack(w, h, d); for (int i = 1; i <= d; i++) result.setPixels(new float[w * h], i); current = 0; total = w * h * d * 3; new Z(stack, result).compute(); new Y(result).compute(); new X(result).compute(); return new ImagePlus("EDT", result); }
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); }
private static ImageStack getVolume(ImagePlus imp, int c, int t) { ImageStack stack1 = imp.getStack(); ImageStack stack2 = new ImageStack(imp.getWidth(), imp.getHeight()); if (imp.getNSlices()==1) { for (t=1; t<=imp.getNFrames(); t++) { int n = imp.getStackIndex(c, 1, t); stack2.addSlice(stack1.getProcessor(n)); } } else { for (int z=1; z<=imp.getNSlices(); z++) { int n = imp.getStackIndex(c, z, t); stack2.addSlice(stack1.getProcessor(n)); } } return stack2; }
private void show(int n) { ImageStack stack = new ImageStack(w, h); for(int z = 0; z < d; z++) { stack.addSlice("", new FloatProcessor( w, h, u[n][z], null)); } new ImagePlus("Displacement_dim" + n, stack).show(); }
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; } }
/** * Called from constructor Image5D(String title, ImageProcessor ip) in call to * this(). Checks if ip is null and creates a stack from it. */ static private ImageStack createStackFromProcessor(final ImageProcessor ip) { if (ip == null) throw new IllegalArgumentException( "ImageProcessor is null."); final ImageStack is = new ImageStack(ip.getWidth(), ip.getHeight(), ip.getColorModel()); is.addSlice("", ip); return is; }
private void doHSRGBProjection(ImagePlus rgbImp) { ImageStack stack = rgbImp.getStack(); ImageStack stack2 = new ImageStack(stack.getWidth(), stack.getHeight()); for (int i=startSlice; i<=stopSlice; i++) stack2.addSlice(null, stack.getProcessor(i)); startSlice = 1; stopSlice = stack2.getSize(); doRGBProjection(stack2); }
public ImagePlus createResult() { ImageStack stack = new ImageStack(w, h); for(int z = 0; z < d; z++) { stack.addSlice("", new ColorProcessor(w, h, result[z])); } ImagePlus ret = new ImagePlus("Result", stack); ret.setCalibration(image.getCalibration()); return ret; }
/** 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; }