Transcript
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


Top Related