FARSIGHT Tutorials/Quick Start

From FarsightWiki
Revision as of 13:19, 4 May 2009 by LuisIbanez (Talk | contribs)
Jump to: navigation, search

Contents

Details

  • Goal: This tutorial is intended to show you how to use FARSIGHT basic operations
  • Duration: 30 minutes
  • Requisites: Basic familiarity with Python commands
  • Materials: FARSIGHT Installed

Basics Concepts

Image Types

ITK requires users to be aware of the pixel type and dimension used by the images.

Typical pixel types and dimensions may be

Image Type Pixel Type Dimension pixel depth
IUC2 unsigned char 2 8 bits per pixel
IUC3 unsigned char 3 8 bits per pixel
IUS2 unsigned short 2 16 bits per pixel
IUS3 unsigned short 3 16 bits per pixel

For the purpose of this tutorial session we will focus on using only two-dimensional images of 8bits per pixel. This is defined as IUC2.


Part I: Starting the Interpreter

The first thing you need to do is to start your Python interpreter

  • In GNU/Linux and Mac this is done by simply typing "python" from within the X11 window
  • In Windows this is done by launching from the Start menu the program "Python (command line)"

Once the command line window appears, type

 import itk

This may take some seconds while the shared libraries are loaded.

Part II: Reading an image from a file and Showing it

Getting example image

Download this image to your computer. Simply right-click on it from your browser and select the option "save link as".


CellsFluorescence1.png


Alternatively you could get this image from the ITK directory


   Insight/Testing/Data/Input/CellsFluorescence1.png


Save the image file in any directory, but remember what directory this is. Hereafter we will call pathToImages the full path to that directory where you put this image file..


Reading the image file

In order to read the image, please type the following commands

 reader1 = itk.ImageFileReader.IUC2.New(FileName="pathToImages/CellsFluorescence1.png")
 image1  = reader1.GetOutput()
 itk.show( image1 )

The first line declares an ImageFileReader for 2D images of pixel type "unsigned char" (8bits per pixel), and provides the full path to the image file to read.

ITK supports multiple file formats, including

  • TIFF
  • JPEG
  • PNG
  • BioRad

Once the first line finish executing, and you get the prompt back, the image will have been read into memory.

The second line assigns the read image to the variable "image1".

The third line will display the image in an newly open window

This is done by using the package imview


This could be simplified by using the following Python function

  def readimage( imagetype, filename ):
    rd1 = itk.ImageFileReader[imagetype].New()
    rd1.SetFileName(filename)
    rd1.Update()
    image = rd1.GetOutput()
    return image

Part II: Writing an image to a file

 itk.write( image1, "/pathToImages/cells2.tiff")

This line will write the image represented in the variable "image1" to the file specified by a full path.

Part III: Smoothing an image

 image = itk.read( itk.Image.F2, "/pathToImages/cells.png")
 filter = itk.SmoothingRecursiveGaussianImageFilter.IF2IF2.New()
 filter.SetInput( image )
 filter.SetSigma( 2.0 )
 filter.Update()
 smoothedImage = filter.GetOutput()
 itk.write( smoothedImage, "/pathToImages/smoothed.mha")

Note that because we are using an image of pixel type "float" the file format for the output image has to be selected from the set of file format that supports float pixels. This includes

  • MetaImage
  • VTK

and does not include

  • TIFF
  • PNG
  • JPEG

Part IV: Computing gradients from an image

 image = itk.read( itk.Image.F2, "/pathToImages/cells.png")
 filter = itk.GradientMagnitudeRecursiveGaussianImageFilter.IF2IF2.New()
 filter.SetInput( image )
 filter.SetSigma( 2.0 )
 filter.Update()
 gradientMagnitudeImage = filter.GetOutput()
 itk.write( gradientMagnitudeImage, "/pathToImages/gradientMagnitude.mha")

Part V: Thresholding an image

 filter = itk.BinaryThresholdImageFilter.IF2IUC2.New()
 filter.SetUpperThreshold( 200 )
 filter.SetLowerThreshold( 100 )
 filter.SetInput( inputImage )
 filter.Update()
 binaryImage = filter.GetOutput()
 itk.write( binaryImage,"/pathToImages/binary.png")
 itk.show( binaryImage )

In this case the type of the input image and the output image are not the same. The input image uses "float" as pixel type, while the output image uses "unsigned char" (8 bits per pixel).

Personal tools