Quantcast

moving average in stack

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

moving average in stack

Da NN
Hi,

Does anyone know how to do moving average in the z direction of a stack? Now
the moving average filter is for the x-y plane. I want to do a moving
average for each pixle in the z direction. Can anyone tell me how to do that
with ImageJ? Thanks.

Da

_________________________________________________________________
Need a brain boost? Recharge with a stimulating game. Play now! 
http://club.live.com/home.aspx?icid=club_hotmailtextlink1
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: moving average in stack

Michael Cammer
some modification of the two macros should do what you want.


//-----------------------------------------------
macro "paste with blend adjacent slices"{
   checkCurrentVersion();
   original = getImageID();
   selectImage(original);
   for (i=2;i<=nSlices;i++) {
     run("Set Slice...", "slice="+i);  run("Select All");  run("Copy");
     run("Set Slice...", "slice="+(i-1));  setPasteMode("Average");
run("Paste");
   }
   selectImage(original);
   run("Set Slice...", "slice="+nSlices); run("Delete Slice");
   run("Set Slice...", "slice="+1);  run("Delete Slice");
   run("Brightness/Contrast...");
}



//------------------------------------------------------------------
macro 'Projections of variable width'{
   checkCurrentVersion();
   original = getImageID();
   end = nSlices();
   zdepth = 4;
   projtype = "'Max Intensity'" ;    // or 'Average Intensity' or
some other type
   for (i=1;i<(end-zdepth);i++){
     stop = i + zdepth;
     run("Z Project...", "start="+i+" stop="+stop+" projection="+projtype);
     run("Select All");
     run("Copy");
     run("Close");
     selectImage(original);
     run("Set Slice...", "slice="+i);
     run("Paste");
   }








At 12:20 PM 07/11/07, you wrote:

>Hi,
>
>Does anyone know how to do moving average in the z direction of a
>stack? Now the moving average filter is for the x-y plane. I want to
>do a moving average for each pixle in the z direction. Can anyone
>tell me how to do that with ImageJ? Thanks.
>
>Da
>
>_________________________________________________________________
>Need a brain boost? Recharge with a stimulating game. Play
>now!  http://club.live.com/home.aspx?icid=club_hotmailtextlink1

____________________________________________________________________________
Michael Cammer   Analytical Imaging Facility   Albert Einstein Coll. of Med.
URL:  http://www.aecom.yu.edu/aif/ 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: moving average in stack

Gabriel Landini
On Wednesday 11 July 2007 20:12:00 Michael Cammer wrote:
> some modification of the two macros should do what you want.

I wonder if this would also work? (haven't tried it):

Reslice the stack starting at top
Convolve with a kernel
0 1 0
0 1 0
0 1 0
Reslice the stack back

cheers,

G.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: moving average in stack

Arne Seitz-2
In reply to this post by Da NN
Hi,

Follow the link and you can find a Plugin called Walking_Average_.class.
This should do what you are looking for.

http://www.embl.de/eamnet/html/kymograph.html

Cheers Arne

____________________________________________________
 
Arne Seitz, Scientific Officer
Advanced Light Microscopy Facility
EMBL Heidelberg
 
+49 6221 387 8467
-----Ursprüngliche Nachricht-----
Von: ImageJ Interest Group [mailto:[hidden email]] Im Auftrag von Da NN
Gesendet: Mittwoch, 11. Juli 2007 18:21
An: [hidden email]
Betreff: moving average in stack

Hi,

Does anyone know how to do moving average in the z direction of a stack? Now

the moving average filter is for the x-y plane. I want to do a moving
average for each pixle in the z direction. Can anyone tell me how to do that

with ImageJ? Thanks.

Da

_________________________________________________________________
Need a brain boost? Recharge with a stimulating game. Play now! 
http://club.live.com/home.aspx?icid=club_hotmailtextlink1
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: moving average in stack

Wayne Rasband
In reply to this post by Gabriel Landini
> I wonder if this would also work? (haven't tried it):
>
> Reslice the stack starting at top
> Convolve with a kernel
> 0 1 0
> 0 1 0
> 0 1 0
> Reslice the stack back

This does appear to work. Here is a macro that does 3, 5 or 7 slice
moving averages in the z direction of a stack.

-wayne

   k3 = "[0 1 0 0 1 0 0 1 0]";
   k5 = "[0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0]";
   k7a = "[0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1";
   k7b = " 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0]";
   k7 = k7a + k7b;
   Dialog.create("Running Average");
   Dialog.addChoice("Slices to Average:", newArray("3", "5", "7"));
   Dialog.addCheckbox("Keep Source Stack", true);
   Dialog.show;
   n = Dialog.getChoice;
   keep = Dialog.getCheckbox;
   kernel = k3;
   if (n=="5")
       kernel = k5;
   else if (n=="7")
       kernel = k7;
   if (nSlices==1)
       exit("Stack required");
   id1 = getImageID;
   // re-slicing may not work if stack is scaled
   setVoxelSize(1, 1, 1, "pixel");
   getMinAndMax(min, max);
   run("Reslice [/]...", "input=1 output=1 start=Top");
   id2 = getImageID;
   if (!keep) {selectImage(id1); close;}
   selectImage(id2);
   run("Convolve...", "text1="+kernel+" normalize stack");
   run("Reslice [/]...", "input=1 output=1 start=Top");
   setMinAndMax(min, max);
   selectImage(id2);
   close;
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: moving average in stack

Gabriel Landini
On Thursday 12 July 2007 21:52:39 Wayne Rasband wrote:
>
> This does appear to work. Here is a macro that does 3, 5 or 7 slice
> moving averages in the z direction of a stack.

Great. I just noticed: assuming that the running average is over n (odd)
slices, the first (n-1)/2 and the last (n-1)/2 slices of the resulting stack
should perhaps be discarded (i.e. deleted from the stack) as the convolving
filter would not average outside the image. (So in the result stack, the
first slice is the average of the 1st, 2nd and 3rd original slices and so
on).

Regards,

Gabriel
Loading...