ImagePlus refreshes although it shouldnt

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

ImagePlus refreshes although it shouldnt

Heerpa
Dear all,

I am currently trying to develop a plugin, which alters the pixel values of
a stack and has the option to keep the original stack. If I use this option
though, the old image also displays the new data - which I cannot
understand.

Basically what I do is I get the stack from the imp I get from the setup()
    ImageStack stack = imp.getImageStack();
Then create a new stack in which I copy the stack
    ImageStack newStack = new ImageStack();
    newStack = makeStack(stack);
Then manipulate this stack and create a new ImagePlus containing this stack.
    ImagePlus newImp = new ImagePlus(title, newStack);
Then I show it
    newImp.show();
and once I do this, the imp I started with changes, too!
Do you know why? Did I do anything by reference or something like that?

Actually, I couldn't find what makeStack(stack) does (I always use the API
or Google to guide me, and did not get a hit on makeStack) but I guess it
copies the data from stack to the newStack..

The whole thing is based on the LOCI bio formats stack slicer
(http://dev.loci.wisc.edu/trac/java/browser/trunk/components/loci-plugins/sr
c/loci/plugins/Slicer.java).

Best
   Heinrich
Reply | Threaded
Open this post in threaded view
|

Re: ImagePlus refreshes although it shouldnt

Michael Schmid
Hi Heinrich,

it seems that none of your commands duplicates the image data, so you get two images based on the same data.

You can use imp.duplicate() to duplicate all the image data, or duplicate() of an ImageProcessor, or clone() of a pixels array.

As I understand makeStack in line 284 of http://trac.openmicroscopy.org.uk/ome/browser/bioformats.git/components/loci-plugins/src/loci/plugins/Slicer.java:
It creates an empty stack of the same image width and height as the argument, unless the argument is a BFVirtualStack (where it essentially creates a new BFVirtualStack based on the same path, so it can define the stack slices without affecting the original stack).
The command that actually fills in the stack slices is in line 128; it does not duplicate the image data.

Michael
________________________________________________________________
On Apr 12, 2012, at 11:24, Heinrich Grabmayr wrote:

> Dear all,
>
> I am currently trying to develop a plugin, which alters the pixel values of
> a stack and has the option to keep the original stack. If I use this option
> though, the old image also displays the new data - which I cannot
> understand.
>
> Basically what I do is I get the stack from the imp I get from the setup()
>    ImageStack stack = imp.getImageStack();
> Then create a new stack in which I copy the stack
>    ImageStack newStack = new ImageStack();
>    newStack = makeStack(stack);
> Then manipulate this stack and create a new ImagePlus containing this stack.
>    ImagePlus newImp = new ImagePlus(title, newStack);
> Then I show it
>    newImp.show();
> and once I do this, the imp I started with changes, too!
> Do you know why? Did I do anything by reference or something like that?
>
> Actually, I couldn't find what makeStack(stack) does (I always use the API
> or Google to guide me, and did not get a hit on makeStack) but I guess it
> copies the data from stack to the newStack..
>
> The whole thing is based on the LOCI bio formats stack slicer
> (http://dev.loci.wisc.edu/trac/java/browser/trunk/components/loci-plugins/sr
> c/loci/plugins/Slicer.java).
>
> Best
>   Heinrich