Quantitative Big Imaging

Kevin Mader, Maria Büchner
27 March 2014

ETHZ: 227-0966-00L

Analysis of Complex Objects

Exercises

Tools for the Exercise

  • Basic Exercises

  • Advanced Exercises

    • Contour and Curvature in ParaView
    • 3D Watershed in Matlab

Objectives

  1. Use thickness to quantify evolution in a structure
  2. Use a skeleton to identify connectivity of a pore network
  3. Use watershed to segment cells clustered together
  4. Characterize the surface of beer foam using curvature

Setting up the Computers

Once you have logged in

  1. Open Matlab
  2. Type in the following commands exactly!
  3. This will start Fiji

Setting up the Computers

In Matlab run the following code Copy / Paste from Here

cd('~')
unzip('http://jenkins.imagej.net/job/Stable-Fiji/lastSuccessfulBuild/artifact/fiji-nojre.zip','./')

addpath 'Fiji.app/scripts'
Miji % start Miji
cd('~')
% to test if it works
% Miji_Test

Changing Java Heap

If the Java Heap Space is not high enough strange error messages may appear. Increase the Java Heap Space using the preferences (in this movie)

Basic MIJ (MIJ) Refresher

Tools provide an interface between Matlab and FIJI

Pushing Matlab Images to ImageJ

% random 500 x 500 array
imData=rand(500); 
MIJ.createImage('test',imData,true);

Reading Images from FIJI to Matlab

MIJ.run('Embryos (42K)');
imData = MIJ.getCurrentImage;
% take the sum of red, green, and blue
imSum = sum(double(imData(:,:,1)),3); 
subplot(1,2,1)
imagesc(imSum);
subplot(1,2,2);
imagesc(imSum<150)

FIJI: Recording Macros

Recording Marco's Movie

  • ImageJ provides a powerful macro language, API
  • macro-recording feature that allows you to record operations and apply the same steps in a folder full of images
  • not all features are supported so be careful
  1. You can run a Macro again by going to New \( \rightarrow \) _Script, pasting the code in
  2. Set the Language \( \rightarrow \) to ImageJ Macro
  3. Run

Macros to MIJI

For many commands, the results from macro recording can be directly used in Matlab/MIJI by making the following changes

  1. add MIJ. before the command
  2. Replace the character “ with '
run("Compute Curvatures", "compute sigma=0.5000 use order");

\[ \downarrow \textrm{Becomes} \]

MIJ.run('Compute Curvatures', 'compute sigma=0.5000 use order');

FIJI: Creating Test Images

Many of these operations can produce fairly complicated results which can be difficult to interpret on complex structures. It is thus easiest to test their functionality and parameter sensitivity using test images.

  1. File \( \rightarrow \) Image Create a new image with desired size and background (512x512 is fine)
  2. Use the rectangular, oval, polygonal, or freehand selection tools (the first buttons in the toolbar)
  3. Draw a region and either click delete or go to Edit \( \rightarrow \) Invert
  4. Repeat for as many shapes as you want
  5. Using the macro-recording feature you can end up with a script to generate test images

Ovals Marco

setBackgroundColor(0,0,0)
newImage("Untitled", "8-bit white", 2000, 2000, 1);
run("Invert");
makeOval(252, 177, 240, 240);
setBackgroundColor(0, 0, 0);
run("Invert");
makeOval(840, 180, 222, 501);
run("Invert");
makeOval(1494, 168, 222, 879);
run("Invert");
makeOval(255, 1308, 633, 633);
run("Invert");
makeOval(1236, 1191, 642, 741);
run("Invert");
run("Select None");

FIJI: Skeletonization

Two options

  1. Plugins \( \rightarrow \) Skeleton \( \rightarrow \) Skeletonize (2D/3D)…
    • A thinning based approach not covered in the class but potentially useful for some applications
  2. Analyze \( \rightarrow \) Local Thickness \( \rightarrow \)
    • Geometry to Distance Map creates the distance map itself
    • Distance Map to Distance Ridge creates the ridge (or local maximum values from the distance map)

Macro Commands

run("Geometry to Distance Map", "threshold=1");
run("Distance Map to Distance Ridge");
  1. Try both approaches using the test or your own image and comment on which works better. How might you improve the distance map based method
  2. Use Matlab to analyze the structures from both. The script assumes a 1 voxel thick skeleton. Starting Script (The final output is a color map showing terminal points (\( =1 \)), connecting lines (\( =2 \)), and junctions (\( =3 \)))

Simple Test Image

ImageJ Macro or make your own

FIJI: Thickness Analysis

FIJI has a built in pathway for performing thickness analysis in the

  • Analyze \( \rightarrow \) Local Thickness menu
  • Provides full thickness analysis option (from binary mask to thickness map)
  • Provides individual steps (they prune afterwards instead of before)
    • What does the pruning (Cleaned-up Local Thickness) step do?

This can be used from Matlab with the following command

MIJ.run('Local Thickness (complete process)', 'threshold=1')

FIJI: Thickness Analysis on Foam

  • Load in the Pivo data (beer in czech) http://people.ee.ethz.ch/~maderk/qbi/PivoData.zip
  • It is liquid foam where the liquid absorps X-rays and the air does not
  • Filter and threshold so you can see the liquid between bubbles
  • Calculate the local thickness
  • Repeat for the other samples, what is the difference?
    • Bonus: What physical process might be behind this?

FIJI: Watershed Segmentation

We will use watershed segmentation to “break apart” single blobs into sub-objects

  1. Create a distance map from the Analyze \( \rightarrow \) Local Thickness menu
  2. Try and identify the separate objects from the distance map
  3. Apply a watershed transformation (Process \( \rightarrow \) Binary \( \rightarrow \) Watershed)
  1. Create a test image from overlapping circles
  2. Try to separate them using Watershed
  3. Do again with very anisotropic ellipses instead of circles
  4. Apply the “Analyze Particles” command in both cases to compare the results with and without watershed
  5. Modify your scripts from the last exercises with simulated Cell Images to apply watershed before “Analyze Particles” is run, hint: MIJ.run('Watershed')
  6. Is the accuracy markedly improved?

FIJI: Watershed on Real Images

Using the foam images from the thickness component

  1. Run watershed on a single slice (click No in the dialog) of the thresheld image
  2. How well did it perform?
  3. Are there other preprocessing steps which might improve the segmentation
  4. Run watershed on the entire stack (click Yes in the dialog)
  5. Examine other slices in the image
  6. How could you improve the quality of the segmentation?

FIJI: Computing Curvature

Curvature definitions

MIJ.run('Compute Curvatures', 'compute sigma=0.5000 use order');

Compute the curvature on several test images and try adjusting the sigma (\( \sigma \)) value for the Gaussian filter applied.

  1. What happens to the results when you change this value?
  2. Is 0.5 enough? For the ovals image at the beginning what is an appropriate value?

Challenge MATLAB: Reading Curvature Values from FIJI

Using one of the test images you have made (or the one we supplied by Macros). You can show the curvature distribution against the shape and get a feeling for the kind of results you can extract

Using the follwing script you can inspect the results.

  • This version calculates just the positive curvatures by using absolute value

  • Can you differentiate between small circles and large circles (create an image to test this)

  • What is the relationship between radius and curvature?

  • In an anisotropic ellipse how to the semiaxis lengths relate to the curvature?

Advanced FIJI: Skeletonization of a Foam

  • Load in the Pivo data (beer in czech) http://people.ee.ethz.ch/~maderk/qbi/PivoData.zip
  1. Run the skeletonization as in the previous example.
  2. Import the skeleton into Matlab using the script

Advanced: Paraview

  • What is ParaView
    • parallel, distributed image processing and visualization toolbox written in C++
    • open source, extendable API
    • pipeline style analyses

General Paraview Tutorial

Loading Data Into Paraview

Video Instructions Additional more detailed Web Instructions

Advanced: Calculating Curvature in Paraview

Source Scripts

The following python script / Paraview state file (they perform the same task but one is more of a macro while the other is a saved state file) show how to use the “Threshold” and “Extract Surface” commands to get meshes from voxel data. For curvature we will use the contour command (like isosurface in Matlab) to extract contours at different values. From these contours we can then calculate the curvature using the curvature filter

  1. Filters \( \rightarrow \) Alphabetical \( \rightarrow \) Curvature

We can visualize the results either in 3D mapped to the surface or as a histogram by using the Histogram tool

  1. Filters \( \rightarrow \) Data Analysis \( \rightarrow \) Histogram

Advanced: 3D Watershed in Matlab

Matlab's built-in watershed function works on both 2- and 3D image data.

watershed

The Matlab watershed command performs both watershed and the labeling of the resulting components (as shown in the lecture) unlike FIJI which just introduces a line between components that could be separated so that component labeling can be performed.

Advanced: Contact Area Estimation

  • Since the watershed operation allows us to segment out the individual components of clumped objects.
  • We can examine the interfaces between these objects (when we use component labeling this interface area is necessarily 0).
  • The goal of the exercise is to determine the area of the interfaces between objects after performing a watershed operation
  • This can be done by writing a short script which examines the neighborhood of each voxel and compares the values to see if a boundary is present.
    • Another approach is to use the nlfilter command with a special function to identify if more than one voxel type is present
    • Hint unique command tells you the different values present in a list