Concatenate bug in macro

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

Concatenate bug in macro

Djoere Gaublomme
Hello,

In a macro, I am trying to create an image stack with 10 identical  
slices (based on 1 non-z-stack image).
Since I don't know a very elegant solution to this problem, I am using  
the concatenate function from the stack tools, with the same image as  
the input 10 times.
Although this works most of the time, sometimes the number of slices  
included in the resulting stack is too little when running the macro.  
I am wondering how this inconsistency can be fixed.

Code:
run("Concatenate...", "  title=10x-ondersteFilled keep  
image1=ondersteFilled image2=ondersteFilled image3=ondersteFilled  
image4=ondersteFilled image5=ondersteFilled image6=ondersteFilled  
image7=ondersteFilled image8=ondersteFilled image9=ondersteFilled  
image10=ondersteFilled image11=[-- None --]");


Thanks in advance

Djoere

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Concatenate bug in macro

Rasband, Wayne (NIH/NIMH) [E]
On Feb 19, 2015, at 8:29 AM, Djoere Gaublomme <[hidden email]> wrote:
>
> Hello,
>
> In a macro, I am trying to create an image stack with 10 identical slices (based on 1 non-z-stack image).
> Since I don't know a very elegant solution to this problem, I am using the concatenate function from the stack tools, with the same image as the input 10 times.
> Although this works most of the time, sometimes the number of slices included in the resulting stack is too little when running the macro.  I am wondering how this inconsistency can be fixed.

The Image>Stacks>Tools>Concatenate command was not designed to create stacks of identical slices. Instead, use a batch mode loop, something like

 size = 50;
 setBatchMode(true);
 run("Boats (356K)");
 stack = getImageID()
 for (i=1; i<size; i++) {
    run("Duplicate...", "title=temp");
    run("Copy");
    selectImage(stack);
    run("Add Slice");
    run("Paste");
 }
 setSlice(1);
 run("Select None");
 setBatchMode(false);

In JavaScript and Java, use code something like

 size = 50;
 img = IJ.openImage("http://imagej.nih.gov/ij/images/boats.gif");
 ip = img.getProcessor();
 stack = new ImageStack(ip.getWidth(),ip.getHeight());
 for (i=0; i<size; i++)
    stack.addSlice(ip.duplicate());
 img.setStack(stack);
 img.show();

-wayne

> Code:
> run("Concatenate...", "  title=10x-ondersteFilled keep image1=ondersteFilled image2=ondersteFilled image3=ondersteFilled image4=ondersteFilled image5=ondersteFilled image6=ondersteFilled image7=ondersteFilled image8=ondersteFilled image9=ondersteFilled image10=ondersteFilled image11=[-- None --]");
>
>
> Thanks in advance
>
> Djoere

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Concatenate bug in macro

Djoere Gaublomme
Ok, thanks Wayne !

Quoting "Rasband, Wayne (NIH/NIMH) [E]" <[hidden email]>:

> On Feb 19, 2015, at 8:29 AM, Djoere Gaublomme  
> <[hidden email]> wrote:
>>
>> Hello,
>>
>> In a macro, I am trying to create an image stack with 10 identical  
>> slices (based on 1 non-z-stack image).
>> Since I don't know a very elegant solution to this problem, I am  
>> using the concatenate function from the stack tools, with the same  
>> image as the input 10 times.
>> Although this works most of the time, sometimes the number of  
>> slices included in the resulting stack is too little when running  
>> the macro.  I am wondering how this inconsistency can be fixed.
>
> The Image>Stacks>Tools>Concatenate command was not designed to  
> create stacks of identical slices. Instead, use a batch mode loop,  
> something like
>
>  size = 50;
>  setBatchMode(true);
>  run("Boats (356K)");
>  stack = getImageID()
>  for (i=1; i<size; i++) {
>     run("Duplicate...", "title=temp");
>     run("Copy");
>     selectImage(stack);
>     run("Add Slice");
>     run("Paste");
>  }
>  setSlice(1);
>  run("Select None");
>  setBatchMode(false);
>
> In JavaScript and Java, use code something like
>
>  size = 50;
>  img = IJ.openImage("http://imagej.nih.gov/ij/images/boats.gif");
>  ip = img.getProcessor();
>  stack = new ImageStack(ip.getWidth(),ip.getHeight());
>  for (i=0; i<size; i++)
>     stack.addSlice(ip.duplicate());
>  img.setStack(stack);
>  img.show();
>
> -wayne
>
>> Code:
>> run("Concatenate...", "  title=10x-ondersteFilled keep  
>> image1=ondersteFilled image2=ondersteFilled image3=ondersteFilled  
>> image4=ondersteFilled image5=ondersteFilled image6=ondersteFilled  
>> image7=ondersteFilled image8=ondersteFilled image9=ondersteFilled  
>> image10=ondersteFilled image11=[-- None --]");
>>
>>
>> Thanks in advance
>>
>> Djoere
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Concatenate bug in macro

Adrian Daerr-2
In reply to this post by Djoere Gaublomme
Hi Djoere,

On 02/19/2015 02:29 PM, Djoere Gaublomme wrote:
> In a macro, I am trying to create an image stack with 10 identical
> slices (based on 1 non-z-stack image).
> Since I don't know a very elegant solution to this problem,  [...]

Here's what I do in that case, in three steps:
1) reslice my image into a stack of 1 pixel high images
(Image->Stacks->Reslice..., using "start=Top" and avoiding interpolation)
2) Scale the resulting stack to a height of 10 pixels (Image->Scale...,
10 for the Y scale, Interpolation: none, create new image (scale does
not seem to work in place for stacks))
3) reslice that new stack (same parameters as in step 1) to exchange y
and z directions again

HTH,
cheers,
Adrian


Example macro recorded by performing the steps above on a sample image:

run("AuPbSn 40 (56K)");
run("Reslice [/]...", "output=1.000 start=Top avoid");
run("Scale...", "x=1.0 y=10 z=1.0 width=600 height=10 depth=412
interpolation=None average process create title=[Reslice of AuPbSn40-1]");
run("Reslice [/]...", "output=1.000 start=Top avoid");

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