Deleting first slice in a stack

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

Deleting first slice in a stack

simon andrews (BI)
I'm sure I must be doing this wrong, but I can't find a way to delete  
the first image in a stack.

If I have a stack of 5 images in an ImagePlus object and I call:

imp.getImageStack().deleteSlice(1);

Then the second slice is deleted.

If I call imp.getImageStack().deleteSlice(0);

Then I get an Illegal Argument exception.

How do I get rid of the first slice??

Simon.
Reply | Threaded
Open this post in threaded view
|

Re: Deleting first slice in a stack

Rasband, Wayne (NIH/NIMH) [E]
On Feb 18, 2010, at 8:41 AM, Simon Andrews wrote:

> I'm sure I must be doing this wrong, but I can't find a way to delete  
> the first image in a stack.
>
> If I have a stack of 5 images in an ImagePlus object and I call:
>
> imp.getImageStack().deleteSlice(1);
>
> Then the second slice is deleted.
>
> If I call imp.getImageStack().deleteSlice(0);
>
> Then I get an Illegal Argument exception.
>
> How do I get rid of the first slice??

This seems to work:

   ImagePlus imp = IJ.getImage();
   ImageStack stack = imp.getStack();
   stack.deleteSlice(1);
   imp.setStack(null, stack);

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: Deleting first slice in a stack

Arttu Miettinen
Hello,

Related to this, how to add a slice to the first position in a stack? In
1.43q, Image-Stacks->Add slice adds one slice after the active one. Add
slice toolbar button does the same thing.

Of course one can duplicate the first slice but that requires many mouse
clicks; it would be nice to be able to insert new slice before the active
one.

- Arttu Miettinen


> On Feb 18, 2010, at 8:41 AM, Simon Andrews wrote:
>
>> I'm sure I must be doing this wrong, but I can't find a way to delete
>> the first image in a stack.
>>
>> If I have a stack of 5 images in an ImagePlus object and I call:
>>
>> imp.getImageStack().deleteSlice(1);
>>
>> Then the second slice is deleted.
>>
>> If I call imp.getImageStack().deleteSlice(0);
>>
>> Then I get an Illegal Argument exception.
>>
>> How do I get rid of the first slice??
>
> This seems to work:
>
>    ImagePlus imp = IJ.getImage();
>    ImageStack stack = imp.getStack();
>    stack.deleteSlice(1);
>    imp.setStack(null, stack);
>
> -wayne
>
Reply | Threaded
Open this post in threaded view
|

Re: Deleting first slice in a stack

Rasband, Wayne (NIH/NIMH) [E]
On Feb 19, 2010, at 4:06 AM, Arttu Miettinen wrote:

> Hello,
>
> Related to this, how to add a slice to the first position in a stack? In
> 1.43q, Image-Stacks->Add slice adds one slice after the active one. Add
> slice toolbar button does the same thing.
>
> Of course one can duplicate the first slice but that requires many mouse
> clicks; it would be nice to be able to insert new slice before the active
> one.

Hold down the alt key while selecting Image>Stacks>Add Slice to add a blank slice before the active one.

-wayne


>> On Feb 18, 2010, at 8:41 AM, Simon Andrews wrote:
>>
>>> I'm sure I must be doing this wrong, but I can't find a way to delete
>>> the first image in a stack.
>>>
>>> If I have a stack of 5 images in an ImagePlus object and I call:
>>>
>>> imp.getImageStack().deleteSlice(1);
>>>
>>> Then the second slice is deleted.
>>>
>>> If I call imp.getImageStack().deleteSlice(0);
>>>
>>> Then I get an Illegal Argument exception.
>>>
>>> How do I get rid of the first slice??
>>
>> This seems to work:
>>
>>   ImagePlus imp = IJ.getImage();
>>   ImageStack stack = imp.getStack();
>>   stack.deleteSlice(1);
>>   imp.setStack(null, stack);
>>
>> -wayne
>>
Reply | Threaded
Open this post in threaded view
|

Re: Deleting first slice in a stack

Mike Cowperthwaite
On 19-Feb-10 7:10 am, Rasband, Wayne (NIH/NIMH) [E] wrote:

> On Feb 19, 2010, at 4:06 AM, Arttu Miettinen wrote:
>
>> Hello,
>>
>> Related to this, how to add a slice to the first position in a stack? In
>> 1.43q, Image-Stacks->Add slice adds one slice after the active one. Add
>> slice toolbar button does the same thing.
>>
>> Of course one can duplicate the first slice but that requires many mouse
>> clicks; it would be nice to be able to insert new slice before the active
>> one.
>
> Hold down the alt key while selecting Image>Stacks>Add Slice to add a blank slice before the active one.
>
> -wayne

FYI: In Windows, it's not possible to hold down Alt while navigating a
menu.  Generally, modifier keys on menu clicks are nonstandard.
Reply | Threaded
Open this post in threaded view
|

Re: Deleting first slice in a stack

jolyon
In reply to this post by Rasband, Wayne (NIH/NIMH) [E]
I ran into this very problem with both macro and plugin scripts. The workaround that I found was to reverse the stack order:

run("Reverse");

Then delete the last slice, then reverse again. Works ok, though doesn't seem to work in macro's batch mode annoyingly, so is a little slow and displays the images as it goes.

Any more elegant solution would be welcome though!
Reply | Threaded
Open this post in threaded view
|

Re: Deleting first slice in a stack

mhmh
In reply to this post by simon andrews (BI)

simon andrews (BI) wrote
If I have a stack of 5 images in an ImagePlus object and I call:

imp.getImageStack().deleteSlice(1);

Then the second slice is deleted.
I think

imp.getImageStack().deleteSlice(1);

deletes the first slice, even though you still see it with imp.show().

If you do

ImagePlus timp = new ImagePlus("test",imp.getStack());timp.show();

it's not there anymore.