![]() | ![]() |
![]() |
Previous Message |
Next Message Previous in Topic | Next in Topic Previous by Same Author | Next by Same Author Previous Page (May 2002) | Back to Main IMAGEJ Page | | ![]()
Reply
| Post a New Message |
Join or Leave IMAGEJ, or Change Options
|
Search | ![]()
Chronologically |
Most Recent First |
Wrap Text (Proportional Font) |
Don't Wrap Text (Non-proportional Font) | ![]() |
Delivered-To: [log in to unmask]@fixme References: <[log in to unmask]> Content-Type: multipart/mixed; Message-ID: <[log in to unmask]> Date: Fri, 31 May 2002 17:09:07 -0700 Reply-To: [log in to unmask] Sender: ImageJ Interest Group <[log in to unmask]> From: Bob Dougherty <[log in to unmask]> Organization: OptiNav, Inc. Subject: Re: 3-D samplesAditya, Here is a plugin that makes ellipsoids. To run a test case, you should not alter any of the dialog inputs. Try f0 = 10 for a larger ellipsoid. By changing the function at the end, you could make just about anything. (For a complicated function, the structure of the code should be different, of course.) Bob > Can anyone provide me or direct me to links where I can find image stacks, > similar to the mri-stack example in ImageJ. > Even a simple stack of cirles(when stacked becomes a sphere) or ellipses > would help. -- Robert Dougherty President, OptiNav, Inc. (425) 467-1118 [log in to unmask] http://www.optinav.com
import ij.*; import ij.plugin.filter.PlugInFilter; import ij.process.*; import ij.*; import ij.plugin.PlugIn; import ij.gui.*; import ij.process.*; import ij.io.*; /** Example plugin to represent 3D shapes as stacks. The shape is represented by the function fun(double x, double y, double z). This function should return a value that is negative or zero if (x,y,z) is inside the object, and positive otherwise. */ public class Make_3D_Stack implements PlugIn { double w = 255; double h = 255; double d = 255; int nx = 256; int ny = 256; int nz = 256; double x0 = 0; double y0 = 0; double z0 = 0; double f0 = 0; boolean canceled = false; double xC, yC, zC; public void run(String arg) { getGrid(); if(canceled)return; double hx,hy,hz; if (nx == 1){ hx = 0; } else { hx = w/(nx - 1); } if (ny == 1){ hy = 0; } else { hy = h/(ny - 1); } if (nz == 1){ hz = 0; } else { hz = d/(nz - 1); } xC = (x0 + (x0 + hx*(nx - 1)))/2; yC = (y0 + (y0 + hy*(ny - 1)))/2; zC = (z0 + (z0 + hz*(nz - 1)))/2; ImageStack stack = new ImageStack(nx,ny); for (int k = 0; k < nz; k++){ IJ.showStatus("Processing slice "+(k+1)+"/"+nz); ByteProcessor bp = new ByteProcessor(nx,ny); byte[] pixels = (byte[])bp.getPixels(); double z = z0 + k*hz; for (int j = 0; j < ny; j++){ double y = y0 + j*hy; for (int i = 0; i < nx; i++){ double x = x0 + i*hx; double f = fun(x,y,z); if (f <= f0){ pixels[i + nx*j] = (byte)255; } else { pixels[i + nx*j] = (byte)0; } } } stack.addSlice(IJ.d2s(z,2),bp); } ImagePlus imp = new ImagePlus("3D shape",stack); imp.show(); } void getGrid() { GenericDialog gd = new GenericDialog("3D grid definition...", IJ.getInstance()); gd.addNumericField("horizontal pixels, nx", nx, 0); gd.addNumericField("vertical pixels ny", ny, 0); gd.addNumericField("slices nz", nz, 0); gd.addNumericField("width (x)", w, 3); gd.addNumericField("height (y)", h, 3); gd.addNumericField("depth (z)", d, 3); gd.addNumericField("x value of left side, x0", x0, 3); gd.addNumericField("y value of top, y0", y0, 3); gd.addNumericField("z value of first slice, z0", z0, 3); gd.addNumericField("f0. (x,y,z) is included if f(x,y,z) <= f0", f0, 3); gd.showDialog(); if (gd.wasCanceled()) { canceled = true; return; } nx = (int)gd.getNextNumber(); ny = (int)gd.getNextNumber(); nz = (int)gd.getNextNumber(); w = (double)gd.getNextNumber(); h = (double)gd.getNextNumber(); d = (double)gd.getNextNumber(); x0 = (double)gd.getNextNumber(); y0 = (double)gd.getNextNumber(); z0 = (double)gd.getNextNumber(); f0 = (double)gd.getNextNumber(); } public double fun(double x, double y, double z){ double xr = x - xC; double yr = y - yC; double zr = z - zC; double f = Math.sqrt(xr*xr/4 + yr*yr + zr*zr) - 50; return f; } }
![]() |
![]() Center for Information Technology National Institutes of Health Bethesda, Maryland 20892 301 594 6248 (v) 301 496 8294 (TDD) Comments and Assistance Accessibility ![]() |