In [1]:
import matplotlib.pyplot as plt
%matplotlib inline
import SimpleITK as sitk
print( sitk.Version() )
# Download data to work on
from downloaddata import fetch_midas_data as fdata
from myshow import myshow
from __future__ import print_function
In [2]:
img = sitk.Image(100,100, sitk.sitkUInt8)
In [3]:
ctFilter = sitk.ConnectedThresholdImageFilter()
ctFilter.SetSeed([0,0])
ctFilter.SetUpper(1)
ctFilter.SetLower(0)
ctFilter.AddCommand(sitk.sitkProgressEvent, lambda: print("\rProgress: {0:03.1f}%...".format(100*ctFilter.GetProgress())))
Out[3]:
Demonstrate reporting of Progress
In [4]:
ctFilter.Execute(img)
Out[4]:
In [5]:
img = sitk.Image(100,100,100,sitk.sitkFloat32)
img = sitk.AdditiveGaussianNoise(img)
myshow(img)
radius = [3,3,3]
In [6]:
%timeit -n 1 sitk.Median(img,radius=radius)
In [7]:
%timeit -n 1 sitk.FastApproximateRank(img, rank=0.5, radius=radius)
In [8]:
%timeit -n 1 sitk.Rank(img, rank=0.5, radius=radius)
In [9]:
%timeit -n 1 sitk.Mean(img,radius=radius)
In [10]:
img = sitk.ReadImage(fdata("cthead1.png"))
myshow(img)
# First create a simple binary image (0 and 1s) for the common cthead1.png test data set
bimg = img >100
myshow(bimg)
Visually show that for binary images the output will be the same.
In [11]:
myshow(sitk.BinaryDilate(bimg, radius, sitk.sitkBall), title="BinaryDilate")
myshow(sitk.GrayscaleDilate(bimg, radius, sitk.sitkBall), title="GrayscaleDilate")
Breifly show that there is a performance difference. These images are only 2D an small to it may not be very accurate, but the filters use different algoritms and the GrayscaleDilate changes which algorithm based on the structuring element.
In [12]:
%timeit -n 100 sitk.BinaryDilate(bimg, 10, sitk.sitkBall)
%timeit -n 100 sitk.GrayscaleDilate(bimg, 10, sitk.sitkBall)
In [13]:
%timeit -n 100 sitk.BinaryDilate(bimg, 10, sitk.sitkBox)
%timeit -n 100 sitk.GrayscaleDilate(bimg, 10, sitk.sitkBox)
In [ ]: