FARSIGHT Tutorials/Quick Start
LuisIbanez (Talk | contribs) |
LuisIbanez (Talk | contribs) |
||
Line 30: | Line 30: | ||
− | = | + | = Starting the Interpreter = |
The first thing you need to do is to start your Python interpreter | The first thing you need to do is to start your Python interpreter | ||
Line 43: | Line 43: | ||
This may take some seconds while the shared libraries are loaded. | This may take some seconds while the shared libraries are loaded. | ||
− | = | + | = Reading an image from a file and Showing it = |
== Getting example image == | == Getting example image == | ||
Line 115: | Line 115: | ||
This line will write the image represented in the variable "image1" to the file specified by a full path. | This line will write the image represented in the variable "image1" to the file specified by a full path. | ||
− | = | + | = Smoothing an image = |
image = itk.read( itk.Image.F2, "/pathToImages/cells.png") | image = itk.read( itk.Image.F2, "/pathToImages/cells.png") | ||
Line 136: | Line 136: | ||
* JPEG | * JPEG | ||
− | = | + | = Computing gradients from an image = |
image = itk.read( itk.Image.F2, "/pathToImages/cells.png") | image = itk.read( itk.Image.F2, "/pathToImages/cells.png") | ||
Line 146: | Line 146: | ||
itk.write( gradientMagnitudeImage, "/pathToImages/gradientMagnitude.mha") | itk.write( gradientMagnitudeImage, "/pathToImages/gradientMagnitude.mha") | ||
− | = | + | = Thresholding an image = |
filter = itk.BinaryThresholdImageFilter.IF2IUC2.New() | filter = itk.BinaryThresholdImageFilter.IF2IUC2.New() |
Revision as of 13:24, 4 May 2009
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.
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.
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".
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()
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".
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
Showing an image
You can do a quick display of the image by typing the command
itk.show2D( image1 )
This will display the image in an newly open window
This is done by using the package imview
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.
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
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")
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).