This work by John Galeotti and Damion Shelton, © 2004-2015, was made possible in part by NIH NLM contract# HHSN276201000580P, and is licensed under a Creative.

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

AP STUDY SESSION 2.
1
1 Vorlesung Informatik 2 Algorithmen und Datenstrukturen (Parallel Algorithms) Robin Pomplun.
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 3 CPUs.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
1 Hyades Command Routing Message flow and data translation.
David Burdett May 11, 2004 Package Binding for WS CDL.
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Custom Statutory Programs Chapter 3. Customary Statutory Programs and Titles 3-2 Objectives Add Local Statutory Programs Create Customer Application For.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt BlendsDigraphsShort.
Chapter 6 File Systems 6.1 Files 6.2 Directories
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
Photo Slideshow Instructions (delete before presenting or this page will show when slideshow loops) 1.Set PowerPoint to work in Outline. View/Normal click.
Solve Multi-step Equations
Break Time Remaining 10:00.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
PP Test Review Sections 6-1 to 6-6
Chapter 17 Linked Lists.
Bright Futures Guidelines Priorities and Screening Tables
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
Project Management from Simple to Complex
CS 6143 COMPUTER ARCHITECTURE II SPRING 2014 ACM Principles and Practice of Parallel Programming, PPoPP, 2006 Panel Presentations Parallel Processing is.
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
Chapter 6 File Systems 6.1 Files 6.2 Directories
How to convert a left linear grammar to a right linear grammar
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
1 RA III - Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Buenos Aires, Argentina, 25 – 27 October 2006 Status of observing programmes in RA.
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
Jim Haywood (Product Manager for Statutory Returns) Adopted from Care - Spring Release 2014.
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
Adding Up In Chunks.
Copyright © 2013 by John Wiley & Sons. All rights reserved. HOW TO CREATE LINKED LISTS FROM SCRATCH CHAPTER Slides by Rick Giles 16 Only Linked List Part.
The content of these slides by John Galeotti, © 2013 Carnegie Mellon University (CMU), was made possible in part by NIH NLM contract# HHSN P,
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
Subtraction: Adding UP
Datorteknik TopologicalSort bild 1 To verify the structure Easy to hook together combinationals and flip-flops Harder to make it do what you want.
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
Analyzing Genes and Genomes
Speak Up for Safety Dr. Susan Strauss Harassment & Bullying Consultant November 9, 2012.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Converting a Fraction to %
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Datorteknik TopologicalSort bild 1 To verify the structure Easy to hook together combinationals and flip-flops Harder to make it do what you want.
Immunobiology: The Immune System in Health & Disease Sixth Edition
Physics for Scientists & Engineers, 3rd Edition
Energy Generation in Mitochondria and Chlorplasts
Murach’s OS/390 and z/OS JCLChapter 16, Slide 1 © 2002, Mike Murach & Associates, Inc.
This work by John Galeotti and Damion Shelton, © , was made possible in part by NIH NLM contract# HHSN P, and is licensed under a Creative.
1 ITK Lecture 7 - Writing Filters, Part 1 Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods.
This work by John Galeotti and Damion Shelton, © , was made possible in part by NIH NLM contract# HHSN P, and is licensed under a Creative.
The content of these slides by John Galeotti, © Carnegie Mellon University (CMU), was made possible in part by NIH NLM contract# HHSN P,
The content of these slides by John Galeotti, © Carnegie Mellon University (CMU), was made possible in part by NIH NLM contract# HHSN P,
The content of these slides by John Galeotti, © Carnegie Mellon University (CMU), was made possible in part by NIH NLM contract# HHSN P,
1 ITK Lecture 8 - Neighborhoods Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image.
The content of these slides by John Galeotti, © Carnegie Mellon University (CMU), was made possible in part by NIH NLM contract# HHSN P,
Lecture 19 ITK Filters: How to Write Them
Presentation transcript:

This work by John Galeotti and Damion Shelton, © , was made possible in part by NIH NLM contract# HHSN P, and is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit or send a letter to Creative Commons, 171 2nd Street, Suite 300, San Francisco, California, 94105, USA. Permissions beyond the scope of this license may be available by ing Commons Attribution 3.0 Unported License The most recent version of these slides may be accessed online via Lecture 19 ITK Filters: How to Write Them Methods in Medical Image Analysis - Spring 2015 BioE 2630 (Pitt) : (CMU RI) (CMU ECE) : (CMU BME) Dr. John Galeotti Based on Shelton’s slides from

Where we are  You should understand  What the pipeline is and how to connect filters together to perform sequential processing  How to move through images using iterators  How to access specific pixels based on their location in data space or physical space 2

What we ’ ll cover  How to write your own filter that can fit into the pipeline  For reference, read Chapters 6 & 8 from book 1 of the ITK Software Guide 3

Is it hard or easy?  Writing filters can be really, really easy  But, it can also be tricky at times  Remember, don’t panic! 4

“Cheat” as much as possible!  Never, ever, ever, write a filter from scratch  Unless you’re doing something really odd, find a filter close to what you want and work from there  Recycling the general framework will save you a lot of time and reduce errors 5

Much of the filter is already written 6

The simple case 7

The header - stuff that’s “always there” 8

The header cont. 9

More header code 10

Pay attention to... 11

Does this seem complex?  That’s why I suggested always starting with an existing class  You may want to use find and replace to change the class name and edit from there  Moving on to the.hxx file... 12

The constructor  In BinomialBlurImageFilter, the constructor doesn’t do much  Initialize the member variable 13

GenerateData() 14

Accessing the input and output 15 Filters can have multiple inputs or outputs, in this case we only have one of each

Allocating the output image 16

The meat of GenerateData() 17

PrintSelf 18

PrintSelf, cont. 19

Questions?  How can we make multithreaded filters?  What if the input and output images are not the same size? E.g., convolution edge effects, subsampling, etc.  What about requested regions? 20 We’ll address these questions when we discuss advanced filters

Another Question for Today How do I deal with neighborhoods in N-Dimensions… Such as for convolution? 21

Neighborhoods in ITK  An ITK neighborhood can be any collection of pixels that have a fixed relationship to the “center” based on offsets in data space.  Not limited to the max- or min-connected immediately neighboring pixels!  See 6.4 in the ITK Software Guide, book 1 22

Neighborhoods in ITK, cont.  In general, the neighborhood is not completely arbitrary  Neighborhoods are rectangular, defined by a “radius” in N-dimensions  ShapedNeighborhoods are more arbitrary, defined by a list of offsets from the center  The first form is most useful for mathematical morphology kinds of operations, convolution, etc. 23

Neighborhood iterators  The cool & useful thing about neighborhoods is that they can be used with neighborhood iterators to allow efficient access to pixels “around” a target pixel in an image 24

Neighborhood iterators  Remember that I said access via pixel indices was slow?  Get current index = I  Upper left pixel index I UL = I - (1,1)  Get pixel at index I UL  Neighborhood iterators solve this problem by doing pointer arithmetic based on offsets 25

Neighborhood layout  Neighborhoods have one primary vector parameter, their “radius” in N-dimensions  The side length along a particular dimension i is 2*radius i + 1  Note that the side length is always odd because the center pixel always exists 26

A 3x5 neighborhood in 2D

Stride  Neighborhoods have another parameter called stride which is the spacing (in data space) along a particular axis between adjacent pixels in the neighborhood  In the previous numbering scheme, stride in Y is amount then index value changes when you move in Y  In our example, Stride x = 1, Stride y = 5 28

Neighborhood pixel access  The lexicographic numbering on the previous diagram is important!  It’s ND  It’s how you index (access) that particular pixel when using a neighborhood iterator  This will be clarified in a few slides... 29

NeighborhoodIterator access  Neighborhood iterators are created using:  The radius of the neighborhood  The image that will be traversed  The region of the image to be traversed  Their syntax largely follows that of other iterators (++, IsAtEnd(), etc.) 30

Neighborhood pixel access, cont Let’s say there’s some region of an image that has the following pixel values

Pixel access, cont.  Now assume that we place the neighborhood iterator over this region and start accessing pixels  What happens? 32

Pixel access, cont lexicographic index within neighborhood Intensity of currently underlying pixel in the image

Pixel access, cont. 34

Pixel access, cont

Pixel access, cont

The ++ method  In Image-Region Iterators, the ++ method moves the focus of the iterator on a per pixel basis  In Neighborhood Iterators, the ++ method moves the center pixel of the neighborhood and therefore implicitly shifts the entire neighborhood 37

An aside: “regular” iterators  Regular ITK Iterators are also lexicographic  That is how they, too, are ND  The stride parameters are for the entire image  Conceptual parallel between:  ITK mapping a neighborhood to an image pixel in an image  Lexicographically unwinding a kernel for an image  The linear pointer arithmetic is very fast!  Remember, all images are stored linearly in RAM 38

Convolution (ahem, correlation)! To do correlation we need 3 things: 1.A kernel 2.A way to access a region of an image the same size as the kernel 3.A way to compute the inner product between the kernel and the image region 39

Item 1 - the kernel 40

Item 2 - image access method  We already showed that this is possible using the neighborhood iterator  Just be careful setting it up so that it’s the same size as your kernel 41

Item 3 - inner product method 42

Good to go? 1.Create an interesting operator to form a kernel 2.Move a neighborhood through an image 3.Compute the IP of the operator and the neighborhood at each pixel in the image Voila – correlation in N-dimensions 43

Inner product example itk::NeighborhoodInnerProduct IP; itk::DerivativeOperator<TPixel, ImageType::ImageDimension> operator ; operator->SetOrder(1); operator->SetDirection(0); operator->CreateDirectional(); itk::NeighborhoodIterator iterator( operator->GetRadius(), myImage, myImage->GetRequestedRegion() ); 44

Inner product example, cont. iterator.SetToBegin(); while ( ! iterator. IsAtEnd () ) { std::cout << "Derivative at index " << iterator.GetIndex () << " is " << IP(iterator, operator) << std::endl; ++iterator; } 45

Note  No explicit reference to dimensionality in neighborhood iterator  Therefore easy to make N-d 46

This suggests a filter... 47

Your arch-nemesis… image boundaries  One obvious problem with inner product techniques is what to do when you reach the edge of your image  Is the operation undefined?  Does the image wrap?  Should we assume the rest of the world is empty/full/something else? 48

ImageBoundaryCondition 49

ConstantBoundaryCondition  The rest of the world is filled with some constant value of your choice  The default is 0  Be careful with the value you choose - you can (for example) detect edges that aren’t really there 50

PeriodicBoundaryCondition  The image wraps, so that if I exceed the length of a particular axis, I wrap back to 0 and start over again  If you enjoy headaches, imagine this in 3D  This isn’t a bad idea, but most medical images are not actually periodic 51

ZeroFluxNeumannBoundaryCondition  This is the default boundary condition  Simply returns the closest in-bounds pixel value to the requested out-of-bounds location.  Important result: the first derivative across the boundary is zero.  Thermodynamic motivation  Useful for solving certain classes of diff. eq. 52

Using boundary conditions 53

Last Major Question (for today, anyway) How do I do math with different pixel types… 54

Answer: numeric traits  Provide various bits of numerical information about arbitrary pixel types.  Usage scenario:  “What is the max value of the current pixel type?”  Need to know these things at compile time, but templated pixel types make this hard.  Numeric traits provide answers that are “filled in” at compilation for our pixel type. 55

itk::NumericTraits 56

Using traits 57 Get used to coding like this!

Excerpt from pleOperations/NumericTraits #include "itkNumericTraits.h” //... std::cout ::min() << std::endl; std::cout ::max() << std::endl; std::cout ::Zero << std::endl; std::cout ::ZeroValue() << std::endl; std::cout ::IsNegative(-1) << std::endl; std::cout ::IsNegative(1) << std::endl; std::cout ::One << std::endl; std::cout ::epsilon() << std::endl; std::cout ::infinity() << std::endl; //... 58