Introduccion a ImageJ

19
 1  . Introduction to ImageJ 8 Sept 2009 Jacqui Ross General Comments: 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. The predecessor to ImageJ, NIH Image was originally only available for Macs but later the PC version Scion Image was developed. 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://rsb.info.nih.gov/ij/index.html  You can download the program from http://rsb.info.nih.gov/ij/download.html . This seminar will introduce you to some of ImageJ’s features and some basic concepts. Portions of the handout have been lifted from the manual and other materials which can be found on the ImageJ homepage. Associate Professor Alistair Young, the Director of the BIRU, has also kindly provided material, some of which is currently used in our Advanced Biomedical Imaging course (MEDSCI 703) There is a mailing list that you can subscribe to at: http://rsb.info.nih.gov/ij/list.html . You can arrange to get a “digest” sent to you each day if you don’t want each message coming through independently. 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 some documentation available here:  http://rsb.info.nih.gov/ij/docs/index.html and there is also a Documentation WIKI being developed at: http://imagejdocu.tudor.lu/  Plugins Plugins are additional software module s or code which provide the ability to perform specific tasks. There is a plugins collection available at: http://rsb.info.nih .gov/ij/plugin s/collection.html  Many more are available on the website and from other users. There is a list of available plugins here: http://rsb.info.nih .gov/ij/plugin s/index.html  Some people have developed their own collections of plugins and bundled them together. For example, Tony Collins from the McMaster Biophotonics Institute, (previously at WCIF), has a great collection for microscopy: http://rsb.info.nih.gov/ij/plugin s/mbf-collection.h tml He also provides excellent information about the plugins on his Biomedical Imaging Research Unit School of Medical Sciences Faculty of Medical and Health Sciences The University of Auckland Private Bag 92019 Auckland, NZ Ph: 373 7599 ext. 87438 http://www.auckland.ac.nz/biru/  [email protected]  

Transcript of Introduccion a ImageJ

Page 1: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 1/19

  1

  . 

Introduction to ImageJ 8 Sept 2009

Jacqui Ross

General Comments:

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. The predecessor to ImageJ, NIH Image was originally only available for Macs but later the PC

version Scion Image was developed. 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://rsb.info.nih.gov/ij/index.html 

You can download the program from http://rsb.info.nih.gov/ij/download.html.

This seminar will introduce you to some of ImageJ’s features and some basic concepts. Portions of the handout

have been lifted from the manual and other materials which can be found on the ImageJ homepage. Associate

Professor Alistair Young, the Director of the BIRU, has also kindly provided material, some of which is currently

used in our Advanced Biomedical Imaging course (MEDSCI 703)

There is a mailing list that you can subscribe to at: http://rsb.info.nih.gov/ij/list.html. You can arrange to get a

“digest” sent to you each day if you don’t want each message coming through independently. 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 some documentation available here: http://rsb.info.nih.gov/ij/docs/index.htmland there is also a

Documentation WIKI being developed at: http://imagejdocu.tudor.lu/ 

Plugins

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

There is a plugins collection available at: http://rsb.info.nih.gov/ij/plugins/collection.html 

Many more are available on the website and from other users. There is a list of available plugins here:

http://rsb.info.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 Institute, (previously at WCIF), has a great collection for microscopy:

http://rsb.info.nih.gov/ij/plugins/mbf-collection.html He also provides excellent information about the plugins on his

Biomedical Imaging Research UnitSchool of Medical Sciences

Faculty of Medical and Health SciencesThe University of Auckland 

Private Bag 92019Auckland, NZ 

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

 [email protected] 

Page 2: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 2/19

  2

website: http://www.macbiophotonics.ca/imagej/ As new updates are released, some of the most useful plugins

are incorporated into the core program.

Macros

In addition to plugins, it is also possible to write macros using the ImageJ macro language. This 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.

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. 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. There are also lots of individual pluginsavailable for opening files from particular imaging systems (e.g. Zeiss .zvi).

The most useful plugin for importing/opening files is the Bioformats plugin, which is available here:

http://www.loci.wisc.edu/ome/formats.html. It will allow you to open a large variety of different file formats.

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:

Page 3: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 3/19

  3

 

• Grayscale and RGB pixel values and X, Y pixel coordinates

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 4: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 4/19

  4

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:

Selections or Regions of Interest (ROI): Drawing tools

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, 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, analysed, etc. using other menu commands.

Page 5: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 5/19

  5

 

 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 hasbeen 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.

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.

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.

Page 6: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 6/19

  6

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.  

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).

 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.

Page 7: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 7/19

Page 8: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 8/19

  8

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. 

Histogram

 Analyze – histogram: displays the image histogram (frequency), and shows maximum and minimum grayscale

values. The log scale shows more minor components.

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”)

Page 9: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 9/19

  9

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 10: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 10/19

  10

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 11: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 11/19

  11

 

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 12: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 12/19

  12

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, theimage 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 (also called

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

Colour balance). 

Page 13: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 13/19

  13

Threshold : for thresholding images for segmentation and analysis purposes. This will be covered in the follow-up

seminar.

Size: changes the image size.

Canvas size: extends the area around the image.

Analyze – Tools – Color 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 14: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 14/19

  14

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 15: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 15/19

  15

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 16: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 16/19

  16

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 17: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 17/19

  17

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 18: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 18/19

  18

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.

Filters are not limited to rectangular selections. The entire image is filtered if no selection is active. They work best

on greyscale images. (Remember that if you have an RGB image, you can split the channels, apply the filters you

want, and then merge again).

Most of these filters in ImageJ (with the notable exception of Rank Filters such as maximum, minimum, etc), areimplemented 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.

I have included some details on how the 3x3 tables differ for two of the filters.

The 3 x 3 tables shown below are the coefficients (weighting factors) for the filters. The popularity of plus and

minus one in these tables is due to the fact that multiplication by one is very efficient, i.e., it is unnecessary.

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.

Page 19: Introduccion a ImageJ

8/6/2019 Introduccion a ImageJ

http://slidepdf.com/reader/full/introduccion-a-imagej 19/19

19

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.

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

measurements you want. This will be covered in more detail in the follow-up seminar.

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. ImageJ will also open stacks created in MetaMorph (stk files).

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.

Stacks - Movies

Time stamper : allows you to add the time information onto your movie.

Zoomify : allows you to make a movie where you zoom in on a particular region.