/** Experimental */ public void setVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels, int channel) { if (getBitDepth()!=24) { setVoxels(x0, y0, z0, w, h, d, voxels); return; } boolean inBounds = x0>=0 && x0+w<=width && y0>=0 && y0+h<=height && z0>=0 && z0+d<=nSlices; if (voxels==null || voxels.length!=w*h*d) ; int i = 0; for (int z=z0; z<z0+d; z++) { int[] ints = (int[])stack[z]; for (int y=y0; y<y0+h; y++) { for (int x=x0; x<x0+w; x++) { int value = inBounds?ints[y*width+x]&0xffffffff:(int)getVoxel(x, y, z); int color = (int)voxels[i++]; switch (channel) { case 0: value=(value&0xff00ffff) | ((color&0xff)<<16); break; case 1: value=(value&0xffff00ff) | ((color&0xff)<<8); break; case 2: value=(value&0xffffff00) | (color&0xff); break; } if (inBounds) ints[y*width+x] = value; else setVoxel(x, y, z, value); } } } }
/** Experimental */ public void setVoxels(int x0, int y0, int z0, int w, int h, int d, float[] voxels, int channel) { if (getBitDepth()!=24) { setVoxels(x0, y0, z0, w, h, d, voxels); return; } boolean inBounds = x0>=0 && x0+w<=width && y0>=0 && y0+h<=height && z0>=0 && z0+d<=nSlices; if (voxels==null || voxels.length!=w*h*d) ; int i = 0; for (int z=z0; z<z0+d; z++) { int[] ints = (int[])stack[z]; for (int y=y0; y<y0+h; y++) { for (int x=x0; x<x0+w; x++) { int value = inBounds?ints[y*width+x]&0xffffffff:(int)getVoxel(x, y, z); int color = (int)voxels[i++]; switch (channel) { case 0: value=(value&0xff00ffff) | ((color&0xff)<<16); break; case 1: value=(value&0xffff00ff) | ((color&0xff)<<8); break; case 2: value=(value&0xffffff00) | (color&0xff); break; } if (inBounds) ints[y*width+x] = value; else setVoxel(x, y, z, value); } } } }
private static void blurZ(ImageStack stack, double sigmaZ) { GaussianBlur gb = new GaussianBlur(); double accuracy = (stack.getBitDepth()==8||stack.getBitDepth()==24)?0.002:0.0002; int w=stack.getWidth(), h=stack.getHeight(), d=stack.getSize(); float[] zpixels = null; FloatProcessor fp =null; IJ.showStatus("Z blurring"); gb.showProgress(false); int channels = stack.getProcessor(1).getNChannels(); for (int y=0; y<h; y++) { IJ.showProgress(y, h-1); for (int channel=0; channel<channels; channel++) { zpixels = stack.getVoxels(0, y, 0, w, 1, d, zpixels, channel); if (fp==null) fp = new FloatProcessor(w, d, zpixels); //if (y==h/2) new ImagePlus("before-"+h/2, fp.duplicate()).show(); gb.blur1Direction(fp, sigmaZ, accuracy, false, 0); stack.setVoxels(0, y, 0, w, 1, d, zpixels, channel); } } IJ.showStatus(""); }
private static void blurZ(ImageStack stack, double sigmaZ) { GaussianBlur gb = new GaussianBlur(); double accuracy = (stack.getBitDepth()==8||stack.getBitDepth()==24)?0.002:0.0002; int w=stack.getWidth(), h=stack.getHeight(), d=stack.getSize(); float[] zpixels = null; FloatProcessor fp =null; IJ.showStatus("Z blurring"); gb.showProgress(false); int channels = stack.getProcessor(1).getNChannels(); for (int y=0; y<h; y++) { IJ.showProgress(y, h-1); for (int channel=0; channel<channels; channel++) { zpixels = stack.getVoxels(0, y, 0, w, 1, d, zpixels, channel); if (fp==null) fp = new FloatProcessor(w, d, zpixels); //if (y==h/2) new ImagePlus("before-"+h/2, fp.duplicate()).show(); gb.blur1Direction(fp, sigmaZ, accuracy, false, 0); stack.setVoxels(0, y, 0, w, 1, d, zpixels, channel); } } IJ.showStatus(""); }