How to use iType method in fMBT

Best Python code snippet using fMBT_python

module2module.py

Source:module2module.py Github

copy

Full Screen

1#==========================================================================2#3# Copyright Insight Software Consortium4#5# Licensed under the Apache License, Version 2.0 (the "License");6# you may not use this file except in compliance with the License.7# You may obtain a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.0.txt10#11# Unless required by applicable law or agreed to in writing, software12# distributed under the License is distributed on an "AS IS" BASIS,13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14# See the License for the specific language governing permissions and15# limitations under the License.16#17#==========================================================================*/18# def custom_callback(name):19# print "loading %s submodule..." % name20# import itkConfig21# itkConfig.ImportCallback = custom_callback22import itk, sys23import ITKCommon24import ITKBinaryMathematicalMorphology25import ITKImageStatistics26import ITKSmoothing27import ITKDistanceMap28import ITKImageIntensity29import ITKIOImageBase30import ITKThresholding31import ITKImageGrid32PType = itk.UC33dim = 234IType = itk.Image[PType, dim]35kernel = itk.strel(2, 1)36# create the reader37reader = itk.ImageFileReader[IType].New(FileName=sys.argv[1])38sources = []39image = ITKCommon.Image[PType, dim].New()40r = itk.ImageRegion._2()41r.SetSize((10, 10))42image.SetRegions(r)43image.Allocate()44sources.append(("ITKCommon", image))45sources.append(("ITKIOImageBase", reader.GetOutput()))46otsu = ITKThresholding.OtsuThresholdImageFilter[IType, IType].New(reader)47sources.append(("ITKThresholding", otsu.GetOutput()))48flip = ITKImageGrid.FlipImageFilter[IType].New(reader)49sources.append(("ITKImageGrid", flip.GetOutput()))50abs = ITKImageIntensity.AbsImageFilter[IType, IType].New(reader)51sources.append(("ITKImageIntensity", abs.GetOutput()))52bdilate = ITKBinaryMathematicalMorphology.BinaryDilateImageFilter[IType, IType, kernel].New(reader, Kernel=kernel)53sources.append(("ITKBinaryMathematicalMorphology", bdilate.GetOutput()))54minmax = ITKImageStatistics.MinimumMaximumImageFilter[IType].New(reader)55sources.append(("ITKImageStatistics", minmax.GetOutput()))56median = ITKSmoothing.MedianImageFilter[IType, IType].New(reader)57sources.append(("ITKSmoothing", median.GetOutput()))58distance = ITKDistanceMap.DanielssonDistanceMapImageFilter[IType, IType].New(reader)59sources.append(("ITKDistanceMap", distance.GetOutput()))60# sobel = EdgesAndContours.SobelEdgeDetectionImageFilter[IType, IType].New(reader)61# sources.append(("EdgesAndContours", sobel.GetOutput()))62# laplacian = Filtering.LaplacianImageFilter[IType, IType].New(reader)63# sources.append(("Filtering", laplacian.GetOutput()))64dests = []65dotsu = ITKThresholding.OtsuThresholdImageFilter[IType, IType].New(reader)66dests.append(("ITKThresholding", dotsu))67dflip = ITKImageGrid.FlipImageFilter[IType].New()68dests.append(("ITKImageGrid", dflip))69dabs = ITKImageIntensity.AbsImageFilter[IType, IType].New()70dests.append(("ITKImageIntensity", dabs))71dbdilate = ITKBinaryMathematicalMorphology.BinaryDilateImageFilter[IType, IType, kernel].New(Kernel=kernel)72dests.append(("ITKBinaryMathematicalMorphology", dbdilate))73dminmax = ITKImageStatistics.MinimumMaximumImageFilter[IType].New()74dests.append(("ITKImageStatistics", dminmax))75dmedian = ITKSmoothing.MedianImageFilter[IType, IType].New()76dests.append(("ITKSmoothing", dmedian))77ddistance = ITKDistanceMap.DanielssonDistanceMapImageFilter[IType, IType].New()78dests.append(("ITKDistanceMap", ddistance))79# dsobel = EdgesAndContours.SobelEdgeDetectionImageFilter[IType, IType].New()80# dests.append(("EdgesAndContours", dsobel))81# dlaplacian = Filtering.LaplacianImageFilter[IType, IType].New()82# dests.append(("Filtering", dlaplacian))83writer = ITKIOImageBase.ImageFileWriter[IType].New(FileName='out.png')84dests.append(("ITKIOImageBase", writer))85nb = 086failList = []87for sname, s in sources:88 for dname, d in dests:89 nb += 190 d.SetInput( s )91 try:92 d.Update()93 print "%s -> %s pass" % (sname, dname)94 except RuntimeError, e:95 print "%s -> %s fail" % (sname, dname)96 failList.append((sname, dname))97print98print "%i tests succeed" % (nb - len(failList))99print "%i tests failed" % len(failList)...

Full Screen

Full Screen

template.py

Source:template.py Github

copy

Full Screen

1#==========================================================================2#3# Copyright Insight Software Consortium4#5# Licensed under the Apache License, Version 2.0 (the "License");6# you may not use this file except in compliance with the License.7# You may obtain a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.0.txt10#11# Unless required by applicable law or agreed to in writing, software12# distributed under the License is distributed on an "AS IS" BASIS,13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14# See the License for the specific language governing permissions and15# limitations under the License.16#17#==========================================================================*/18import itk19dim = 220PType = itk.UC21# check the repr string22assert "<itkTemplate itk::Image>" == repr(itk.Image)23# template should work with CType instance and with numbers24IType = itk.Image[PType, dim]25# template should return the same class with a class as parameter26# or with an object of this class, and should also be the same27# with the attribute28# create instances of image for the next tests29im = IType.New()30im2 = IType.New()31readerType = itk.ImageFileReader[IType]32readerType2 = itk.ImageFileReader[im]33readerType3 = itk.ImageFileReader.IUC234assert readerType == readerType2 == readerType335# we should be able to get the template and its parameters from the class36(tpl, parameters) = itk.template( IType )37assert tpl == itk.Image38assert parameters == (PType, dim)39# the template must raise a KeyError exception if the template parameter40# is unknown41try :42 itk.ImageFileReader['unknown parameter']43 raise Exception('no exception sent for unknown parameter')44except KeyError:45 pass46# TODO: test the rest of the dict interface47# TODO: test __eq__, __ne__ and __hash__48# something else ?49# now test the New method50# without parameter51reader = readerType.New()52reader2 = readerType.New()53# with an attribute parameter54reader = readerType.New(FileName='test.png')55assert reader.GetFileName() == 'test.png'56# wwith a wrong attribute name57try :58 reader = readerType.New(WrongName='test.png')59 raise Exception('no exception sent for wrong attribute name')60except AttributeError:61 pass62# wwith a wrong attribute type63try :64 reader = readerType.New(FileName=1)65 raise Exception('no exception sent for wrong attribute type')66except :67 pass68# pass filter as argument for input69# to a filter with SetInput method70median = itk.MedianImageFilter[IType, IType].New(reader)71assert reader.GetOutput() == median.GetInput()72# to a filter with a SetImage method73calculator = itk.MinimumMaximumImageCalculator[IType].New(reader)74# not GetImage() method here to verify it's the right image75# to a filter with several inputs76sub = itk.SubtractImageFilter[IType, IType, IType].New(reader, reader2)77assert reader.GetOutput() == sub.GetInput(0)78assert reader2.GetOutput() == sub.GetInput(1)79# pass image as argument for input80# to a filter with SetInput method81median = itk.MedianImageFilter[IType, IType].New(im)82assert im == median.GetInput()83# to a filter with a SetImage method84calculator = itk.MinimumMaximumImageCalculator[IType].New(im)85# not GetImage() method here to verify it's the right image86# to a filter with several inputs87sub = itk.SubtractImageFilter[IType, IType, IType].New(im, im2)88assert im == sub.GetInput(0)89assert im2 == sub.GetInput(1)90# pass invalid input91try:92 itk.MedianImageFilter[IType, IType].New(1)93 raise Exception('no exception sent for wrong input type')94except:95 pass96try:97 itk.SubtractImageFilter[IType, IType, IType].New(im, "wrong")98 raise Exception('no exception sent for wrong 2nd input type')99except TypeError:100 pass101# pass both input and attribute102recons = itk.ReconstructionByDilationImageFilter[IType, IType].New(reader.GetOutput(), im, FullyConnected=True)103assert reader.GetOutput() == recons.GetInput(0)104assert im == recons.GetInput(1)105assert recons.GetFullyConnected() == True106# pass input to object which do not take one107try:108 IType.New(im)109 raise Exception('no exception sent for object without input')110except AttributeError:111 pass112# TODO: test auto_progress113# but how ?...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful