Part 2: Review and Expand on Basic Stack Techniques3
ImageJ Memory Management
Stacks are image windows that contain multiple images, or slices. You can picture the images in your computer's memory as strung one after the other in one long stream of data. Stacks containing large images, large numbers of slices, or both can occupy a lot of your computer's memory.
Not only does ImageJ have to keep track of the image data, but it maintains an invisible chunk of memory the same size as each open image called the Undo Buffer. This memory holds the image data from just before the current process so you can choose Edit > Undo and get back to where you were in the previous step. (You can only go back one step with Undo. If you need to go back any farther, the only option is to close the image without saving and re-open it, or choose File > Revert.) These are some of the reasons why it's good to have lots of memory (RAM - chips that is, not drives) in your computer.
Remember that your computer needs memory for lots of other things (like the operating system), so be realistic about your expectations. Unlike most applications you use, ImageJ doesn't just take whatever memory it needs to workit sets aside memory space when ImageJ launches. You can change this amount, up to a maximum of 1700MB (1.7GB), if available. (If you need more, install and use the 64-bit version of ImageJ.) The default memory allocated for ImageJ is usually around 400640MB, which should be plenty for most uses. Just remember that you have to TELL ImageJ to use more memoryadding more RAM alone won't make any difference!
Here are some practices that can help you make the most of ImageJ within the memory limits of your computer:
- Choose Edit > Options > Memory and Threads to open the Memory dialog box. ImageJ defaults to something like 400MB of memory. Remember that this is memory, not hard drive capacity. Most computers today ship with at least 1GB of RAM installed, but you may have an older computer. Click the appropriate option below to find out how much memory is installed in your computer:
This gives you an idea what you have to work with.
- To adjust ImageJ's memory allocation, choose Edit > Options > Memory and Threads. If necessary, increase the Maximum memory setting. The Keep multiple undo buffers option allows you to "Redo" (that is, to Undo the previous Undo command). The Run garbage collector on status bar click option helps recover memory after closing images. It's okay to turn on both of these options.
- How do you know how much memory is available for images when you're using ImageJ? When you click the status bar in ImageJ, it displays the ImageJ and Java version numbers, and the amount and percentage of ImageJ's memory allocation that is in use.
- As ImageJ closes images, the memory they occupied isn't always released back to the application. You can force a process called "Garbage Collection" that makes this unused memory available again by clicking again on the ImageJ status bar.
Here's an example:
Status bar after closing images but before garbage collection (1st click)
Status bar after garbage collection (2nd click)
- There is even a useful little memory window that you can use to keep track of images and memory. To open this window, choose Plugins > Utilities > Monitor Memory. The window shows the amount and percentage of memory in use by ImageJ on the left, the number of open image windows on the right, and a live, rolling graph of memory in use across the bottom.
You don't need to worry about memory issues most of the timeImageJ usually "just works". However, if you run into memory issues while working with stacks or big images, now you have a clue what you can do about it, or at least you'll better understand the nature of the problem. It may even save you some money by keeping you from buying more memory for your computer, as you better understand how to make ImageJ use what you do have!
Stack Tools
ImageJ was designed as a general-purpose tool, but customizable to meet the user's needs. To meet these goals, the developers built in an architecture of macros and plugins (think of these as modular mini-programs) to automate tasks and to add new features to the basic tool. That's why ImageJ has found its way into such diverse fields as astronomy and molecular biology.
You'll notice that the ImageJ toolbar contains 8 buttons to the right of the color picker tool. Some of them may even be blank. These buttons are available to the user. When ImageJ launches, it automatically loads a standard set of macro tools onto the ImageJ toolbar. There are additional macro toolsets available, and one was designed specifically for working with stacks.
- In ImageJ, click the Switch to alternate macro tool sets button - the red >> button at the right end of the ImageJ tool bar, and choose Stack Tools from the pop-up menu.
The 8 tool buttons on the right end of the tool bar are replaced with stack-related tools. These buttons provide basic controls for working with stacks. - Roll over the tools to display their functions in the status bar.
To save time, the first button, labeled Stk, provides a menu of stack functions that duplicates most of what you'll find under the Image > Stacks submenu.
Stack Basics
In Part 1, you dug deeper into digital imageswhat they are, how they are stored, and different ways to open them in ImageJ. You also examined the characteristics such as memory and storage requirements of different image types and file formats. However, your exploration was limited to windows containing single images. Part 2 will extend these concepts to windows that contain multiple images, or stacks.
At the bottom of the Stk menu button on the toolbar is a sample stack to open. (It's also listed under the sample images menu you explored in Part 1.)
- Click the Stk button on the ImageJ toolbar and choose MRI Stack (528K). Remember that a stack is a collection of multiple images in a single window. This stack shows a series of MRI (Magnetic Resonance Imaging) "slices" through a person's head.
- Use the new stack buttons on the toolbar to step forward (> Next Slice), backward (> Last Slice), return to the beginning (
- Mouse over the Animate button and find out how to change the animation speed without having to go through menus.
- Play the stack back at different speeds, including the highest and lowest speed indicated in the dialog box. As the animation is running, ImageJ will report the speed in frames per second on the status bar. Note: The speed indicator will not read accurately for frame rates lower than 1 fps. The maximum animation speed depends on the speed of your computer, so your maximum fps may vary, up to 1000 fps.
- When you're finished experimenting with speed, return the speed setting to a normal value between 10 and 30 frames per second. (FYI - Theatrical movies play at 24 fps and television and web videos play back at around 30 fps.)
- Try out the Loop Back and Forth option in the Animation Options dialog box. What does it do? When might you want to use this setting?
- How many slices are in this stack? How big, memory-wise, is each slice? Use this information to calculate the memory required for the entire stack.
- How does your calculated size compare to the actual size of the stack? (Note: the stack window is too narrow to show the memory size. Either magnify the window or drag to make the window wider until you can read the size, or you can read the size of the MRI Stack at the bottom of the Window menu.) If you did not calculate the correct size, check your math.
- What would happen to the memory requirement if you added four more slices to the stack?
- Check your result by adding four blank slices to the stack using the + button on the toolbar, then check the size of the stack and compare it to your calculation.
- Delete the four slices you added by clicking the Delete Slice button on the toolbar. Note that the memory size has returned to its original value.
- Click the First Slice button to go to the beginning of the stack. Now add one slice. Where is the slice addedafter the first slice or before it?
- Delete the blank slice you added.
- Still on the first slice of the stack, Option-click (Mac) or Alt-click (PC) the Add Slice + button. Where is the slice added now?