Chris' ImageJ overlay tutorial

This write up is by Chris Ambrose of USask when he was a post doc at UBC.  It is one of the most popular search terms coming into my site.

Download the PDF here:  Ambrose 2012 - ImageJ overlays. 



IMAGE J OVERLAYS
Wednesday, January 25, 2012
3:54 PM

By Chris Ambrose, University of British Columbia


USING OVERLAYS TO DRAW THINGS ON IMAGES USING IMAGEJ

Image processing can be either destructive (i.e. the modified pixel value(s) are irreversibly changed), or non-destructive (i.e. the image will look different but the pixel values are unchanged). An example of destructive imaging using image j is drawing an object (e.g. arrow, box, etc) and hitting 'draw' (control+D). An example of non-destructive manipulation is adjusting brightness and contrast. We often need to point things out in our images and movies with arrows, boxes, and other shapes. This is best performed in imagej using overlays, which are non-destructive changes to an image.

ImageJ in particular, does a really bad job using the destructive 'draw' function:

image
This arrow I drew on here is very pixelated, and if I were to track an object using this method, I would have to redraw the arrow from scratch for each timepoint, which results in a goofy arrow that changes angles and sizes each slice.

image
In contrast, imagej is made for overlays. Overlays can use the same exact object as many times as necessary, and the object is not pixelated:
image

TO ADD OVERLAYS TO TIME SERIES IN IMAGEJ:


Open t series and convert to RGB (image>>type>>RGB color)
Open ROI manager (analyze>>tools>>roi manager). In roi manager, make sure 'show all' and 'edit mode' are checked.
image

image
Select a drawing tool of any type (ex. Arrow, line, box etc.)

image
Go to first slice you wish to label, and draw your object where you want it, then hit 't'. This adds your object to the roi manager as an roi.
image

Now move to the next t slice (you can use the '>' key)
Grab the object and move it to its next position (you can grab the object as long as it has the little dots indicating it is selected)

image
image
Again add selection to roi manager by hitting 't'

image
Now just repeat this for as many slices as you need. Here, I added a total of 5 ROIs from my arrow, each one corresponding to a specific position on a specific slice:

Now, at this point, the objects are only ROIs, not overlays. So at this point, you can use the ROI manager to edit these ROIs as you like, such as change positions (just
image
grab object, move, and hit 'update' on the ROI manager) or delete the objects ('delete' on the ROI manager). To select a given roi, just click its name in the roi manager, and it will go to the slice in the stack where that ROI is, and select it, so you can move it etc.

10.

11.

12.

13.
If you save the file at this point, these ROIs will be remembered, and can still be edited.
If you are happy with everything, you will now add your objects as overlays. To do this, just select any of your objects via the ROI manager. Then hit 'b' (or image>> overlay>>add selection), which adds the ROI as an overlay.
After adding overlays, if you save the stack, the overlays will be saved with it, so when you open it another time, they will be there.
image
These overlays are only seen by imagej, since they use imagej algorithms. For example, below I saved my example stack with the overlays, and then opened it using windows image viewer:
image
No arrows!

14.

15.
image
To get the objects permanently embedded within the image (i.e. destructive manipulation), all you do is go to the ROI manager, and select 'flatten'. If you check off 'edit mode' first, the little numbers on your objects will be hidden).

Say yes to process all, since you have a stack.

image
Now if I open with any program, the objects will be on the images:
15.

16.
image
Now if I open with any program, the objects will be on the images:

One flattened, the objects will be there in any format you save the image, which is nice, so you can do avi or mov or jpg etc files. Here, I save the stack as an avi (good for powerpoint etc):
image

THAT'S IT! THIS TOOK ME YEARS TO FIGURE OUT.

Comments