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 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; }
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 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); } }
void reverse(){ for(int iSlice = 1; iSlice < numSlices; iSlice++){ stack.addSlice(stack.getSliceLabel(1), stack.getProcessor(1),numSlices - iSlice + 1); stack.deleteSlice(1); } imp.setStack(null,stack); imp.updateAndDraw(); } void sortByLabel(){
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; }
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 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; }
public void makeTransition(ImagePlus imp, int from, int num) { ImageStack stack = imp.getStack(); int w = imp.getWidth(), h = imp.getHeight(); ImageProcessor fr = stack.getProcessor(from).duplicate(); ImageProcessor to = stack.getProcessor(from + 1); int[] col = new int[h]; for(int n = 0; n < num; n++) { for(int x = n; x < w; x += num) { to.getColumn(x, 0, col, h); fr.putColumn(x, 0, col, h); } stack.addSlice("", fr, from + n); } } }
void first(){ if(slice!=1){ stack.addSlice(stack.getSliceLabel(slice), stack.getProcessor(slice),0); stack.deleteSlice(slice+1); imp.setStack(null,stack); imp.setSlice(1); imp.updateAndDraw(); } } void bkwd(){
/** * 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 void createCase(int confID) { byte value = (byte)255; ImageStack stack = new ImageStack(2,2); stack.addSlice("", new ByteProcessor(2,2)); stack.addSlice("", new ByteProcessor(2,2)); data = new byte[2][]; data[0] = (byte[])stack.getProcessor(1).getPixels(); data[1] = (byte[])stack.getProcessor(2).getPixels(); if(confID>=128) {data[1][0]=value;confID-=128;} if(confID>=64) {data[1][1]=value;confID-=64;} if(confID>=32) {data[1][3]=value;confID-=32;} if(confID>=16) {data[1][2]=value;confID-=16;} if(confID>=8) {data[0][0]=value;confID-=8;} if(confID>=4) {data[0][1]=value;confID-=4;} if(confID>=2) {data[0][3]=value;confID-=2;} if(confID>=1) {data[0][2]=value;confID-=1;} image = new ImagePlus("", stack); }
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; } }
public void makeTransition(ImagePlus imp, int from, int num) { ImageStack stack = imp.getStack(); int w = imp.getWidth(), h = imp.getHeight(); ImageProcessor fr = stack.getProcessor(from).duplicate(); ImageProcessor to = stack.getProcessor(from + 1); int[] row = new int[w]; for(int n = 0; n < num; n++) { for(int y = n; y < h; y += num) { to.getRow(0, y, row, w); fr.putRow(0, y, row, w); } stack.addSlice("", fr, from + n); } } }
void last(){ if(slice!=numSlices){ stack.addSlice(stack.getSliceLabel(slice), stack.getProcessor(slice),numSlices); stack.deleteSlice(slice); imp.setStack(null,stack); imp.setSlice(numSlices); imp.updateAndDraw(); } } void dup(){
/** * 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 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; }