methods in image analysis 2004, damion shelton 1 itk lecture 6 - the pipeline methods in image...

28
Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering 2630 Spring Term, 2004 Damion Shelton

Upload: barrie-harper

Post on 17-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

1

ITK Lecture 6 - The Pipeline

Methods in Image Analysis

CMU Robotics Institute 16-725

U. Pitt Bioengineering 2630

Spring Term, 2004

Damion Shelton

Page 2: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

2

What’s a pipeline?

• You may recall that ITK is organized around data objects and process objects

• You should now be somewhat familiar with the primary data object, itk::Image

• Today we’ll talk about how to do cool things to images, using process objects

Page 3: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

3

The pipeline idea

Source Image Filter

ImageFilterImage

Start here

End here

The pipeline consists of data objects, and thingsthat create data objects (i.e. process objects).

Page 4: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

4

Image sources

itk::ImageSource<TOutputImage>The base class for all process objects thatproduce images without an input image

Source Image Filter

ImageFilterImage

Start here

End here

Page 5: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

5

Image to image filters

itk::ImageToImageFilter<TInputImage, TOutputImage>The base class for all process objects that produce imageswhen provided with an image as input.

Source Image Filter

ImageFilterImage

Start here

End here

Page 6: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

6

Input and output

• ImageSource’s do not require input, so they have only a GetOutput() function

• ImageToImageFilter’s have both SetInput() and GetOutput() functions

Page 7: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

7

Ignoring intermediate images

Source Image Filter

ImageFilterImage

Start here

End here

Source Filter ImageFilter

Start here End here

=

Page 8: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

8

How this looks in code

SrcType::Pointer src = SrcType::New();

FilAType::Pointer filterA = FilAType::New();

FilBType::Pointer filterB = FilBType::New();

src->SetupTheSource();

filterA->SetInput( src->GetOutput() );

filterB->SetInput( filterA->GetOutput() );

ImageType::Pointer im = filterB->GetOutput();

Page 9: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

9

When execution occurs

• The previous page of code only sets up the pipeline - i.e., what connects to what

• This does not cause the pipeline to execute

• In order to “run” the pipeline, you must call Update() on the last filter in the pipeline

Page 10: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

10

Propagation of Update()

• When Update() is called on a filter, the update propagates back “up” the pipeline until it reaches a process object that does not need to be updated, or the start of the pipeline

Page 11: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

11

When are process objects updated?

• If the input to the process object has changed

• If the process object itself has been modified - e.g., I change the radius of a Gaussian blur filter

How does it know?

Page 12: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

12

Detecting process object modification

The easy way is to useitkSetMacro(MemberName, type);

which produces the functionvoid SetMemberName(type);

that calls Modified() for you when a new value is set in the class.

For example:itkSetMacro(DistanceMin, double);

sets member variable m_DistanceMin

Page 13: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

13

Process object modification, cont.

• The other way is to call Modified() from within a process object function when you know something has changed

this->Modified();

• You can call Modified() from outside the class as well, to force an update

• Using the macros is a better idea though...

Page 14: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

14

Running the pipeline - Step 1

Not sure Modified

Source Filter ImageFilter

Start here End here

Updated

Update()Modified?Modified?

Page 15: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

15

Running the pipeline - Step 2

Not sure Modified

Source Filter ImageFilter

Start here End here

Updated

Page 16: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

16

Running the pipeline - Step 3

Not sure

Updated

Modified

Source Filter ImageFilter

Start here End here

Page 17: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

17

Running the pipeline - Step 4

Not sure

Updated

Modified

Source Filter ImageFilter

Start here End here

Page 18: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

18

Modifying the pipeline - Step 1

Not sure

Updated

Modified

Source Filter ImageFilter

Start here End here

Change a filter parameter here

Call Update() here

Page 19: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

19

Modifying the pipeline - Step 2

Not sure

Updated

Modified

Source Filter ImageFilter

Start here End here

We detect that the input is modified

This executes

Page 20: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

20

Modifying the pipeline - Step 3

Not sure

Updated

Modified

Source Filter ImageFilter

Start here End hereThis executes

Page 21: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

21

Thoughts on pipeline modification

• Note that in the previous example the source never re-executed; it had no input and it was never modified, so the output cannot have changed

• This is good! We can change things at the end of the pipeline without wasting time recomputing things at the beginning

Page 22: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

22

It’s easy in practice

1. Build a pipeline

2. Call Update() on the last filter - get the output

3. Tweak some of the filters

4. Call Update() on the last filter - get the output

5. ...ad nauseam

Page 23: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

23

Reading & writing

• You will often begin and end pipelines with readers and writers

• Fortunately, ITK knows how to read a wide variety of image types!

Page 24: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

24

Reading and writing images

• Use itk::ImageFileReader<ImageType> to read images

• Use itk::ImageFileWriter<ImageType> to write images

• Both classes have a SetImageIO(ImageIOBase*) function used to specify a particular type of image to read or write

Page 25: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

25

Reading an image (4.1.2)

• Create a reader

• Create an instance of an ImageIOBase derived class (e.g. PNGImageIO)

• Pass the IO object to the reader

• Set the file name of the reader

• Update the reader

Page 26: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

26

Reader notes

• The ImageType template parameter is the type of image you want to convert the stored image to, not necessarily the type of image stored in the file

• ITK assumes a valid conversion exists between the stored pixel type and the target pixel type

Page 27: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

27

Writing an image

• Almost identical to the reader case, but you use an ImageFileWriter instead of a reader

• If you’ve already created an IO object during the read stage, you can recycle it for use with the writer

Page 28: Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering

Methods in Image Analysis 2004, Damion Shelton

28

More read/write notes

• ITK actually has several different ways of reading files - what I’ve presented is the simplest conceptually

• Other methods exist to let you read files without knowing their format