CH922: Image Analysis Practical November 2014

advertisement
1
CH922: Image Analysis Practical
November 2014
Till Bretschneider
Warwick Systems Biology Centre
T.Bretschneider@warwick.ac.uk
Tel: 024 76 1 50252
Important: Document all steps by saving images (also intermediate results) and macro
code. Comment all macros using // at the beginning of a remark
(For ordinary images, histograms, plots etc. you can use the “edit->copy to system” command.
Brightness&Contrast windows have to be captured using the “Alt+Print Screen” utility in Windows. On
Macs use “command + shift + 4” then activate the window to be copied with the mouse and press
space to copy a particular window to the clipboard.)
Install the Fiji distribution of ImageJ following this weblink
http://pacific.mpi-cbg.de/
You can open the Control Panel (Plugins->Utilities->Control Panel) to obtain a better
overview about installed plugins.
Help->Documentation is the first place to lookup menu commands.
Make extensive use of Help->Plugins…, Macros…, Macro Functions… to find out about
specific commands.
Practical I
1. ImageJ macro recorder: Subtract background Example
All tasks performed in ImageJ can be automated using macros. A macro recorder translates
menu commands into macro functions and also keeps track of what you have been doing. It
can be found under:
Plugins->Macros->Record
Open B03-1-100-d1-frame1.tif using File->Open after you have opened the macro
recorder
Create a histogram by calling Analyze->Histogram and save the image of the histogram.
Create a line with the line ROI tool and look at the intensities along the line using:
Analyze->Plot Profile
2
Save the line scan for your protocol and remember to document all other intermediate
steps.
A particularly useful tool is the ROI Manager. It is called using
Analyze->Tools->ROI Manager
Add your line ROI so that you can restore it later.
Create a rectangular or oval region of interest (“ROI”) in the background.
Use Analyze->Measure and write down the value for the mean intensity.
Call Edit->Selection->Select All to make sure the following command operates on the whole
image rather then your ROI only
Now, see what Process->Math->Subtract does using the value you obtained before.
Again, produce a histogram and save it.
Now have a look at the Recorder window and check out the syntax of the various commands
you applied.
Close the macro recorder.
Now we will create a macro for background subtraction:
Call Plugins->New->Macro.
Save the macro, choose a name which ends in .ijm
Copy the following first two lines of the macro into the macro editor:
getStatistics(area, mean, min, max, std, histogram);
run("Select All");
To find out what command you use for doing the subtraction look up the syntax in the
Macro Recorder.
Replace the numeric value that is passed to Subtract with “&mean” and try out your macro
by selecting different background regions, ie “value=Your_number” should be replaced with
"value=&mean”.
// In ImageJ 1.43 and later variables can be passed by adding
// "&" to the variable name. In earlier versions you have to use
// the “+” operator to concatenate strings.
Document your macro in your write-up.
Remember to use Help->Macro Functions from the main ImageJ toolbar to lookup functions
you are not familiar with.
Apply your macro and look at the line profile again (restore your line ROI from the ROI
Manager by just clicking on it).
Save the line profiles for the original image and the background subtracted image to include
them in your write-up.
3
Draw the line in your image using Edit->Draw to indicate where the line profiles have been
sampled and save it. If nothing appears, open “Image->Color->Color Picker” and select
white.
2. Image math
Remember to apply Plugins->Macros->Record to record your commands for later use in a
macro, or clear the content of the window.
Open “kernel-test.txt”, and import the same file as text image (File->import->Text Image). It
is only 5x5 pixels, so you have to really zoom into it using the magnifying glass tool to display
it properly. Move your mouse over the individual pixels and confirm the pixel intensities in
the ImageJ status line. Now we will convolve the image using Process->Filters->Convolve
with the following kernel:
 
0 0 0
H= 1 1 1
0 0 0
Make sure that the “Normalize Kernel” option is not ticked.
Save the result as text-image using File->Save As->Text Image... and open it again using
File->Open to look at the numeric values.
By hand: For an arbitrary image pixel Ii,j write out the nine summands that occur in the 3x3
kernel operation in the following form: Ii-1,j-1 * Hi-1,j-1 + Ii-1,j * Hi-1,j + ... .
Verify your previous result for a particular pixel of your choice, eg pixel at position (3,3) of
the kernel-test image.
3. Gradient Filters
Open “striated-muscle.jpg”. Convert it to 32 bit by applying Image->Type->32bit and
duplicate your image by applying Image->Duplicate.
Invoke Process->Filter->Convolve… on each of the images and try out what the following
kernels do (Do not tick the “normalize kernel” option).

 
−1 0 1
−1 −2 −1
−2 0 2
0
0
0
−1 0 1 and 1
2
1

What are the equivalent mathematical operations?
(Hint: the result of applying the first kernel can be obtained by successively applying the two
following kernels:
{ −1
0
1}

1
and 2 )
1
Use the line tool to place a line across the stripe pattern, then look at the intensity profile
using Analyze->Plot Profile
Why did you have to convert the image to 32bit first?
4
Save the resulting images.
A commonly used filter is the Sobel filter (B: brightness):
Magnitude=

  
2
∂B
∂B

∂x
∂y
2
Discuss what it is doing.
Use Process->Math->Square and Process->Image Calculator to create your own Sobel filter.
Go to the Recorder window and apply “Create”
Save the macro using File->Save As
Your template should look something like:
open("YOUR_PATH\\striated-muscle.jpg"); // on Mac/Linux YOUR_PATH/striated-muscle.jpg
run("32-bit");
run("Duplicate...", "title=striated-muscle-1.jpg");
run("Convolve...", "text1=[-1 -2 -1\n0 0 0\n1 2 1\n]");
run("Convolve...", "text1=[-1 0 1\n-2 0 2\n-1 0 1\n]");
run("Square");
run("Square");
imageCalculator("Add create 32-bit", "striated-muscle.jpg","striated-muscle-1.jpg");
Find out how to square root the result.
One problem with the above template is that the Convolve and Square commands do not
specify on which image they operate. Also it would be nice to apply the filter to an arbitrary
image selected from a list.
Change the first line to:
open();
Make sure the text cursor is in this line and use Macros->Evaluate line to see its effect.
Check out Help->Macro Functions
Look up getImageID(), imageCalculator(operator, img1, img2) and convert your macro into a
working one. Don't forget to square root your final image.
Remember to insert comments into your macro by using // at the beginning of a line
Construct a new 200x220 (size of striated-muscle.jpg) stack of four slices and 32 bit using
File->New.
Copy the original image, the two gradient images and the Sobel filtered image into
subsequent slices of the stack using Ctl-A (select everything), Ctl-C (Copy) and Ctl-V (Paste)
for insertion into the new stack (On Mac Ctl is the Command key).
Save the stack
Create a Montage from the stack using Image->Stacks->Make Montage and save it for your
protocol.
5
Practical II
4. Working with stacks (time series or z-stacks)
Open B03-1-100-d1.tif which shows a population of cell stained with a nuclear marker
(Hoechst). Create a substack of the first 15 frames using “Image->Stacks->Tools->Make
Substack”
Plot a histogram using Alt+H with 0 and 1600 for the minimum and maximum values (Tick
the “Stack Histogram” option to include intensities of all slices in the histogram).
Rewrite your previous macro for background subtraction, so that it runs through the whole
stack. Use the following fragment for a “for-loop” where ImageJ sets nSlices to the actual
number of slices in the current stack.
for (i=1;i<=nSlices;i++) {
setSlice(i);
//put your background subtraction routine here
}
Select a circular or rectangular region in the background and make sure that no cells enter
this region when you run through the stack.
Run your macro and again output the histogram (in the interval [0,1600]). Discuss the
changes.
Next we will not only subtract the same value from every frame, but will compute the
background and subtract it for each individual frame.
Call Plugins->New->Macro and select a name for your macro
Enter or copy the following lines into the macro editor:
roiManager("reset")
roiManager("Add");
for (i=1;i<=nSlices;i++) {
setSlice(i);
getStatistics(area, mean, min, max, std, histogram);
run("Select All");
run("Subtract...", "value="+mean);
roiManager("select", 0);
}
Use Help->Macro Functions from the main ImageJ toolbar and lookup the functions you are
not familiar with
Discuss in which kind of experimental situation this approach might be preferred to the one
in which you only subtract the background of the first image in a sequence.
.
5. Projections of 3D stacks (t or z-stacks) and Logical
Operations
Open the binarised image of a moving cell: moving-cell.tif
Apply Image->Stacks->Z project with the “Sum Slices” Projection type.
Use Image->Lookup tables->Fire
6
Discuss how you interpret the resulting picture.
Now, let’s visualise the area the cell gains while moving in green and the lost area in red:
We delete every second frame by applying Image->Stacks->Tools->Slice Remover to
calculate gain and loss over a period of two frames.
Rename the original stack “First”.
Duplicate the stack (Image->Duplicate) and name it “Second”.
Using “Image->Stacks->Delete Slice” delete the first frame of “Second” and the last frame of
“First”
Run Process->Image Calculator and subtract First from Second (Tick the “create new
window” option).
Use Image->Rename and call the Result of the subtraction “gain”.
Do the reverse and subtract Second from First. Rename the result “loss”.
Now let’s put everything together:
Apply the Image Calculator with the following settings: First , loss “XOR”
Discuss what this operation does.
Proceed with “Image->Color->Merge Channels”
with red: loss, green: gain, blue: “none”, grey: Result of First and the “composite” as well as
the “keep source” option ticked.
Save gain and loss as tiff files. We will need them later.
6. Z-Profiles
Select “gain” and create a Z-profile (“Image->Stacks->Plot Z-axis profile”)
How do you interpret your result? What further analysis could be done with this time series?
7. Fourier Transforms
Load grid.tif and have a look at the powerspectrum applying “Process->FFT->FFT”
Double click the colour picker (pipette) tool and select black as foreground colour (the
pipette on the colour picker icon must be black).
Using a rectangular ROI and the “edit->fill” command remove the frequencies representing
the vertical bars. See whether you succeeded by calling “Process->FFT->Inverse FFT”.
Do the same for the horizontal lines.
Load shading.tif and remove the background using appropriate masking of its
powerspectrum and back-transformation.
Have a look at “Process->FFT->Bandpass Filter”:
Try to remove the lines and the background shading again (Use the “suppress stripes”
option). In particular check the “Display filter” option and discuss its output.
Download