Medical Image Processingcvinhais.noip.me/materials/itk/itk_presentation_EN.pdf · Medical Image...
Transcript of Medical Image Processingcvinhais.noip.me/materials/itk/itk_presentation_EN.pdf · Medical Image...
Medical Image ProcessingITK Insight Toolkit
Carlos A. [email protected]
ISEP – Departamento de FısicaInstituto Superior de Engenharia do Porto
Porto, Portugal
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 1 / 133
Medical Image ProcessingITK Insight Toolkit
Introduction to ITK
Data Representation
Image IO
Image Iterators
Filtering
Segmentation
Registration
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 2 / 133
Introduction
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 3 / 133
ITK Insight ToolkitIntroduction
ITKThe Insight Segmentation and Registration Toolkit
Image Input/Output (IO)
Image Filtering
Image Segmentation
Image Registration
No visualization
No GUI(Graphical User Interface)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 4 / 133
ITK Insight ToolkitIntroduction
(www.itk.org)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 5 / 133
ITK Insight ToolkitSoftware Guide
The ITK Software Guide Book 1Introduction and Development GuidelinesVol. 1, Kitware Inc., ITK 4.7 Edition (2015)H.J. Johnson, M.M. McCormick, L. Ibanez
The ITK Software Guide Book 2Design and FunctionalityVol. 2, Kitware Inc., ITK 4.7 Edition (2015)H.J. Johnson, M.M. McCormick, L. Ibanez
Freely available for download:InsightSoftwareGuide-Book1-4.9.0.pdfInsightSoftwareGuide-Book2-4.9.0.pdf
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 6 / 133
ITK Insight ToolkitBuild and Test ITK
C++ Programming
Install C++ Compiler/IDE
Install CMake
Download ITK source
Build ITK with CMake
Build C++ Exercises with CMake
Run C++ Exercises
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 7 / 133
ITK Insight ToolkitBuild and Test ITK
Python Programming
Install Python(x,y)(with itk pluginselected)
Run Spyder IDE
Run Python Exercises
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 8 / 133
ITK Insight ToolkitSoftware ITK Snap
(www.itksnap.org)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 9 / 133
ITK Insight ToolkitITK Computer Exercises
C++ Exercises
HelloWorld.zip
myProject.zip
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 10 / 133
Data Representation
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 11 / 133
Data RepresentationOverview
Digital Image
Pixels and Voxels
Sampling and Quantization
ITK Image
File Formats and Pixel Types
Pixel Neigborhood
Pixel Connectivity
Distance Metrics
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 12 / 133
Data RepresentationDigital Image
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 13 / 133
Data RepresentationPixels and Voxels
Picture element Volume element
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 14 / 133
Data RepresentationSampling and Quantization
Spatial resolution Pixel intensity
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 15 / 133
Data RepresentationSampling and Quantization
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 16 / 133
Data RepresentationSampling and Quantization
Image ofconstant size:
472× 374
Number ofintensity levels:
L = 2k
k = no of bits/pixel
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 17 / 133
Data RepresentationITK Image
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 18 / 133
Data RepresentationITK Image
Pixel Coordinates
pixel Index: [i , j , k]
image Region
start [0, 0, 0]size [Nx ,Ny ,Nz ]
pixel Type
pixel Intensity
Physical Coordinates
point coord.: (x , y , z)
coord. system OXYZ
origin (xO , yO , zO)spacing (dX , dY , dZ )
Image Extent
(∆X ,∆Y ,∆Z )
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 19 / 133
Data RepresentationITK Image
Physical units: mm
Coordinate Transformation:point (x , y , z) ↔ pixel [i , j , k]
point = origin + index*spacing
x = xO + i · dXy = yO + j · dYz = zO + k · dZ
ITK Classes:itk::TransformIndexToPhysicalPoint(index, point)itk::TransformPhysicalPointToIndex(point, index)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 20 / 133
Data RepresentationFile Formats and Pixel Types
BMP (2D only)
unsigned charRGB
PNG (2D)
unsigned charunsigned shortRGB
TIFF (2D only)
unsigned charunsigned shortRGB
JPEG (2D only)
unsigned char
GDCM
unsigned charcharunsigned shortshortunsigned intIntdouble
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 21 / 133
Data RepresentationFile Formats and Pixel Types
DICOMfloatcharunsigned charshortunsigned shortRGB (char)RGB (short)
VTKfloatdoubleunsigned charcharunsigned shortshortunsigned intintunsigned longlongRGB
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 22 / 133
Data RepresentationFile Formats and Pixel Types
The itk::Image class can be templated over virtually any pixel type,however
not all file formats support all data types for reading and writing. Insome cases, it may be necessary to add an itk::CastImageFilter toconvert the output to a pixel format appropriate for the target file.
It is important not to truncate the data by converting to a smallertype (e.g. short → char). In this case, theitk::RescaleIntensityImageFilter can be used before casting.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 23 / 133
Data RepresentationPixel Neighborhood
2D Neighborhood
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 24 / 133
Data RepresentationPixel Neighborhood
2D Neighborhood Shapes
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 25 / 133
Data RepresentationPixel Connectivity
2D Connectivity
4–connected 8–connected
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 26 / 133
Data RepresentationPixel Connectivity
How many CONNECTED objects?
2 OBJECTS(4-connected)
or
1 OBJECT(8-connected)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 27 / 133
Data RepresentationPixel Connectivity
3D Connectivity
6–connected 10–connected 26–connected
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 28 / 133
Data RepresentationDistance Metrics
Distance between points/pixels p (x , y) and q (s, t)
Euclidian De (p, q) =√
(x − s)2 + (y − t)2
Cityblock D4 (p, q) = |x − s|+ |y − t|
Chessboard D8 (p, q) = max (|x − s| , |y − t|)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 29 / 133
Data RepresentationDistance Metrics
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 30 / 133
Data RepresentationAccessing Pixel Data
GetPixel() and SetPixel() are very inefficientfor accessing pixel data.
These methods should only be used for debugging or forsupporting interactions like querying pixel values by mouse clicking.
Image iterators should be used whenmassive access to pixel data is required.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 31 / 133
Data RepresentationITK Computer Exercises
C++ Exercises
CreateImages.zip
Python Exercises
1.Create2DImage.py
2.Create3DImage.py
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 32 / 133
Image IO
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 33 / 133
Image IOOverview
Reading and Writing Images
Region of Interest Extraction
Slice Extraction from Volume
DICOM Images and Header (metadata)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 34 / 133
Image IOITK Computer Exercises
C++ Exercises
ReadRGBWritePNG.zip
DicomReadPrintTagsWrite1.zip
DicomReadPrintTagsWrite2.zip
DicomSerieReadPrintTagsWrite.zip
ImageReadImageSeriesWrite.zip
Python Exercises
1.Read2DImageWrite.py
2.Read3DImageWrite.py
3.ExtractRegionOfInterest.py
4.ExtractSliceFromVolume.py
5.GenerateSlicesFromVolume.py
6.DicomSerieReadPrintTagsWrite.py
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 35 / 133
Image Iterators
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 36 / 133
Image IteratorsOverview
ITK Image Iterators(non-constant, constant, with index)
Linear
Slice
Region
Neighborhood
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 37 / 133
Image IteratorsSTL Iterators
STL Iterators(1D vector)
#include <vector >
typedef std::vector < float > VectorType;
VectorType myVector;
myVector.push_back( 4 );
myVector.push_back( 7 );
myVector.push_back( 19 );
VectorType :: const_iterator itr = myVector.begin ();
while( itr != myVector.end() )
{
std::cout << *itr << std::endl;
++itr;
}
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 38 / 133
Image IteratorsLoops
Nested loops?
for( unsigned int z = 0; z < Nz; z++ )
{
for( unsigned int y = 0; y < Ny; y++ )
{
for( unsigned int x = 0; x < Nx; x++ )
{
image[z][y][x] = ... // pixel access
}
}
}
How to generalize this code to 2D, 3D, 4D, . . . ?
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 39 / 133
Image IteratorsRegion Iterators
ITK Region IteratorMoving Iterator
GoToBegin()
GoToEnd()
IsAtEnd()
IsAtBegin()
++
- -
SetPosition( index )
GetIndex()
Image data access
Get()
Set( value )
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 40 / 133
Image IteratorsRegion Iterators
ITK Region Iterator (const.)
#include "itkImage.h"
#include "itkImageRegionIterator.h"
typedef itk::Image < signed short , 3 > ImageType;
typedef itk:: ImageRegionConstIterator < ImageType > IteratorType;
ImageType :: ConstPointer image = GetConstImageSomeHow ();
ImageType :: RegionType region = image ->GetLargestPossibleRegion ();
IteratorType itr( image , region );
itr.GoToBegin ();
while( !itr.IsAtEnd () )
{
std::cout << itr.Get() << std::endl;
++itr;
}
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 41 / 133
Image IteratorsRegion Iterators
ITK Region Iterator (non-const.)
#include "itkImage.h"
#include "itkImageRegionIterator.h"
typedef itk::Image < signed short , 3 > ImageType;
typedef itk:: ImageRegionIterator < ImageType > IteratorType;
ImageType :: ConstPointer image = GetNonConstImageSomeHow ();
ImageType :: RegionType region = image ->GetLargestPossibleRegion ();
IteratorType itr( image , region );
itr.GoToBegin ();
while( !itr.IsAtEnd () )
{
itr.Set( 0 );
++itr;
}
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 42 / 133
Image IteratorsLinear Iterators
ITK Linear Iterator (with Index)
#include "itkImage.h"
#include "itkImageLinearIteratorWithIndex.h"
typedef itk::Image < signed short , 3 > ImageType;
typedef itk:: ImageLinearConstIteratorWithIndex < ImageType > IteratorType;
ImageType :: ConstPointer image = GetConstImageSomeHow ();
ImageType :: RegionType region = GetImageRegionSomeHow ();
IteratorType itr( image , region );
for( itr.GoToBegin (); !itr.IsAtEnd (); itr.NextLine () )
{
while( !itr.IsAtEndOfLine () )
{
std::cout << itr.Get() << ", " << itr.GetIndex () << std::endl;
// ...
++itr;
}
// ...
}
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 43 / 133
Image IteratorsSlice Iterators
ITK Slice Iterator (with Index)
#include "itkImage.h"
#include "itkImageSliceIteratorWithIndex.h"
typedef itk::Image < signed short , 3 > ImageType;
typedef itk:: ImageSliceConstIteratorWithIndex < ImageType > IteratorType;
ImageType :: ConstPointer image = GetConstImageSomeHow ();
ImageType :: RegionType region = GetImageRegionSomeHow ();
IteratorType itr( image , region );
for( itr.GoToBegin (); !itr.IsAtEnd (); itr.NextSlice () )
{
for( ; !itr.IsAtEndOfSlice (); itr.NextLine () )
{
for( ; !itr.IsAtEndOfLine (); ++itr )
{
std::cout << itr.Get() << ", " << itr.GetIndex () << std::endl;
// ...
}
// ...
}
// ...
}
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 44 / 133
Image IteratorsNeighborhood Iterators
ITK Neighborhood Iterator
Neighborhood
GetRadius()
Size()
GetNeighborhood()
GetIndex()
Image data access
GetPixel( offset )
GetCenterPixel()
GetNext( dir )
GetPrevious( dir )
SetPixel( i, value )
SetCenterPixel( value )
SetNext( dir, value )
SetPrevious ( dir, value )
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 45 / 133
Image IteratorsNeighborhood Iterators
ITK Neighborhood Iterator
#include "itkImage.h"
#include "itkConstNeighborhoodIterator.h"
typedef itk::Image < signed short , 3 > ImageType;
typedef itk:: ConstNeighborhoodIterator < ImageType > IteratorType;
ImageType :: ConstPointer image = GetConstImageSomeHow ();
ImageType :: RegionType region = GetImageRegionSomeHow ();
IteratorType itr( image , region );
itr.GoToBegin ();
while( !itr.IsAtEnd () )
{
for ( int i = 0; i < itr.Size (); i++)
{
value = itr.GetElement( i );
// ...
}
// ...
++itr;
}
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 46 / 133
Image IteratorsIntensity Projections
MIP - Maximum Intensity Projection
leon25.vtk (3D image, slice 87)axial plane OXY
MIP along OZ axis (2D)(projection direction = 2)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 47 / 133
Image IteratorsIntensity Projections
MIP - Maximum Intensity Projection
leon25.vtk (3D image, slice 256)coronal plane OXZ
MIP along OY axis (2D)(projection direction = 1)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 48 / 133
Image IteratorsIntensity Projections
MIP - Maximum Intensity Projection
leon25.vtk (3D, slice 256)sagittal plane OYZ MIP along OX axis (2D)
(projection direction = 0)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 49 / 133
Image IteratorsITK Computer Exercises
C++ Exercises
MIP.zip
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 50 / 133
Filtering
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 51 / 133
FilteringOverview
Thresholding
Intensity Mapping
Edges and Derivatives
Neighborhood Filters
Mathematical Morphology
Logical and Arithmetic Operations
Smoothing
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 52 / 133
FilteringThresholding
Image Histogram
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 53 / 133
FilteringThresholding
Binary Thresholding
The thresholding operation isused to change or identify pixelvalues based on specifying one ormore threshold values.
This filter transforms the inputimage into a binary image.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 54 / 133
FilteringThresholding
Binary Threshold
cthead1.png(UC, 2D)
Tlower = 100Tupper = 255
Tlower = 200Tupper = 255
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 55 / 133
FilteringThresholding
General Thresholding(Threshold Below)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 56 / 133
FilteringThresholding
General Thresholding(Threshold Above)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 57 / 133
FilteringThresholding
General Thresholding(Threshold Outside)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 58 / 133
FilteringThresholding
General Threshold
cthead1.png(UC, 2D)
ThresholdBelowTlower = 100
ThresholdOutsideTlower = 100, Tupper = 200
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 59 / 133
FilteringIntensity Mapping
Intensity Mapping
Used to pixel type-conversions required in the data pipeline
It is up to the user to the user to anticipate the pixel type-conversionsrequired in the data pipeline.
In medical imaging applications it is usually not desirable to use ageneral pixel type, since this may result in the loss of valuableinformation.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 60 / 133
FilteringIntensity Mapping
Linear Intensity Mapping(ITK Filters)
itk::CastImageFilter
itk::RescaleIntensityImageFilter
itk::ShiftScaleImageFilter
itk::NormalizeImageFilter
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 61 / 133
FilteringIntensity Mapping
Non Linear Mapping(sigmoid filter)
the sigmoid filter maps a specific range of intensity values into anew intensity range, by making a very smooth and continuoustransition in the borders of the range.
ITK Implementation: the filter includes 4 parameters that can betuned to select the input and output intensity ranges.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 62 / 133
FilteringIntensity Mapping
Sigmoid Filter(alpha parameter)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 63 / 133
FilteringIntensity Mapping
Sigmoid Filter(beta parameter)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 64 / 133
FilteringIntensity Mapping
Sigmoid
cthead1.png(UC, 2D)
α = 30β = 128
α = −30β = 128
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 65 / 133
FilteringEdges and Derivatives
Edges
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 66 / 133
FilteringEdges and Derivatives
Edges (cont.)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 67 / 133
FilteringEdges and Derivatives
Canny Edge Detection
Widely used for edge detection
Optimal solution satisfying the constraints of:
edge sensitivityedge localizationnoise robustness
This filter operates on image of pixel type float.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 68 / 133
FilteringEdges and Derivatives
Canny Edge Detection
cthead1.png(UC, 2D)
CannyEdgeσ = 1
CannyEdgeσ = 10
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 69 / 133
FilteringEdges and Derivatives
Image Gradient(First Order Derivatives)
Magnitude and direction Approximations
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 70 / 133
FilteringEdges and Derivatives
Image Gradient(Edge Detection Kernels)
Roberts
Prewitt
Sobel
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 71 / 133
FilteringEdges and Derivatives
ITK Gradient Magnitude
ITK computes the magnitude ofthe image gradient at eachpixel location using a simplefinite differences approach:
Equivalent to convolving of theimage with masks . . .
. . . then computing the gradientmagnitude as:
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 72 / 133
FilteringEdges and Derivatives
ITK Gradient Magnitude
cthead1.png(UC, 2D)
gradientmagnitude
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 73 / 133
FilteringEdges and Derivatives
Laplacian Filters(Second Order Derivatives)
Laplacian L (x , y) of an image withpixel intensity values I (x , y)
Discrete convolution kernelsthat can approximate thesecond derivatives:
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 74 / 133
FilteringNeighborhood Filters
Neighborhood FiltersExamples
Mean Filter (local operator)
Median Filter (order filter)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 75 / 133
FilteringNeighborhood Filters
Mean vs Median
cthead1.png(UC, 2D)
meanradius = [1,1]
medianradius = [1,1]
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 76 / 133
FilteringNeighborhood Filters
Mean vs Median
cthead1.png(UC, 2D)
meanradius = [5,5]
medianradius = [5,5]
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 77 / 133
FilteringMathematical Morphology
Mathematical Morphology
Morphological Filters(Binary and Grayscale Image Filters)
DilationErosion
ClosingOpening
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 78 / 133
FilteringMathematical Morphology
Binary Dilation(pipeline)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 79 / 133
FilteringMathematical Morphology
Binary Dilation
binary(UC, 2D)
dilations.e. radius = 1
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 80 / 133
FilteringMathematical Morphology
Binary Closing(pipeline)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 81 / 133
FilteringMathematical Morphology
Binary Closing
binary(UC, 2D)
dilations.e. radius = 1
closings.e. radius = 1
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 82 / 133
FilteringLogical and Arithmetic Operations
Logical and Arithmetic Operations
Logical Operations:
And, Not, . . .
Arithmetic Operations:
Add, Subtract, . . .
Basic Algorithms:
Boundary ExtractionMorphological Gradient
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 83 / 133
FilteringLogical and Arithmetic Operations
Boundary Extraction(pipeline)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 84 / 133
FilteringLogical and Arithmetic Operations
Boundary Extraction
binary(UC, 2D)
boundarys.e. radius = 1
boundarys.e. radius = 5
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 85 / 133
FilteringLogical and Arithmetic Operations
Morphological Gradient(pipeline)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 86 / 133
FilteringLogical and Arithmetic Operations
Morphological Gradient
cthead1.png(UC, 2D)
morphological gradients.e. radius = 1
morphological gradients.e. radius = 5
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 87 / 133
FilteringLogical and Arithmetic Operations
Gradient Magnitude vs Morphological Gradient
cthead1.png(UC, 2D)
gradient magnitude(Sobel)
morphological gradients.e. radius = 1
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 88 / 133
FilteringITK Computer Exercises
C++ Exercises
BinaryThreshold.zip
GeneralThreshold.zip
Sigmoid.zip
Rescale.zip
CannyEdge.zip
GradientMagnitude.zip
Laplacian.zip
Mean.zip
Median.zip
BinaryDilate.zip
BinaryClose.zip
BoundaryExtraction.zip
IJ MorphologicalGradient.zip
IJ LogicalOperationExtra.zip
SmoothingRecursiveGaussian.zip
GradientAnisotropicDiffusion.zip
CurvatureFlow.zip
Bilateral.zip
DerivativeRecursiveGaussian.zip
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 89 / 133
FilteringITK Computer Exercises
Python Exercises
1.BinaryThreshold.py
2.Threshold.py
3.RescaleIntensity.py
4.Sigmoid.py
5.GradientMagnitude.py
6.MeanMedian.py
7.BinaryDilate.py
8.BinaryClose.py
9.BoundaryExtraction.py
10.MorphologicalGradient.py
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 90 / 133
Segmentation
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 91 / 133
SegmentationOverview
Optimal Thresholding
Seeded Region Growing
Connected Component Analysis
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 92 / 133
SegmentationOptimal Thresholding
Optimal Thresholding
Automated selection of optimal threshold value(s), under some criteria, forseparating objects from background by histogram analysis
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 93 / 133
SegmentationOptimal Thresholding
Optimal Thresholding
Local maxima of the histogramcorrespond to objects of interest inthe image scene
Threshold values are best placed atlocal minima of the histogram toseparate such objects
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 94 / 133
SegmentationOptimal Thresholding
Iterative Thresholding(ISODATA Clustering)
iterative unsupervised clusteringmethod
distances between the cluster centersand the members of the cluster areminimized
fixed number of clusters to bedetected must be initially provided
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 95 / 133
SegmentationOptimal Thresholding
Otsu Thresholding
Finds a threshold that classifies the imageinto two clusters such that we minimize thearea under the histogram for one clusterthat lies on the other cluster’s side of thethreshold
minimize the within class variance
maximize the between class varianceof foreground and background pixels
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 96 / 133
SegmentationOptimal Thresholding
Otsu Thresholding
cthead1.png(UC, 2D)
Otsu Threshold: T = 84(rescaled)
NOT filter(rescaled)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 97 / 133
SegmentationOptimal Thresholding
Multiple Otsu Thresholding
cthead1.png(UC, 2D)
Otsu Thresholds:T0 = 73, T1 = 188
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 98 / 133
SegmentationOptimal Thresholding
Robust Thresholding
Fast and noise robust automaticthreshold selection methodbased on gradients in the image
The basic idea is to choose thethreshold at the intensity wherethe gradient are the highest
I = input imageG = gradient of I
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 99 / 133
SegmentationOptimal Thresholding
Robust Thresholding
same method with a power ofthe gradient gives better resultswith noisy images, by giving ahigher weight to the highgradients
m greater than 1,typically 2
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 100 / 133
SegmentationOptimal Thresholding
Robust Thresholding
Gaetan Lehmann, Robust Automatic Threshold Selection – RATS, The InsightJournal, 2006.
J. Kitler, J. Illingworth, and J. Foglein, Threshold Selection based on a SimpleImage Statistic, Computer vision, Graphics and Image Processing, vol. 30, pp.125–147, 1985.
M.H.F. Wilkinson, Optimizing Edge Detectors for Robust Automatic ThresholdSelection: Coping with Edge Curvature and Noise, Graphical Models and ImageProcessing, vol. 60, pp. 385–401, 1998.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 101 / 133
SegmentationSeeded Region Growing
Seeded Region Growing
Neighborhood Iterators
Connected Threshold
Isolated Connected
Confidence Connected
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 102 / 133
SegmentationSeeded Region Growing
Neighborhood Iterators
Pixel Connectivity
Example (NeighborhoodIterators6)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 103 / 133
SegmentationSeeded Region Growing
Image Partition
Limitations of histogram basedsegmentation:
the image histogram does not allow torecover spacial information, but onlypixel intensities or gray-levels
Image segmentation based on thehistogram does not explore the factthat neighbor pixels can have similarintensity values
Alternative:
image partition in sub-regionsR1, R2, ..., RN
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 104 / 133
SegmentationSeeded Region Growing
Image Partition
Conditions:
P(Ri) = property of the pixels that belongto region Ri must satisfy:
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 105 / 133
SegmentationSeeded Region Growing
Seeded Region GrowingAlgorithm
From the image, choose or find initial points (pixels) called seeds, that satisfysome criteria:
e.g. P > T (local maximum)
Join to an existing region, the neighbor pixels that are connected to that region, ifthey satisfy some criteria:
e.g. P > mean(R) − 2
Stop the algorithm if the grow of the existing region is no more possible
Consider the remaining points as new regions, coincident with the connectedregions
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 106 / 133
SegmentationSeeded Region Growing
Seeded Region GrowingExample
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 107 / 133
SegmentationSeeded Region Growing
Connected Threshold
A simple similarity criterion for including connected pixels in the region isbased on their gray level:
”pixels having gray level I(x,y,z) in the same interval receive the same class label”
TL and TU are the lower and upper thresholds that define that interval
The region growing algorithm includes those pixels connected to the seed thatsatisify:
TL 6 I (x , y , z) 6 TU
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 108 / 133
SegmentationSeeded Region Growing
Connected Threshold
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 109 / 133
SegmentationSeeded Region Growing
Connected Threshold
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 110 / 133
SegmentationSeeded Region Growing
Confidence Connected
Criteria based on statistics of the current region may be used
In the simplest case, the algorithm first computes the mean m and standarddeviation σ of values for all the pixels currently included in the region
By providing a factor f to define a range around the mean, neighbor pixels whosevalues fall inside the range are accepted and included in the region:
I (P) ∈ [m − f σ,m + f σ]
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 111 / 133
SegmentationSeeded Region Growing
Confidence Connected
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 112 / 133
SegmentationSeeded Region Growing
Confidence Connected
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 113 / 133
SegmentationSeeded Region Growing
Isolated Connected
Two seeds and a lower threshold TL are provided. The algorithm can beapplied to grow a region connected to the first seed and not connected tothe second one.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 114 / 133
SegmentationSeeded Region Growing
Isolated Connected
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 115 / 133
SegmentationSeeded Region Growing
Seeded Region Growing
Image segmentation using SRG should be performed on smoothedversion of the image.
Like thresholding, region growing is sensitive to noise and is not oftenused alone but within a set of image processing operations.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 116 / 133
SegmentationConnected Component Analysis
Connected Component
Seeded Region Growing
Methods:
SetSeed( index0 )
AddSeed( index1 )
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 117 / 133
SegmentationConnected Component Analysis
Region Labeling
input image(binary)
labeled image(gray)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 118 / 133
SegmentationConnected Component Analysis
Region Labeling
1o scan
if P = 255:
if all visited neighbors of P are 0, then P = new label (1, 2, 3, ...)if only one visited neighbor of P is not 0, then P = this neighborif exist more than one visited neighbor of P not 0, then:
if all neighbors not 0 are equal, then P = this valueif neighbors are different, then:P = one of themConstruct a table of equivalence
2o scan
Choose a unique value for each equivalenceChange all equivalent values to the chosen value
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 119 / 133
SegmentationConnected Component Analysis
Region Labeling
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 120 / 133
SegmentationConnected Component Analysis
Region Labeling
input image(binary)
labeled image(gray)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 121 / 133
SegmentationConnected Component Analysis
Region Labeling(ITK Implementation)
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkConnectedComponentImageFilter.h"
#include "itkRelabelComponentImageFilter.h"
// Define image type and dimension ...
// Instantiate the reader ...
// Create the reader ...
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 122 / 133
SegmentationConnected Component Analysis
Region Labelingtypedef itk:: ConnectedComponentImageFilter <
InputImageType ,
OutputImageType > ConnectedComponentFilterType;
ConnectedComponentFilterType :: Pointer
labeller = ConnectedComponentFilterType ::New();
labeller -> SetInput ( reader -> GetOutput () );
labeller -> Update ();
Object Relabelingtypedef itk:: RelabelComponentImageFilter <
OutputImageType ,
OutputImageType > RelabelComponentType;
RelabelComponentType :: Pointer
relabeller = RelabelComponentType ::New();
relabeller -> SetInput( labeller -> GetOutput () );
relabeller -> Update ();
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 123 / 133
SegmentationConnected Component Analysis
Object Statistics(1 object)
// ...
unsigned long nObjects =
relabeller -> GetNumberOfObjects ();
std::cout << "Number of objects: "
<< nObjects
<< std::endl;
unsigned long sizeOfObject1 =
relabeller -> GetSizeOfObjectsInPixels ()[0];
std::cout << "Size of object 1: "
<< sizeOfObject1
<< "pixels" << std::endl;
// ...
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 124 / 133
SegmentationConnected Component Analysis
Object Statistics(All objects)
// ...
const std::vector < unsigned long > size_pix =
relabeller -> GetSizeOfObjectsInPixels ();
const std::vector < float > size_phys =
relabeller -> GetSizeOfObjectsInPhysicalUnits ();
std::vector < unsigned long >:: const_iterator it1;
std::vector < float >:: const_iterator it2;
int i;
for( i = 0, it1 = size_pix.begin(), it2 = size_phys.begin ();
it1 != size_pix.end ();
++i, ++it1 , ++it2 )
std::cout << "Size of object " << i+1 << ": "
<< (*it1) << " pixels , "
<< (*it2) << " physical units" << std::endl;
// ...
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 125 / 133
SegmentationConnected Component Analysis
Connected Components
cthead1.png(UC, 2D)
binary threshold(TL = 150, TL = 255)
connected components(relabeled objects: 23)
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 126 / 133
SegmentationWatersheds
Watersheds Concepts
The strategy of watershed segmentation is to treat an image I as aheight function
The image f is often not the original input data, but is derived fromthat data through some filtering, feature extraction, or fusion offeature maps from different sources
Assume that higher values of I (or –I ) indicate the presence ofboundaries in the original data.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 127 / 133
SegmentationWatersheds
Watersheds Concepts
Watershed segmentation classifies pixels into regions using gradient descent onimage features and analysis of weak points along region boundaries.
Imagine water raining onto a landscape topology and flowing with gravity tocollect in low basins. The size of those basins will grow with increasing amounts ofprecipitation until they spill into one another, causing small basins to mergetogether into larger basins.
Regions (catchment basins) are formed by using local geometric structure toassociate points in the image domain with local extrema in some featuremeasurement such as curvature or gradient magnitude.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 128 / 133
SegmentationWatersheds
Watersheds
Gradient descent associates regions with localminima of I using the watersheds of the graph of I
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 129 / 133
SegmentationWatersheds
Watersheds
The care with which the data is preprocessed will greatly affect the quality of theresult;
Typically, the best results are obtained by preprocessing the original image with anedge-preserving filter, such as anisotropic diffusion or bilateral image filters;
The height function used as input should be created such that higher positivevalues correspond to object boundaries;
A suitable height function for many applications can be generated as the gradientmagnitude of the image to be segmented.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 130 / 133
SegmentationWatersheds
Watershed
cthead1.png(UC, 2D)
watershed2.0 5 0.01 0.05 1
watershed2.0 5 0.0 0.05 1
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 131 / 133
SegmentationITK Computer Exercises
C++ Exercises
OtsuThreshold.zip
IJ RobustSelection.zip
ConnectedThreshold.zip
ConfidenceConnected.zip
IsolatedConnected.zip
ConnectedComponent.zip
WatershedSegmentation1.zip
Python Exercises
1.OtsuThreshold.py
2.MultipleOtsuThreshold.py
3.ConnectedThreshold.py
4.ConnectedComponent.py
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 132 / 133
Medical Image ProcessingITK Insight Toolkit
End.
(Carlos A. Vinhais) ITK Insight Toolkit March, 2017 133 / 133