Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy...

22
1 Introduction to ImageJ for Anatomy Surgical Options Students 03 May 2012 Jacqueline Ross INTRODUCTION ImageJ is a public domain image processing program. It was written by Wayne Rasband at the Research Services Branch (RSB) of the National Institute of Mental Health (NIMH) which is part of the National Institutes of Health in Maryland, USA. ImageJ is based on Java/javascript (Sun Microsystems) and will run on any platform. ImageJ has become a standard tool in many laboratories around the world because it is free, open source, and very well supported. The website address is: http://imagej.nih.gov/ij/ There is a mailing list that you can subscribe to at: http://imagej.nih.gov/ij/list.html. I recommend this if you are using the program a lot but otherwise it’s not necessary since you can still search the archives without being a subscriber. There is a very good User Guide to ImageJ available here: http://imagej.nih.gov/ij/docs/index.html as well as other information. There is also a Documentation WIKI at: http://imagejdocu.tudor.lu/ PLUGINS Plugins are additional software modules or code, which provide the ability to perform specific tasks. There is a list of available plugins here: http://imagej.nih.gov/ij/plugins/index.html Some people have developed their own collections of plugins and bundled them together. For example, Tony Collins from the McMaster Biophotonics Facility (MBF), has a great collection for microscopy: http://imagej.nih.gov/ij/plugins/mbf-collection.html He also provides excellent information about the plugins on his website: http://www.macbiophotonics.ca/imagej/ FIJI The acronym Fiji stands for “Fiji Is Just ImageJ”. This is just a version of ImageJ with a specific compilation of useful Plugins included. For example there are good Plugins available for stitching and colocalization. There is good documentation available. Website: http://pacific.mpi-bg.de/wiki/index.php/Fiji Biomedical Imaging Research Unit School of Medical Sciences Faculty of Medical and Health Sciences The University of Auckland Private Bag 92019 Auckland 1142, NZ Ph: 373 7599 ext. 87438 http://www.fmhs.auckland.ac.nz/sms/biru/ [email protected]

Transcript of Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy...

Page 1: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

1

.

Introduction to ImageJ for Anatomy Surgical Options Students 03 May 2012

Jacqueline Ross INTRODUCTION ImageJ is a public domain image processing program. It was written by Wayne Rasband at the

Research Services Branch (RSB) of the National Institute of Mental Health (NIMH) which is part of the

National Institutes of Health in Maryland, USA. ImageJ is based on Java/javascript (Sun Microsystems)

and will run on any platform. ImageJ has become a standard tool in many laboratories around the world

because it is free, open source, and very well supported. The website address is: http://imagej.nih.gov/ij/

There is a mailing list that you can subscribe to at: http://imagej.nih.gov/ij/list.html. I recommend this if

you are using the program a lot but otherwise it’s not necessary since you can still search the archives

without being a subscriber.

There is a very good User Guide to ImageJ available here: http://imagej.nih.gov/ij/docs/index.html as

well as other information. There is also a Documentation WIKI at: http://imagejdocu.tudor.lu/

PLUGINS Plugins are additional software modules or code, which provide the ability to perform specific tasks.

There is a list of available plugins here: http://imagej.nih.gov/ij/plugins/index.html

Some people have developed their own collections of plugins and bundled them together. For example,

Tony Collins from the McMaster Biophotonics Facility (MBF), has a great collection for microscopy:

http://imagej.nih.gov/ij/plugins/mbf-collection.html He also provides excellent information about the

plugins on his website: http://www.macbiophotonics.ca/imagej/

FIJI The acronym Fiji stands for “Fiji Is Just ImageJ”.

This is just a version of ImageJ with a specific compilation of useful Plugins included. For example there are good Plugins available for stitching and colocalization. There is good documentation available.

Website: http://pacific.mpi-bg.de/wiki/index.php/Fiji

Biomedical Imaging Research Unit School of Medical Sciences

Faculty of Medical and Health Sciences The University of Auckland

Private Bag 92019 Auckland 1142, NZ

Ph: 373 7599 ext. 87438 http://www.fmhs.auckland.ac.nz/sms/biru/

[email protected]

Page 2: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

2

MACROS In addition to Plugins, it is also possible to write macros using the ImageJ macro language. A macro

allows you to string a series of commands together to perform operations that you may want to do

repeatedly. These can also be converted to Plugins by adding an underscore to the name and putting

the file in the Plugins folder. There is a macro recorder built into ImageJ that allows you to record each

step in a process and then create the macro. There is also a built-in batch processing function that can

be used to apply macros to entire folders of images. Some instructions for writing macros are available

on the BIRU website.

MEMORY You can change the memory allocation (RAM) if necessary by going to Edit-Options-Memory. Make

sure that you don’t exceed the capability of your computer. You shouldn’t go beyond 75% of your RAM

capacity.

OPENING FILES File-Open: opens TIFF (uncompressed), GIF, JPEG, DICOM, BMP, STK, video and FITS images. It

also opens lookup tables (LUT), text files, regions of interest (ROIs), etc.

File/Import: provides access to plugins for reading RAW files, images in ASCII format, and for loading

images over the network using a URL. To import a raw (one byte or 8 bits per pixel) file, you must know

the image size (eg. 480x640 pixels) and the offset to the image data.

Files can be opened in groups by selecting them and dragging and dropping them on the ImageJ icon or

onto the toolbar. You can also open files from a series (x-y, lambda, z) by using File-Import-Image

Sequence. The files should be named in numerical order. ImageJ will then create a stack for you of the

data.

Bioformats plugin - LOCI • Useful for opening files from different sources and formats. Can also export into some formats.

• Images bring in information such as channel information and calibration

• “Converts proprietary microscopy data into an open standard called the OME data model” = Open Microscopy Environment

• http://www.loci.wisc.edu/software/bio-formats

Page 3: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

3

File/Revert: allows you to revert to the last saved version of the image.

File Save: files can be saved in TIFF, GIF, JPEG, AVI, etc. , tab-delimited text, and raw formats.

STATUS BAR Gives information such as memory usage:

Grayscale and RGB pixel values and X, Y pixel coordinates as well as resolution

Page 4: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

4

IMAGE PROPERTIES

Pixels and Grayscale: Digital images are made up of "pixels" (short for picture elements). Each pixel is

a spot with a given intensity or greyscale value which is an integer, e.g. in the range 0 (black) to 255

(white) if it is 8 bit, 0-4095 (12bit), etc.

Bit depth: Generally 8, 12 or 16bits per pixel.

Image-Show Info: displays a list of known information about the image.

Image-Type: allows you to change the image mode. Some operations are designed to work with 8 bit

grayscale or 8bit colour so if you have an RGB image, you may need to change it to 8 bit colour or

grayscale. An alternative is to split the image into its component channels. RGB stands for Red, Blue

and Green- each of these intensities can be an integer between 0 and 255.

Image – Color: allows you to merge images, change colours, etc.

Page 5: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

5

LOOKUP TABLES (LUT)

Images are displayed using a lookup table. This assigns a color to be used for each of 256 possible

displayed pixel values (for 8bit images). These LUTs are used a lot for fluorescence images.

Analyze-Show LUT: displays the current lookup table of the active image.

Image-Lookup Tables: allows selection of a range of color palettes.

Invert LUT: inverts the pixel values.

LUTs are also useful for checking whether you have even or uneven illumination.

SPATIAL CALIBRATION

Analyze/Set Scale allows you to calibrate the image so that your results are in units such as microns

rather than pixels. You know the pixel values from the Show Info window and you should know the

aspect ratio and size of the field of view. If you click Global, ImageJ will apply this calibration to all open

images.

If you have a calibration bar on an image, you can use the line tool to draw along it and then go to

Analyze – Set Scale and type in the micron value. Or you can take an image of a micrometer slide with

the same objective lens and magnification and use that to calibrate your images.

Page 6: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

6

TOOLS There are a number of drawing tools on the LHS of the toolbar. Red triangles (as indicated by the arrows

below) indicate more tools/options which are available either by right or left hand mouse click or double-

clicking.

Page 7: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

7

On the RHS, where the >> is located, there are a number of other tool sets available which can be

selected. These install macros which change the tools visible on the RHS of the toolbar as shown below:

SELECTION TOOLS FOR CREATING REGIONS OF INTEREST (ROI) Most commands in ImageJ will work on a region of the image which you need to select or segment in

some way. You can select the whole image by going to Edit-Selection-Select All.

You can define a specific region of interest (ROI) within the image, using any one of the region selection

tools in the Menu toolbar (rectangular, oval, polygonal and freehand). To remove a selection, just click

the mouse outside the ROI.

Rectangle: when using the rectangle tool, you can resize by dragging the corners. Hold down the Shift

key to constrain the selection to be square.

Polygon: when using the polygon tool, click once for each vertex, then double click to close the

selection.

Edit – Selection - Specify allows you to specify the size, shape and location of the ROI.

All Selections: use the arrow keys to “nudge” selections one pixel at a time. Use the arrow keys with the

alt key held down to change the width or height one pixel at a time. As a selection is created or resized,

Page 8: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

8

its location, width and height are displayed in the status bar. Selections can also be moved around the

image by dragging.

Selections can be copied, pasted, cropped, analyzed, etc. using other menu commands. They can also

be created from binary images (e.g. after thresholding/segmentation) by going to Edit – Selection –

Create Selection.

Analyze-Tools-ROI Manager allows you to have multiple ROIs active. It will also allow you to move

them, save them and measure them.

OTHER TOOLS Lines: Allows you to draw straight, segmented or freehand lines. Double-click on the tool to change the

line width. Go to Edit-Draw to make the line permanent or Ctr-D.

Arrow: You can create arrows by using the arrow tool. Double-click on it to change the properties.

Grid: You can also apply a “grid” to use with this tool by downloading the grid plugin

(http://rsb.info.nih.gov/ij/plugins/grid.html )and installing it. You can specify the size of the grid and it can

be shown as lines, crosses or points.

Magic Wand: Allows you to trace the outline of an object by looking for the edges. It works best if the

object has been thresholded and made binary (black/white) for maximum contrast. You can select

multiple objects such as cells by holding the shift key down as you go. The tolerance can be set to

include a greater range of grayscale. The selections can be added to the ROI Manager.

Text: Double-click on the tool to change the options. If the image is grayscale, then text can only be

black or white. If you want coloured text, you need to change the image to colour. The colour of the text

will be whatever has been specified as foreground colour. Move it to where you want the text to appear

and then go to Edit-Draw (Ctrl-D).

Eyedropper: Allows you to choose the background and foreground colours by double-clicking on the

eyedropper and choosing colours from the Colour Picker. Click on the tiny arrow to swap the foreground

and background colours. The colour of the eyedropper then shows the foreground colour while the box

around it shows the background colour.

Magnifying glass: Use the Left mouse button to zoom in (magnify) and the right mouse button to zoom

out (reduce). Next to the name in the title bar of the image, you will see the % of the image currently

displayed.

Page 9: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

9

Hand: useful when viewing a magnified image or an image that is larger than the screen will allow to

display. Click on the image and hold the mouse button down whilst dragging the mouse. The image will

pan with the mouse.

COLOURS Edit-Options-Colors: Allows you to set colours for background, foreground & selections.

SCALE BARS 1. Go to Analyze-Tools-Scale Bar.

2. Choose the size, position, colour, etc. of the scale bar you want.

3. Choose the location.

4. You can choose to hide the text if you just want a bar.

5. If you want to draw the size of the bar you want or specify a different location on the image to

the options listed, then use the line tool to draw a selection. Choose At Selection for the

location. The bar will be drawn at that location and will be the same length as the selection.

EDIT Cut & Paste: works similarly to most other programs. You can make a ROI, copy it, move the selection

around to where you want to paste it to, then click Edit-Paste. You can still move the selection box

together with the pasted pixels around the image using the mouse and position it where you want it.

When you are happy with the position, just click outside the selection to make it permanent. It is not in a

layer anymore.

Undo: only goes back one step. Sometimes, you have to use File-Revert instead.

Clear Inside/Clear Outside: Clears the area inside/outside an ROI, e.g. if it’s an area you don’t want to

analyse or process.

Crop: You can crop by drawing a selection and then going to Image-Crop. It will always crop out a

rectangle/square. You can’t crop out a circle, it will just crop a rectangle of the size that contains the

circle boundary.

Page 10: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

10

ENHANCING IMAGES Image Adjust-

Contrast and brightness: use to enhance images by dynamically changing the lookup table mapping.

Click on the brightness slider and drag from side to side. You can also adjust the contrast setting

independently.

Brightness adds or subtracts a constant to each pixel – shift in histogram along x axis but doesn’t

change the distribution. Contrast – lower level set (e.g. to 0) and higher level set (e.g. to 255) and rest of

pixel values adjusted proportionately.

Window Level: adjustment of intensity levels (also known as “histogram stretch”)

The examples below illustrate how these procedures alter pixel values.

The image below is 8bit grayscale. The histogram to the RHS shows the pixel value distribution and

some statistics including Maximum and Minimum values for pixels in the image. You can generate a list

of the values by clicking on List. The list can be saved and opened in Excel.

Shown below is the default window for Brightness & Contrast (B&C). The histogram is shown in the

window with a scale from 0-255 (8bit).

Page 11: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

11

Now we apply changes to the LUT by moving the Brightness slider. As brightness is increased, the

maximum value decreases and the line moves up. To implement the changes on the image, you need to

click on Apply. Until then, only the display of the image is changed, the pixel values are still the same.

Following the application of the changes, we can see that the histogram has changed. Maximum and

minimum values have changed along with other data.

Page 12: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

12

After moving the Contrast slider and applying those changes, we can see the altered histogram as

below. This time the histogram has been stretched between 0 and 255. We now have some values out

of detection range (see minimum and maximum values).

Page 13: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

13

Page 14: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

14

Window/Level (W&L) also changes pixel values. Shown below is the W&L window. Note the position of

the histogram in the W&L window.

Now that changes to the LUT have been applied, you can see that the histogram has moved over to the

RHS, the image is not as black in appearance and the minimum and maximum values are closer

together. In this case, the result is less contrast and apparently higher background in the image.

Color balance: allows you to change the colour balance. An additional plugin from the MBF bundle

(called Colour balance) allows you to draw a ROI in a white area and then white balance the image

(Plugins – Colour – Colour balance).

Page 15: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

15

Threshold: for thresholding images for segmentation and analysis purposes.

Size: changes the image size.

Canvas size: extends the area around the image.

ANALYZE – TOOLS – RGB HISTOGRAM A useful tool to analyse the RGB values in order to adjust colour balance correctly. Or you can look at

the values in the status bar.

BACKGROUND REMOVAL

Process-Subtract Background: (rolling ball) tries to remove anything on a scale larger than the set

radius (good for removing continuously varying smooth backgrounds from gels and other images). You

can also generate a background image from your image to remove uneven background using

Calculator Plus. Change the rolling ball radius until no detail is visible.

Process-Image-Calculator: allows you to do mathematical operations using 2 images.

Calculator Plus: http://rsb.info.nih.gov/ij/plugins/calculator-plus.html

Enables you to subtract a background image from an image to remove uneven background or

shadowing. Works for RGB images as well as grayscale. It is best to have a background image that you

have acquired at the same time as the image of interest.

Page 16: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

16

The example below shows a background image being created for this image using the rolling ball so that

I can demonstrate the Calculator Plus plugin.

Original image Has shadows in the corners due

to the microscope not being set

up correctly

Original image with LUT applied Original image converted to 8bit

grayscale and a LUT (16_colors)

applied to emphasise the uneven

illumination. This is a useful

application of the LUTs to check

illumination issues.

Page 17: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

17

The background image is created by going to Process – Subtract Background as below:

You can rename the background image if you want to.

Click on Preview to see

the background image.

This is also a useful way

to see what radius you

need for using the rolling

ball. Once no detail is

visible, click OK. To apply

the rolling ball directly, just

turn off the Create

Background option.

Original image

Background image

Page 18: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

18

The background image is then used to correct the background as shown below, i.e. dividing the original

image by the background image and then multiplying by 255.

Resulting image

Page 19: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

19

Original and processed image as below:

Note: You do need to take care that you don’t lose detail through the correction process resulting in an

image that looks too “bleached” of colour.

Original image with LUT applied Original image converted to 8bit

grayscale and a LUT (16_colors)

applied. Note shading in corners.

Image after background subtraction with LUT applied Result image converted to 8bit

grayscale and a LUT (16_colors)

applied. Note the uneven shading in the

corners, shown on the original image

below, has disappeared.

Page 20: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

20

PROCESS MENU

The Process menu contains image processing filters and other operators used for enhancing images or

segmenting features for image analysis.

Filters Filters represent group processing rather than individual pixel operations. There are many things you can

do to change (e.g. improve) the look of the image or make analysis/thresholding easier, eg. sharpen

edges, reduce noise, subtract background, etc.

Most filters in ImageJ (with the notable exception of Rank Filters such as maximum, minimum, etc), are

implemented using 3 x 3 spatial convolutions. In this procedure, the value of each pixel in the selection is

replaced with the weighted average of its 3 x 3 neighbourhood.

Smooth - Blurs (softens) the selected area. It can be used to reduce noise in an image or to

even out the greyscale in the area.

1 1 1

1 1 1

1 1 1

Sharpen - Increases contrast and accentuates detail in the selection, but may also

accentuate noise.

-1 -1 -1

-1 12 -1

-1 -1 -1

Rank filters rank (sort) the nine pixels in each 3 x 3 neighborhood and replace the pixel with the median,

minimum (lightest), or maximum (darkest) value. Use the Median filter to reduce noise. This removes

high values for the target/central pixel which might be due to electronic noise. A lower value is inserted.

This is repeated on the next pixel, etc. until the whole image is treated. It gets rid of noise without

causing significant blurring of the image.

Despeckle is also a median filter. It replaces each pixel with the median value in its 3 x 3 neighborhood.

Median filters are good at removing salt and pepper noise.

The Minimum filter erodes (shrinks) objects in grayscale images similar to the way binary erosion

shrinks objects in binary images. The Maximum filter dilates (expands) objects in grayscale images

similar to the way binary dilation expands objects in binary images.

Page 21: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

21

Unsharp Mask: sharpens up the image, good if you need extra contrast, often better than Sharpen.

ANALYZE MENU

This menu has all the analysis functions including the Set Measurements window, where you select

what parameters you want to measure. It also has the Analyze Particles option.

Please refer to the second document, Image Analysis Basics for more information on image analysis.

IMAGE - STACKS

Allows you to work with stacks, (e.g. z series or time series data). You need to have a series (time, z, x-

y) of images which can be built into a stack. If you open the images as a numbered sequence, then they

will automatically be put into a stack in the correct order

Convert Images to Stack: converts a set of 2D images that you have already opened into a stack.

Animate: animates the images in a stack at a rate up to 100 frames per second.

Convert Stack to Images: splits the stack into individual images.

Next Slice/Previous Slice: browsing images can be done using the > and < keys. The number of the

current slice and the total number of slices are displayed in the title bar. You can also use the slider bar

in the stack window.

Make Montage: allows you to make a montage out of your stack images.

Z Project: simple projection algorithms designed to render 3D images into 2D projections, allows volume

rendering, useful for visualizing the internal structures of 3D images.

3D Project: Allows you to project the stack and then rotate it.

Orthogonal view: provides an orthogonal (or section) view.

• Can also be used with built-in batch processor

Page 22: Introduction to ImageJ for Anatomy Surgical Options Students · Introduction to ImageJ for Anatomy Surgical Options Students ... it is also possible to write macros using the ImageJ

22

SPECIALISED PLUGINS FOR COLOUR ANALYSIS Instructions (PDF) available on BIRU website: Colour analysis in ImageJ:

http://www.fmhs.auckland.ac.nz/sms/biru/facilities/analysis_resources.aspx

Threshold Colour

• Author – Gabriel Landini

• http://www.dentistry.bham.ac.uk/landinig/software/software.html

• For segmenting images where splitting the images into their component channels of red, green

and blue does not segment the objects of interest. Good for histology images.

Colour Deconvolution

• Author – Gabriel Landini

• For segmentation of colour images, e.g. histology stains or combinations like DAB/Haematoxylin

• http://www.dentistry.bham.ac.uk/landinig/software/cdeconv/cdeconv.html

REFERENCES

• Rasband ,WS. 1997–2006. ImageJ. U.S. National Institutes of Health: Bethesda, MD. Available

at http://rsb.info.nih.gov/ij/.

• Ferreira, T. & Rasband, W., The ImageJ User Guide — Version 1.44,

http://imagej.nih.gov/ij/docs/user-guide.pdf , January 2011.

• Collins TJ. ImageJ for microscopy. Biotechniques. Jul 2007;43(1):25-+.

• BIRU website: http://www.fmhs.auckland.ac.nz/sms/biru/facilities/analysis_resources.aspx

• Google ImageJ!