ImagePlus.setSlice() seems to not work anymore

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ImagePlus.setSlice() seems to not work anymore

Stephan Preibisch
Hi guys,

I noticed that calling ImagePlus.setSlice() does not result anymore in displaying the selected slice. Also an ImagePlus.updateAndDraw() call afterwards has no effect. I see that in the source code there is a new variable "noUpdateMode", which seems to cause that ...

There is also a new method setPosition() which actually works. However, I am a bit confused why that changed and when to use each of both? Should I replace all setSlice() calls with setPosition() calls in my plugins?

Thanks for your help and nice greetings,
Stephan
Reply | Threaded
Open this post in threaded view
|

Re: ImagePlus.setSlice() seems to not work anymore

Rasband, Wayne (NIH/NIMH) [E]
On Mar 28, 2012, at 4:59 PM, Stephan Preibisch wrote:

> Hi guys,
>
> I noticed that calling ImagePlus.setSlice() does not result anymore in displaying the selected slice. Also an ImagePlus.updateAndDraw() call afterwards has no effect. I see that in the source code there is a new variable "noUpdateMode", which seems to cause that ...
>
> There is also a new method setPosition() which actually works. However, I am a bit confused why that changed and when to use each of both? Should I replace all setSlice() calls with setPosition() calls in my plugins?
>
> Thanks for your help and nice greetings,
> Stephan

The legacy ImagePlus.setSlice() method displays the selected stack image. Here is a JavaScript example that opens a 256 image stack, displays the 100th image and then, two seconds later, displays the 200th image.

  imp = IJ.createImage("Untitled", "8-bit Ramp", 256, 256, 256);
  imp.show();
  imp.setSlice(100);
  IJ.wait(2000);
  imp.setSlice(200);

With Hyperstacks, you need to use setPosition() or setZ() (ImageJ 1.46d or later) to set the Z position. Here is an example that opens a hyperstack with 3 channels, 10 slices and 20 frames, displays the 4th slice and 2 seconds later, displays the 8th slice.

  IJ.run("Hyperstack...", "title=HyperStack type=8-bit display=Composite "
     +"width=300 height=200 channels=3 slices=10 frames=20 label");
  imp = IJ.getImage();
  imp.setZ(4);
  IJ.wait(2000);
  imp.setZ(8);

-wayne