Accessing voxels in javascript


#1

Can someone explain how to read (and then write) the voxels in a stack using javascript? I get indexoutofbounds errors in current efforts. [noob in JS]
I have an open image (512x512x100z), then:

imp = IJ.getImage();
stk = imp.getStack();   // (stk.getWidth Height slices vals ok as reported)
tst=stk.getVoxel(1,1,0); //this line fails with any/all vals in range I've tried

same result if I try imp.getStack().getVoxel(1,1,0) approach.
What am I missing?
Is this a good approach, or is there a better way?
thanks


#2

The following script works for me:

importClass(Packages.ij.IJ);

imp = IJ.openImage("http://imagej.nih.gov/ij/images/bat-cochlea-volume.zip");
stk = imp.getStack();
tst = stk.getVoxel(1,1,0);

print(tst); // prints 0

Are you sure your active image is a stack and has the correct dimensions?

If you keep having issues, maybe you can post a sample image that reproduces the problem?


That depends on what you want to achieve. In many cases, you don’t need to go down to the level of single pixel access, but you can use functions or filters that provide a high-level access.

Why don’t you tell us a bit more about your goals?