Login  Register

Re: how to update ImagePlus in Python

Posted by Aryeh Weiss on Feb 26, 2015; 3:46am
URL: http://imagej.273.s1.nabble.com/how-to-update-ImagePlus-in-Python-tp5011768p5011778.html

On 2/25/15 9:55 PM, Rasband, Wayne (NIH/NIMH) [E] wrote:

> On Feb 25, 2015, at 10:40 AM, Aryeh Weiss <[hidden email]> wrote:
>> I have an  ImagePlus that was created by loading a stack from a file.
>> I am trying to remove a single slice as follows:
>>
>> # this stack has 6 slices
>> inputStack = impInput.getImageStack()
>> inputStack.deleteSlice(6)
>>
>> impInput.show()
>>
>> print impInput.getNChannels()
>> # this command now prints 5
>>
>> dupStack = inputStack.duplicate()
>> impTest = ImagePlus("lksdfj", dupStack)
>> impTest.show()
>>
>> The original image (impInput), appears with on slice missing (as expected, but it is the wrong slice, and the information overthe image is not completely correct (it shows 5 slices, but still thins it has 6 channels).
>>
>> The duplicated stack (dupStack) was used to create a new imp (impText). This image is shown correctly, with the correct slice removed.
>> However, it still says c:5/6 over the image..
>>
>> What is the correct way to manipulate an ImageStack, and then update the ImagePlus and ImageProcessr?
> Get the stack, delete or add slices, set the stack. Here is a JavaScript example:
>
>    img = IJ.openImage("http://imagej.nih.gov/ij/images/t1-rendering.zip");
>    img.show();
>    stack = img.getStack();
>    stack.deleteSlice(20);
>    img.setStack(stack);
>
> -wayne
>
Thank you Wayne -- works as advertised.

I still see that at the top of the image, the information shows (for
example for the first image in the stack):
1/5 (c:1/6 - Series 1); ...

Before I removed a slice it showed:
1/6 (c:1/6 - Series 1); ...

This occurs also if I use the GUI to remove a slice  -- it is not
related to the scripting.

Is this a bug, or is it expected, and there is a way to update the part
with c: 1/6?

--aryeh



>> I looked in the tutorials (which are very nice), but the examples I found had the stacks being built "fresh". My confusion is how to deal with an existing imp. I suppose I could create a new imp each time I do something, but that does not seem to be the right way.
>>
>> Thanks in advance.
>> --aryeh
>>
>> --
>> Aryeh Weiss
>> Faculty of Engineering
>> Bar Ilan University
>> Ramat Gan 52900 Israel
>>
>> Ph:  972-3-5317638
>> FAX: 972-3-7384051
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html