Quantitative Big Imaging

Kevin Mader, Maria Büchner
20 March 2014

ETHZ: 227-0966-00L

Analysis of Single Objects

Exercises

Tools for the Exercise

Objectives

  1. Perform Shape Analysis in Fiji
  2. Use FIJI from Matlab to Perform Component Labeling and Shape Analysis
  3. Use quantitative shape anaysis to assess how well our segmentation of cells work (not just total count, but orientation distribution and other information)
  4. Write Custom Shape Analysis in Matlab

Setting up the Computers

Once you have logged in

Open Matlab

Type in the following commands exactly!

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 Particle Analyzer

FIJI has a built in basic particle analyzer in the Analyze_\( \rightarrow \) _Analyze Particles… menu and the Set Measurements… menu.

Set Measurements

This is used to specify what the particle analyzer does when it runs on an image, the settings we use for this exercise are:

MIJ.run('Set Measurements...', 'area centroid perimeter bounding fit shape stack redirect=None decimal=3');

Which mean calculate area, centroid (center of volume), perimeter, bounding box, fit an ellipse, shape metrics, stack (keep the z position).

Analyze Particles

MIJ.run('Analyze Particles...', 'show=Ellipses display clear');

These settings are more basic and just show the ellipse fits in a new window, display the results in a table, and clear after runing.

Cell Exercise

Download the new image generator function and save (right click raw and then click “Save Link As”) it in your home directory cell_simulator.m to generate images with varying parameters (keep noise at 0 and illumination at 1 for now)

  1. Perform a threshold
  2. Run a component labeling and shape analysis
  3. Compare the shape analysis to the original results

Starting Script

Volume

  • How do the volume distributions change between the model cells and the analysis? What effect might explain this?
  • How might you compensate for this difference in the results? (Hint: it is already part of the analysis output)
  • Calculate the volume fraction of the cells from the data

Position

  • How well do the positions of the cells overlap?
  • Where do most of the problems seem to occur

Angle

  • How does the angle of the primary axis given as input compare to the computed angle?
  • Run the simulation with cell_radius_std=0 how does the angle compare now? Why?

Challenge: Writing your own shape analysis script

Using the following code as a starting point, can you write your own function to perform the shape analysis within Matlab.

  1. Add a column for anisotropy
  2. Add a column for oblateness
  3. Testing is important use a test image to make sure your function is working correctly (an easy starting point is diag(1:20))

Creating an Isosurface in Matlab

Starting Code

  1. Show an isosurface for just a region of interest in the image
  2. What does an isosurface represent? Estimate how much more memory is used than for displaying all the slices
  3. Change the value from 100 in the script, what happens? How is this different from thresholding
  4. Try on other 3D images

Creating an Isosurface in FIJI

You need to have Java3D installed so it will not work on the tardis (computer lab) machines, but it should work on your personal computer

  1. Load a 3D image in FIJI (File -> Open Samples -> MRI Stack in case you don't have your own)
  2. Perform a threshold
  3. Create the surface using the Create Surfaces plugin
    • Run the plug-in using the “Plugins -> Segmentation -> Create Surfaces”
  4. The meshes will be created and displayed in a 3D Viewer Window
  5. You can export the meshes by “File -> Export Surfaces”

Advanced: Creating an Isosurface / Mesh 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.

Advanced: 3D Shape Analysis in FIJI

FIJI has a more advcaned built in “3D Object Counter” in the Analyze_\( \rightarrow \) _3D Object Counter menu. It has a number of options built into the function itself, it also has an option item (3D OC Options) where even more parameters can be adjusted

Object Counter

MIJ.run('3D Objects Counter', 'threshold=128 slice=0 min.=0 objects surfaces centroids centres_of_masses statistics summary');

Options

MIJ.run('3D OC Options', 'volume surface nb_of_obj._voxels nb_of_surf._voxels integrated_density mean_gray_value std_dev_gray_value median_gray_value minimum_gray_value maximum_gray_value centroid mean_distance_to_surface std_dev_distance_to_surface median_distance_to_surface centre_of_mass bounding_box dots_size=5 font_size=10 show_numbers white_numbers store_results_within_a_table_named_after_the_image_(macro_friendly) redirect_to=none')

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

  1. Load Data in
  2. Apply a threshold
  3. Visualize the segmentation
  4. Simplify the mesh
    • When would it make sense to simplify a mesh on a computer?
  5. Subdivide a mesh
    • when would it make sense to subdivide a mesh? Do you gain detail on the structure?

Advanced: Paraview Tensor Visualization

Tensor Glyph Plugin can be used to visualize tensor, in particular the shape tensor. Specific instructions for setting this plugin up on a Mac are here