Extracting stationary background

Hello everyone!

I took a course in ImageJ recently and now I have to practice with some tasks! I hope someone can give some help with one particular task:

I am trying to extract a stationary background from a stack: I have a stack of images that show an object moving across a stationary background, and I want to remove the object and just be left with the background. I am uploading an image of what I have (left) and what I want to get (right).

I think it might be very obvious and simple but please excuse the fact that I am a total beginner with the program! I have been at this task for over a week and tried as many actions as I could think of. I also asked a couple of colleagues who know the program and they couldn´t figure it out either. So hopefully someone is able to give me some ideas!

Thank you in advance to anyone who can spare some time for me!

Hi @SR357,

As this sounds like an assignment, I won’t give away too much.

Did you measure total intensity?
Did you try to subrract images?
What did you try so far? Give us some code.
If you try to perform the task manually, do Plugin>Macro>Record before you start.
This will give you all commands you tried which you can copy into a reply in this thread.

By copying this code (in ImageJ1, not FIJI), and pasting it in a Plugins>New>Macro window, you can change the order of the commands, add, skip or delete commands and after every change ‘Debug>Debug Macro’ and then Debug> Step through your code to see what happens.

Changing constants into variables (which you might have learnt during your course) and varying the contents of these variables might give other, better, results.

Using this method, I created this macro for instance, which takes the three images from your sample image on my clipboard:

run("System Clipboard");
makeRectangle(12, 11, 169, 168);run("Duplicate...", "title=[im 1]");
makeRectangle(319, 5, 169, 168);run("Duplicate...", "title=[im 2]");
makeRectangle(507, 6, 169, 168);run("Duplicate...", "title=[result im]");

but the most important command is, I think, to first run

1 Like


I would first try to do a projection of your movie. Maybe with an average, median or max projection you could get the background: Image > Stacks > Z Project…

But it might be necessary to go for more advanced stuff. This thread: http://imagej.1557.x6.nabble.com/Recovering-the-static-background-of-a-series-of-timelapse-images-td5002169.html talks about this software which extracts the mobile object and the immobile background: http://serpico.rennes.inria.fr/doku.php?id=software:hullkground:hullkground

Searching this forum might yield also other solutions.


1 Like

Hello schmiedc

Thank you very much for your reply, I managed with z project of max intensity! I had forgotten about this command so I am happy to remember about it. Now I will not forget.

Thank you again, I appreciate the help a lot.


1 Like

Hello eljonco

Thank you for your reply!! I actually managed with z project like schmiedc suggested. It was very easy. I knew it was supposed to be easy so I am disappointed that I had tried so many commands except this one. But at least now I won´t forget!
Thanks a lot for the macro suggestion, I will also have to practice that, and hopefully I will learn that too.

Thank you again!