6
1 Th is wo rk b y Jo h n Galeo ttian d Damio n Sh elto n, © 200 4-2 01 6,was mad e p o ssible in part b y NI H NLM co ntract# HHSN2 7 6 2 0 10 00 58 0P, an d islicen sed un der a Creative Co mmo ns Attri b ution 3.0 Unp orted Licen se. To view a co p y of this l i cen se, vi si t h ttp ://creati veco mmo n s.o rg/l i cen ses/b y/3 .0 / or sen d a l etter to Creati ve C o mmo n s,1 71 2nd Street, Sui te 300, San Fran cisco , C alifo rn ia, 94 10 5,USA. P ermissio ns beyo n d th e sco pe o fth i s licen se may b e availab le b y emailing itk@galeo tti.net. Th e mo st re ce n t ve rsion of the se slid es may b e acce sse d on lin e via h ttp://itk.gale o tti.ne t/ Lecture 17 ITK Pipeline Methods in Medical Image Analysis - Spring 2016 18-791 (CMU ECE) : 42-735 (CMU BME) : BioE 2630 (Pitt) Dr. John Galeotti Based in part on Shelton’s slides from 2006 1 The Pipeline § ITK is organized around data objects and process objects § You should now be somewhat familiar with the primary data object, § Today we’ll talk about how to do cool things to images, using process objects § A pipeline is a series of process objects that operate on one or more data objects § The data objects “flow” along the pipeline 2 The pipeline idea The pipeline consists of: § Data objects § Process object (things that create data objects) 3 Source Image Filter A Image Filter B Image Start here End here Image sources 4 itk::ImageSource<TOutputImage> The base class for all process objects that produce images without an input image Source Image Filter A Image Filter B Image Start here End here Image to image filters 5 itk::ImageToImageFilter<TInputImage, TOutputImage> The base class for all process objects that produce images when provided with animageasinput. Source Image FilterA Image FilterB Image Start here End here Input and output § ImageSource’s do not require input, so they have only a function § ImageToImageFilter’s have both and functions 6

The Pipeline - cs.cmu.edugaleotti/methods_course/ITK_Pipeline.pdf · pipeline - i.e., what connects to what §This does notcause the pipeline to execute §In order to “run” the

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Pipeline - cs.cmu.edugaleotti/methods_course/ITK_Pipeline.pdf · pipeline - i.e., what connects to what §This does notcause the pipeline to execute §In order to “run” the

1

Th iswo rkb y John Galeo tti and Damion Shel ton,©200 4-2 01 6,wasmadepo ssible inpartb yNIHNLMcontract#HHSN2 7 6 2 0 10 00 58 0P,and i sl i cen sed underaC reativeCommonsAttrib ution 3.0Unported Licen se.To viewacop yof thisl i cen se,vi si th ttp ://creativecommons.o rg/l icen ses/b y/3 .0 /or send a letter to CreativeCommons,1 712nd Street, Sui te300,San Fran cisco ,Cal i fo rn ia,94 10 5,USA. P ermissionsbeyond th escopeo fth is l i cen semayb eavai lab leb yemai l ing i tk@galeo tti .net.The most re ce n tve rsion of the sesl idesmaybe acce sse don lineviah ttp://itk.gale o tti .ne t/

Lecture 17ITKPipeline

MethodsinMedicalImageAnalysis- Spring201618-791(CMUECE):42-735(CMUBME):BioE 2630(Pitt)

Dr.JohnGaleotti

BasedinpartonShelton’s slides from2006

1

ThePipeline

§ ITKisorganizedarounddataobjects andprocessobjects§ Youshouldnowbesomewhatfamiliarwiththeprimarydataobject,

§ Todaywe’lltalkabouthowtodocoolthingstoimages,usingprocessobjects

§Apipeline isaseriesofprocessobjectsthatoperateononeormoredataobjects

§Thedataobjects“flow” alongthepipeline

2

Thepipelineidea

Thepipelineconsistsof:§Dataobjects§ Processobject(thingsthatcreatedataobjects)

3

Source Image FilterA

ImageFilterBImage

Starthere

Endhere

Image sources

4

itk::ImageSource<TOutputImage>Thebaseclassforallprocessobjectsthatproduceimageswithoutaninputimage

Source Image FilterA

ImageFilterBImage

Starthere

Endhere

Image toimagefilters

5

itk::ImageToImageFilter<TInputImage, TOutputImage>

Thebaseclassforallprocessobjectsthatproduceimageswhenprovidedwithanimageasinput.

Source Image FilterA

ImageFilterBImage

Starthere

Endhere

Inputandoutput

§ ImageSource’s donotrequireinput,sotheyhaveonlya function

§ ImageToImageFilter’s havebothand functions

6

Page 2: The Pipeline - cs.cmu.edugaleotti/methods_course/ITK_Pipeline.pdf · pipeline - i.e., what connects to what §This does notcause the pipeline to execute §In order to “run” the

2

Ignoringintermediate images

7

Source Filter ImageFilterStarthere Endhere

=

Source Image FilterA

ImageFilterBImage

Starthere

Endhere

Howthis looksincode

8

Whenexecutionoccurs

§Thepreviouspageofcodeonly setsupthepipeline- i.e.,whatconnectstowhat

§Thisdoesnot causethepipelinetoexecute§ Inorderto“run” thepipeline,youmustcall

onthelastfilterinthepipeline

9

PropagationofUpdate()

§When iscalledonafilter,theupdatepropagatesback“up” thepipelineuntilitreachesaprocessobjectthatdoesnotneedtobeupdated,orthestartofthepipeline

10

When are process objects updated?

§ Iftheinputtotheprocessobjecthaschanged§ Iftheprocessobjectitselfhasbeenmodified-e.g., IchangetheradiusofaGaussianblurfilter

11

Howdoesitknow?

Detecting process objectmodification

§ Theeasyway(whenwritingyourownprocesobject) istouse

which produces thefunction

thatcalls foryouwhenanewvalueissetintheclass.

§ Forexample, thecompiler turns thislineof code:

intoamember function, ,thatsetsmember variable .

12

Page 3: The Pipeline - cs.cmu.edugaleotti/methods_course/ITK_Pipeline.pdf · pipeline - i.e., what connects to what §This does notcause the pipeline to execute §In order to “run” the

3

Process objectmodification, cont.

§TheotherwayistocallModified()fromwithinaprocessobjectfunctionwhenyouknowsomethinghaschanged

§YoucancallModified()fromoutsidetheclassaswell, toforceanupdate

§Usingthemacrosisabetterideathough...

13

Runningthepipeline– Step1

14

Notsure ModifiedUpdated

Modified?Modified?

Source Filter ImageFilterStarthere Endhere

Runningthepipeline– Step2

15

Source Filter ImageFilterStarthere Endhere

Notsure ModifiedUpdated

Runningthepipeline– Step3

16

Source Filter ImageFilterStarthere Endhere

Notsure ModifiedUpdated

Runningthepipeline– Step4

17

Source Filter ImageFilterStarthere Endhere

Notsure ModifiedUpdated

Modifyingthepipeline– Step1

18

Source Filter ImageFilterStarthere Endhere

Changeafilterparameterhere

Thencall here

Notsure ModifiedUpdated

Page 4: The Pipeline - cs.cmu.edugaleotti/methods_course/ITK_Pipeline.pdf · pipeline - i.e., what connects to what §This does notcause the pipeline to execute §In order to “run” the

4

Modifyingthepipeline– Step2

19

Source Filter ImageFilterStarthere Endhere

Wedetectthattheinputismodified

Thisexecutes

Notsure ModifiedUpdated

Modifyingthepipeline– Step3

20

Source Filter ImageFilterStarthere Endhere

Thisexecutes

Notsure ModifiedUpdated

Thoughts on pipelinemodification

§Notethatinthepreviousexamplethesourcenever re-executed;ithadnoinputanditwasnevermodified,sotheoutputcannothavechanged

§Thisisgood!Wecanchangethingsattheendofthepipelinewithoutwastingtimerecomputingthingsatthebeginning

21

It’s easyinpractice

1. Buildapipeline2. Call onthelastfilter- gettheoutput3. Tweaksomeofthefilters4. Call onthelastfilter- gettheoutput5. ...adnauseam

22

Reading&writing

§Youwilloftenbeginandendpipelineswithreadersandwriters

§Fortunately,ITKknowshowtoreadawidevarietyofimagetypes!

23

Readingandwritingimages

§Readimageswith:

§Writeimageswith:

§Bothclasseshaveafunction

usedtooptionally specifyaparticulartypeofimage toreadorwrite

24

Page 5: The Pipeline - cs.cmu.edugaleotti/methods_course/ITK_Pipeline.pdf · pipeline - i.e., what connects to what §This does notcause the pipeline to execute §In order to “run” the

5

Readinganimage(4.1.2)

§Createareader§ Ifyouknowthefileformat(optional):§ Createaninstanceofan derivedclass(e.g. )

§ PasstheIOobjecttothereader§Set thefilenameofthereader§Updatethereader

25

Readernotes

§The templateparameteristhetypeofimageyouwanttoconvertthestoredimageto,notnecessarilythetypeofimagestoredinthefile

§ ITKassumesavalidconversionexistsbetweenthestoredpixeltypeandthetargetpixeltype

26

Writinganimage

§Almostidenticaltothereadercase,butyouusean insteadofareader

§OutputformatcanbespecifiedwithanIOobject(optional)§ Ifyou’vealreadycreatedanIOobjectduringthereadstage,youcanrecycleitforusewiththewriter

27

Moreread/writenotes

§ ITKactuallyhasseveraldifferentwaysofreadingfiles- whatI’vepresentedisthesimplestconceptually

§Remember, youcanreadfileswithoutknowingtheirformata-priori§ Justdon’tspecifyanyIOobjects.

§Manymoredetailsare inch. 7ofthesoftwareguide.

28

SimpleITK Pipeline

Itdoesn’thaveone!

§SimpleITK’s interfacedoesNOTuseapipeline§Every timeyoucallafilterinSimpleITK, itre-executes.

§Youmanuallyexecuteeachfilterevery timeyouthinkitisnecessary

§Youalsomanuallypasstheupdatedoutputfromonefiltertotheinputofthenextfilter

29

CombiningITKandSimpleITK

§YoucancombineITKwithSimpleITK!§Forexample:§UseSimpleITK toquicklyreadandpreprocessimages§Use“full”ITKtoperformacomplexregistration§UseSimpleITK tosavetheresults

§ThisisreallyeasyinC++§WejustneedtointegrateSimpleITK intoourITKpipeline

30

Page 6: The Pipeline - cs.cmu.edugaleotti/methods_course/ITK_Pipeline.pdf · pipeline - i.e., what connects to what §This does notcause the pipeline to execute §In order to “run” the

6

Using SimpleITK inan ITK Pipeline

§ConvertaSimpleITK image intoa“full”ITKimage:

§Converta“full”ITKimageintoaSimpleITK image:

31

Using SimpleITK inan ITK Pipeline

§Warning: Conversion from SimpleITK toITKrequiresmatching image types!§ “Full”ITKhard-codes(viatemplateparameters)eachoutputimage’spixeltypeanddimensionality

§ SimpleITK automaticallymakesdecisionsaboutanoutputimage’spixeltypeanddimensionality

§ ThedefinitivelistofSimpleITK pixeltypesisinitssourcecode,atthebottomofthisfile:

§ Solution:§ Verifythatdimensionsmatch,andthen…§ UseSimpleITK’s toconvertpixeltype§ See

32

Example: ITKwithSimpleITK

33

Example: ITKwithSimpleITK

34

CMakeLists.txt: ITK+SimpleITK

35