ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May...

25
1 ImageJ: Introduction to Image Analysis 3 May 2012 Jacqui Ross Image analysis questions 1. What do you want to measure in order to get meaningful data? Area Number of particles (e.g. cells) Intensity Size/distribution of particles Colour Particle shape Orientation Colocalisation Distance, velocity, etc. 2. Do you need to work in colour or grayscale? RGB split channels Colour thresholding Convert to 8bit grayscale Colour deconvolution 3. Do you want to measure the whole image or specific regions? Do you need to select the regions using one image and apply it to another? Regions of Interest (ROI) and ROI Manager 4. Do you need to use processing filters to facilitate segmentation? Background subtraction Median filter Edge detection Unsharp Mask/Sharpen Enhance contrast 5. Do you need to fill holes or separate joining particles? Fill holes/Erosion/Dilation/Open/Close Watershed 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 ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May...

Page 1: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

1

.

ImageJ: Introduction to Image Analysis 3 May 2012 Jacqui Ross Image analysis questions 1. What do you want to measure in order to get meaningful data?

• Area • Number of particles (e.g. cells)

• Intensity • Size/distribution of particles

• Colour • Particle shape

• Orientation • Colocalisation

• Distance, velocity, etc.

2. Do you need to work in colour or grayscale?

• RGB split channels • Colour thresholding

• Convert to 8bit grayscale • Colour deconvolution

3. Do you want to measure the whole image or specific regions? Do you need to select

the regions using one image and apply it to another?

• Regions of Interest (ROI) and ROI Manager

4. Do you need to use processing filters to facilitate segmentation?

• Background subtraction • Median filter

• Edge detection • Unsharp Mask/Sharpen

• Enhance contrast

5. Do you need to fill holes or separate joining particles?

• Fill holes/Erosion/Dilation/Open/Close

• Watershed

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: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

2

AREA MEASUREMENTS Manual approach: measure the area of structures by drawing a region of interest (ROI)

around them with one of the drawing tools, e.g. freehand, ellipse, rectangle tool. 1. Open the image. Draw the ROI.

2. Go to Analyze-ROI Manager. 3. Then go to Analyze-Set Measurements to select the parameters that you want to

measure.

4. Click on Measure in the ROI Manager window. Results will appear in a Results window.

These results can be saved and are .xls files, i.e. can be opened in Excel. If you go to

Analyze – Measure instead of using the ROI Manager, then you will get results for the

entire image, not just the ROI.

5. You can draw multiple ROIs and add them to the ROI Manager. You can move the ROIs

and update them, rename them, etc. You can also save the set of ROIs. This is a really

good idea as a record of what you have measured. That allows you to reload them or use

them on another image. You can also draw the ROIs onto the image and save it as a

record.

Note: measuring lines or angles manually works the same way except that you select one of the

line tools or the angle tool.

Threshold approach: use thresholding followed by binarising to segment the stained area which you wish to measure (for area measurements where you are not interested in intensity). 1. Open the image. Change to grayscale (Image – Type – 8bit) or go to Image – Color -

RGB Split. 2. Go to Image – Adjust – Threshold. You can select the Auto setting or alternatively move

the sliders yourself until you have all the stained areas selected. You should select dark background if you have a fluorescence/confocal image. The threshold defines the objects

that you want to measure (red overlay).

Note that if the Auto setting works well for you, you could omit this step and go straight to

Process – Binary – Make Binary).

Page 3: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

3

3. Click Apply to make the image binary if you are not interested in intensity values. The

areas overlaid with red will be changed to black. You should not change the defaults

unless you want to measure the unstained areas. ImageJ regards the black areas as the

areas/objects of interest.

4. Go to Analyze – Set Measurements. Choose the parameters you want to measure. If you

are interested in the proportion of area labelled, you may want to select Area Fraction in

addition to Area. Make sure that you include Display Label.

Page 4: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

4

5. Go to Analyze – Measure. The Results table will come up and you can then save this.

You can also save the binary image if you want to.

Page 5: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

5

MEASUREMENT OF NUMBER OF PARTICLES/OBJECTS Manual approach: measure the number of objects by using the Point Selection tool. Necessary if you are unable to threshold your images or if you need to count cells but the cells

are overlapping and will be measured as one object.

1. Click on the Point Selection tool.

2. If you have an RGB image, you can choose the colour that you want to use for the

selections by going to Edit – Options - Colors – Selection. Make sure you choose a

colour that stands out on your image.

3. You should also make the Foreground colour the same as your selection colour. This is

because once you have made the selection and clicked on another object, the selection

point will be filled with the foreground colour.

4. If you have a grayscale image, you will see the colour in gray so you should choose

white/black as your selection and drawing colour. Alternatively, you could change the

image to RGB colour so that the mark is in colour. If you want to measure intensities

(grayscale) at each point, then you need to keep the image in grayscale.

5. Go to Edit – Options – Point Tool and turn on Auto-Measure. You can also choose the

size of the point you want to make to label each object. This size required will depend on

the resolution of your image. You just need it to be big enough to be able to see it. If you

don’t want to automatically label the points, you could select the option to Add to ROI Manager. In this case, each point selection is added to the ROI Manager and you can

save the selections, etc. and make measurements as you can for any other ROIs.

Page 6: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

6

6. Now every time you click on the image, a dot will appear and the data will be entered into

the Results window. This includes the x, y z positions and the grayscale value.

7. Use the Magnifying tool if necessary to make the objects (cells) look bigger and the

Hand tool to navigate.

8. When you have completed all your measurements, you can save the image with the

marks on it.

Page 7: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

7

Grids You can also use a grid if necessary by going to Plugins – Analysis – Grid. You can define the

size of the grid and the points. A plugin for a Chalkley grid is also available (25 random spots).

Threshold approach: use thresholding followed by binarising to segment the objects which you wish to measure. The first part of the procedure is the same as that detailed for Area measurements.

1. Open the image. Change to grayscale (Image – Type – 8bit) or go to Image – Color - RGB Split.

2. Go to Image – Adjust – Threshold. You can select the Auto setting or alternatively move

the sliders yourself until you have all the stained areas selected. You should select dark background if you have a fluorescence or confocal image.

3. Click Apply to binarise the image if you are not interested in intensity values. The stained

areas which you want to measure will be black. You should not change the defaults unless

you want to measure the unstained areas. ImageJ regards the black areas as the

areas/objects of interest.

Page 8: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

8

4. Go to Analyze – Set Measurements. Choose the parameters you want to measure. You

may be interested in Shape Descriptors or Feret’s Diameter as well as the number of

particles in the images. Make sure that you include Display Label.

Page 9: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

9

5. Go to Analyze – Analyze Particles. The success of this depends on the individual objects

being able to be clearly distinguished. Note that you can exclude based on size and

circularity. If you have calibrated your image, then this size will be in whatever unit you are

using (e.g. microns squared). You can also Exclude on Edges, which is the usual

approach since you won’t have the whole particle in the image. Record Starts combined

with Add to Manager, adds all the particle outlines into the ROI Manager.

6. Click on OK to run the analysis.

Page 10: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

10

7. If you have holes in your particles as shown below, which will affect your measurements,

you could fill these holes by going to Process – Binary – Fill Holes. There is also an

option within the Particle Analyzer to Include Holes but filling the holes prior to analysis

ensures that it is done correctly. Other binary operations such as opening and closing or

dilation and erosion, can also be used and are found under Process - Binary menu.

8. If two particles are joined together, you can use processing filters such as Process – Binary – Watershed to separate them.

Page 11: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

11

9. You can use enhancement tools such as Brightness/Contrast or Window/Level to make

the particles easier to segment. There is also a large range of image processing filters and

operations available in ImageJ that can help to enhance contrast, etc. to make the

segmentation easier.

Note: If you don’t want the data for each individual particle, you can just save the Summary.

The outline/mask image can also be saved as a record.

Classify Particles Plugin: Gabriel Landini This is a plugin that works very well, which allows you to classify particles based on certain

morphological attributes such as size, circularity, etc.

This plugin and information about it are available here:

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

Page 12: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

12

INTENSITY MEASUREMENTS – FLUORESCENCE LABELLING ONLY Use thresholding to select the stained area which you wish to measure

1. Open the image. Change to grayscale if necessary (Image – Type – 8bit/16bit or Image – Color – Split Channels).

2. Go to Image – Adjust – Threshold. You can select the Auto setting or alternatively move

the sliders yourself until you have all the stained areas selected. The displayed histogram

gives you some assistance with this. There are a number of different methods available

under the drop-down box.

3. Choose Dark background for fluorescence images.

Page 13: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

13

4. Click Set to set the threshold of the image. If you want to use a consistent threshold (e.g.

based on your background value), you can type in values.

5. Go to Analyze – Set Measurements. Choose the parameters you want to measure. Make

sure that you select all the gray level measurements. You can change the number of

decimal places if you think you need more than the default (3). You should also select

Limit to Threshold. If you don’t select Limit to Threshold, then the entire image will be

measured, not just the selected area. In some cases, you do want the intensity

measurements for entire image.

6. Go to Analyze – Measure. The Results table will come up and you can then save this.

7. Intensity measurements can also be done within Regions Of Interest (ROIs), e.g. if you

need to exclude an area or if you need to create a number of ROIs of the same size that

you apply to multiple images. In this case, you add each ROI into the ROI Manager and

then once they are all there, click Measure.

Use thresholding to select the particles which you wish to measure Follow Steps 1-5 above then go to Analyze – Analyze Particles as described earlier. In this

case, the image is not converted to binary.

Page 14: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

14

USING PARTICLE ANALYSIS TO CREATE ROIS Use enhancement filters followed by binarising to segment the objects which you wish to measure. You can also use it to create regions of interest (ROI), that you then apply to a second image.

1. Open your first image (the one you want to use to create the ROIs).

2. Go to Image – Type – 8bit to change the image into grayscale or to Image – Colour – RGB Split and choose the image which has the most contrast.

3. Go to Image – Adjust Brightness/Contrast to improve the differentiation between the

edges of the objects and the background. You could also use Image – Adjust – Window/Level.

4. Remove any speckle/noise by using a filter, e.g. Process – Filters – Median.

5. Go to Process – Find Edges to define the boundaries of the objects. (Various other

options such as Process – Enhance contrast can also be used prior to this operation).

(You can also try Process – Filters – Variance, e.g. radius 2 pixels for a similar result).

Page 15: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

15

6. Go to Process – Binary – Threshold to binarise the image or do it manually by going to

Image – Adjust Threshold and then clicking on Apply once you are satisfied with the

selection.

Page 16: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

16

7. Now go to Process – Binary – Fill Holes.

8. These gaps in the outlines of the objects can be filled by going to Process – Binary –

Close. This performs a dilation and erosion operation to fill in the outline and small holes

in objects. You can also do the operations separately, i.e. Process – Binary – Dilate.

Then Fill Holes, followed by Process – Binary – Erode. You need to do the opposite

operation, i.e. if you erode, you must then dilate.

If any are not filled as

shown, it means that

some boundaries were not

complete.

Don’t worry about any

objects that are on the

image boundary. These

should not be included in

your analysis.

Page 17: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

17

9. You can change the options and preview the effect on your image by going to Process – Binary – Options.

10. If you are really struggling, then you can draw a small line using the pencil tool to fill in the

gap in the boundary. Make sure that the Foreground colour selected is black. You can

use the Magnifying tool to zoom up so that you can see the gap.

11. If you have lots of small particles or particles joined together, then you may want to use

Open to remove these.

12. If you have an image like the one below, try Process – Noise – Remove Outliers as

below. Note that this is the same image but in this case I have omitted the median filter

step, which has resulted in all these small black particles (=noise).

Page 18: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

18

13. Use the Preview option to show how this will affect the image. Select Dark for a binarised

image.

Page 19: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

19

14. If you want to analyse the particles, go to Analyze – Analyze Particles. This also will

allow you to add the outline of each nucleus into the ROI Manager to use on the second

image.

15. Now all the measured particles are outlined and each outline is added into the ROI

Manager as a ROI.

16. Another option if you don’t want to go through the Analyse Particles window is simply to

go to Edit – Selection – Create Mask. You then go to Edit - Selection – Create Selection and add that into the ROI Manager. However, in this case, you will only get one

measurement, since the selection combines all the outlines.

Page 20: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

20

Page 21: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

21

17. Now go to your second image. Convert it to grayscale.

18. Click on Show All in the ROI Manager. You will see all the ROIs on your second image

as shown below.

19. Make sure that you have all the grayscale measurement parameters selected in Analyze

– Set Measurements.

20.

Page 22: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

22

21. Click Measure in the ROI Manager.

22. If you want to use a threshold within the ROIs to define the grayscale levels of interest,

you can go to Image – Adjust threshold. In this case, you need to select Limit to Threshold in the Set Measurements window.

ROI MANAGER Manual Selections Draw a region by using the ROI tools or you specify a size by going to Edit – Selection -

Specify. All ROIs can be saved using the ROI Manager and applied to other images.

Loading ROI Sets

1. Open your image.

2. Go to ROI Manager and click Open.

3. Select the roiSet.zip file that you previously saved. These ROIs will then be inserted into

the ROI Manager. 4. You can then measure, draw, move ROIs, etc.

Page 23: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

23

Magic Wand Using the Magic Wand and ROI Manager.

1. Open up ROI Manager by going to Analyze – Tools – ROI Manager. 2. Using the binarised image that you have already created, go to the Wand Tool, and click

on one of the filled in objects: The object should then be outlined. Click Add in the ROI

Manager window. There is a tolerance value that you can alter to expand the selection

more according to the

3. Continue until all the nuclei have had ROIs created for them.

4. Then click Save. The ROIs will be saved as a zip file called ROISet. You can change the

name if you like. These ROIs can then be applied to your second image.

5. You can also use the Magic Wand to select grayscale values.

There is a more flexible magic wand tool available at:

http://imagejdocu.tudor.lu/doku.php?id=plugin:segmentation:versatile_wand:start

There is another one which also works in 3D called YAWI at: http://yawi3d.sourceforge.net/

Page 24: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

24

COLOUR DECONVOLUTION Notes on BIRU website: http://www.fmhs.auckland.ac.nz/sms/biru/facilities/analysis_resources.aspx

• Allows you to segment standard histological stain combinations such as Haematoxylin &

Eosin (H & E), and DAB with counterstains such as Haematoxylin or Methyl Green.

• You can also create your own matrices using stained sections or sample areas of your

stained section using a ROI to create the matrices.

• Following deconvolution, thresholding can be used to select the area of interest for

measurements as described above or alternatively the image can be converted straight to

a binary image.

EXAMPLE

1. Open the image. Use Process – Subtract Background if necessary to correct shadow or

colour effects.

2. Go to Plugins – Colour – Colour Deconvolution (or wherever you have placed the

Plugin).

Page 25: ImageJ: Introduction to Image Analysis 3 May 2012 · ImageJ: Introduction to Image Analysis 3 May 2012 . Jacqui Ross . Image analysis questions . 1. What do you want to measure in

25

3. Select the stain of interest, e.g. H & E. Then click OK.

4. The image will then be split into 3 components. If you have a 2 colour stain, then one

image should be white.

5. You can then use thresholding (or make the images binary) and make your

measurements.