1 ITK Lecture 5 Intro to Iterators Methods in Image Analysis CMU Robotics Institute 16-725 U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image.

Slides:



Advertisements
Similar presentations
. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
Advertisements

School of EECS, Peking University “Advanced Compiler Techniques” (Fall 2011) Parallelism & Locality Optimization.
Understanding the Need for Sorting Records
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 4 Images in ITK Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering.
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.
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.
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.
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
1 ITK Lecture 7 - Writing Filters, Part 1 Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods.
Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering.
CS 211 Inheritance AAA.
1 Foundations of Software Design Lecture 3: How Computers Work Marti Hearst Fall 2002.
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
. The Standard C++ Library. 2 Main Ideas Purpose Flexibility Efficiency Simple & Uniform Interface.
CS503: First Lecture, Fall 2008 Michael Barnathan.
CS 1114: Introduction to Computing Using MATLAB and Robotics Prof. Graeme Bailey (notes modified from Noah Snavely, Spring.
R-1 University of Washington Computer Programming I Lecture 17: Multidimensional Arrays © 2000 UW CSE.
C++ for Engineers and Scientists Third Edition
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Yet More Array Practice Lecture 24, Mon Mar
Sorting Algorithms and Analysis Robert Duncan. Refresher on Big-O  O(2^N)Exponential  O(N^2)Quadratic  O(N log N)Linear/Log  O(N)Linear  O(log N)Log.
1 ITK Lecture 4 Images in ITK Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image Analysis.
1 ITK Lecture 2 A brief C++ review Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image.
Simple Sorting Algorithms. 2 Outline We are going to look at three simple sorting techniques: Bubble Sort, Selection Sort, and Insertion Sort We are going.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Sorting. Background As soon as you create a significant database, you’ll probably think of reasons to sort it in various ways. You need to arrange names.
Data Structures Using C++ 2E
Lists in Python.
The content of these slides by John Galeotti, © Carnegie Mellon University (CMU), was made possible in part by NIH NLM contract# HHSN P,
Principles of Programming - NI Simple Recursion Recursion is where a function calls itself. Concept of recursive function: A recursive function is.
NETW3005 File System Interface. Reading For this lecture, you should have read Chapter 10 (Sections 1-5) and Chapter 11 (Sections 1-4). NETW3005 (Operating.
Searching. RHS – SOC 2 Searching A magic trick: –Let a person secretly choose a random number between 1 and 1000 –Announce that you can guess the number.
1 Chapter 3 Arrays (2) 1. Array Referencing 2. Common Operations 1. Slicing 2. Diminution 3. Augmentation 3. List of Commonly Used Built-in Functions 1.
Chapter 7 – End-to-End Data Two main topics Presentation formatting Compression We will go over the main issues in presentation formatting, but not much.
1 ITK Lecture 8 - Neighborhoods Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image.
Software Design 1.1 Tapestry classes -> STL l What’s the difference between tvector and vector  Safety and the kitchen sink What happens with t[21] on.
Methods in Image Analysis 2004, Damion Shelton 1 ITK Lecture 9 - Toolbox Part I Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers.
CSC 211 Data Structures Lecture 13
1 ITK Lecture 9 - Toolbox Part I Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image.
Searching Chapter 18 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
CPS 100, Spring Tools: Solve Computational Problems l Algorithmic techniques  Brute-force/exhaustive, greedy algorithms, dynamic programming,
Clustering Prof. Ramin Zabih
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Homework due Test the random number generator Create a 1D array of n ints Fill the array with random numbers between 0 and 100 Compute and report the average.
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
Matlab tutorial course Lesson 4: Writing your own functions: programming constructs
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
Principles of Programming - NI Simple Recursion Recursion is where a function calls itself. Concept of recursive function: A recursive function is.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Project Wikis will be made public tonight. Presentations week 6 – next week. Slack Chat invites sent.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
1 ITK Lecture 6 - The Pipeline Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image Analysis.
Linked Lists. Introduction In linked list each item is embedded in a link Each item has two parts – Data – Pointer to the next item in the list Insert,
In the news: A recently security study suggests that a computer worm that ran rampant several years ago is still running on many machines, including 50%
Search Algorithms Written by J.J. Shepherd. Sequential Search Examines each element one at a time until the item searched for is found or not found Simplest.
CSE 332: C++ STL iterators What is an Iterator? An iterator must be able to do 2 main things –Point to the start of a range of elements (in a container)
CS 1114: Finding things Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
BMTRY 789 Lecture9: Proc Tabulate Readings – Chapter 11 & Selected SUGI Reading Lab Problems , 11.2 Homework Due Next Week– HW6.
CSE 1301 Lecture 14 2D Arrays Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Intro to Data Structures Concepts ● We've been working with classes and structures to form linked lists – a linked list is an example of something known.
C++ coding standard suggestion… Separate reasoning from action, in every block. Hi, this talk is to suggest a rule (or guideline) to simplify C++ code.
OOP What is problem? Solution? OOP
CISC/CMPE320 - Prof. McLeod
Lecture 16 Images in ITK Methods in Medical Image Analysis - Spring (CMU ECE) : (CMU BME) : BioE 2630 (Pitt) Dr. John Galeotti Based.
Lecture 19 ITK’s Path Framework
Lecture 2- Query Processing (continued)
Presentation transcript:

1 ITK Lecture 5 Intro to Iterators Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006 Methods in Image Analysis CMU Robotics Institute U. Pitt Bioengineering 2630 Spring Term, 2006

2 Ways of accessing pixels  So far we’ve seen two “direct” methods of pixel access  Using an Index object in data space  Using a Point object in physical space  Both of these methods look like typical C++ array access:  myDataArray[x][y][z] = 2;  So far we’ve seen two “direct” methods of pixel access  Using an Index object in data space  Using a Point object in physical space  Both of these methods look like typical C++ array access:  myDataArray[x][y][z] = 2;

3 Why direct access is bad 1… It’s slow: a) Build the index b) Pass the index to the image c) Build a memory address from the index d) Access the pixel 1… It’s slow: a) Build the index b) Pass the index to the image c) Build a memory address from the index d) Access the pixel

4 Direct access = bad, cont. 2… It’s hard to make it N-d: Let’s say I want to do something really simple, like access all of the pixels in an image (any data type, any dimensionality) How would you do this using indices? 2… It’s hard to make it N-d: Let’s say I want to do something really simple, like access all of the pixels in an image (any data type, any dimensionality) How would you do this using indices?

5 N-d access troubles  I’m not sure I have a good answer, you could probably come up with a fairly complicated way of building an index  But, nested for-loops won’t work, because you don’t know ahead of time how many you’ll need  I’m not sure I have a good answer, you could probably come up with a fairly complicated way of building an index  But, nested for-loops won’t work, because you don’t know ahead of time how many you’ll need

6 N-d access troubles, cont. I.e. the following works on 2D images only loop over rows loop over columns build index (row, column) GetPixel(index) end column loop end row loop I.e. the following works on 2D images only loop over rows loop over columns build index (row, column) GetPixel(index) end column loop end row loop

7 Iterators to the rescue  There’s a concept in generic programming called the iterator  It arises from the need to sequentially & efficiently access members of complex data objects  Iterators are not unique to ITK; the Standard Template Library (STL) uses them extensively  There’s a concept in generic programming called the iterator  It arises from the need to sequentially & efficiently access members of complex data objects  Iterators are not unique to ITK; the Standard Template Library (STL) uses them extensively

8 Iterators in ITK  ITK has many types of iterators. There are iterators to traverse:  image regions  neighborhoods  arbitrary functions (“inside” the function)  random pixels in an image  and more…  We’ll be covering several of these in class  ITK has many types of iterators. There are iterators to traverse:  image regions  neighborhoods  arbitrary functions (“inside” the function)  random pixels in an image  and more…  We’ll be covering several of these in class

9 See the software guide  All this and more can be found in Chapter 11 of the ITK Software Guide

10 Good news about iterators Iterators are:  Simple to learn and use, and make your code easier to read (!)  Wrap extremely powerful data access methods in a uniform interface  N-d  Fast Iterators are:  Simple to learn and use, and make your code easier to read (!)  Wrap extremely powerful data access methods in a uniform interface  N-d  Fast

11 An aside: “concepts” in ITK  One of the ways the Doxygen documentation is organized is by concepts  This helps sort classes by similar functionality (concepts) even if they don’t share base classes   Iterators are one of the concepts you can look up  One of the ways the Doxygen documentation is organized is by concepts  This helps sort classes by similar functionality (concepts) even if they don’t share base classes   Iterators are one of the concepts you can look up

12 Image region iterators  The simplest type of iterator lets you traverse an image region  The class is itk::ImageRegionIterator - it requires an image pointer, and a region of the image to traverse  The simplest type of iterator lets you traverse an image region  The class is itk::ImageRegionIterator - it requires an image pointer, and a region of the image to traverse

13 Creating the iterator First, we assume we have or can get an image ImageType::Pointer im = GetAnImageSomeHow(); Next, create the iterator typedef itk::ImageRegionIterator ItType; ItType it( im, im->GetRequestedRegion() ); Finally, move the iterator to the start of the image it.GoToBegin(); First, we assume we have or can get an image ImageType::Pointer im = GetAnImageSomeHow(); Next, create the iterator typedef itk::ImageRegionIterator ItType; ItType it( im, im->GetRequestedRegion() ); Finally, move the iterator to the start of the image it.GoToBegin();

14 Using the iterator Loop until we reach the end of the image, and set all of the pixels to 10 while( !it.IsAtEnd() ) { it.Set( 10 ); ++it; } Loop until we reach the end of the image, and set all of the pixels to 10 while( !it.IsAtEnd() ) { it.Set( 10 ); ++it; }

15 More compact notation We can skip the explicit “move to beginning” stage and write the following: for (it = it.Begin(); !it.IsAtEnd(); ++it) { it.Set( 10 ); } We can skip the explicit “move to beginning” stage and write the following: for (it = it.Begin(); !it.IsAtEnd(); ++it) { it.Set( 10 ); }

16 Image regions We initialized the iterator with: ItType it( im, im->GetRequestedRegion() ); Note that the region can be anything - pick your favorite image region (using the requested region is common in filters). We initialized the iterator with: ItType it( im, im->GetRequestedRegion() ); Note that the region can be anything - pick your favorite image region (using the requested region is common in filters).

17 Other iterator tricks  Access the pixel with Get()  Figure out the Index of the pixel with GetIndex()  Get a reference to a pixel with Value() - a somewhat faster operation than Get()  Access the pixel with Get()  Figure out the Index of the pixel with GetIndex()  Get a reference to a pixel with Value() - a somewhat faster operation than Get()

18 Iterator tricks, cont.  Moving forwards and backwards  Increment with ++  Decrement with --  Beginning/ending navigation:  GoToBegin()  GoToEnd()  IsAtBegin()  IsAtEnd()  Moving forwards and backwards  Increment with ++  Decrement with --  Beginning/ending navigation:  GoToBegin()  GoToEnd()  IsAtBegin()  IsAtEnd()

19 Const vs. non-const iterators  You will notice that most iterators have both const and non-const versions  Const iterators do not allow you to set pixel values (much like const functions don’t allow you to change class member values)  In general, the non-const versions of each iterator derive from the const  You will notice that most iterators have both const and non-const versions  Const iterators do not allow you to set pixel values (much like const functions don’t allow you to change class member values)  In general, the non-const versions of each iterator derive from the const

20 Const vs. non-const, cont.  Good programming technique is to enforce const access when you don’t intend to change data  Moreover, input images in ITK filters are const, so you can’t traverse them using non-const iterators  Why? It’s very important to not accidentally modify the input to a filter!  Good programming technique is to enforce const access when you don’t intend to change data  Moreover, input images in ITK filters are const, so you can’t traverse them using non-const iterators  Why? It’s very important to not accidentally modify the input to a filter!

21 Problems with iterating regions  It’s not easy to know “who” your neighbors are, which is often important  You don’t have much control over how the iteration proceeds (why?)  Fortunately, there are solutions to both of these problems… stay tuned  It’s not easy to know “who” your neighbors are, which is often important  You don’t have much control over how the iteration proceeds (why?)  Fortunately, there are solutions to both of these problems… stay tuned