1
#=========================================================================
3
# Copyright Insight Software Consortium
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 at
9
# http://www.apache.org/licenses/LICENSE-2.0.txt
11
# Unless required by applicable law or agreed to in writing, software
12
# 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 and
15
# limitations under the License.
17
#=========================================================================
20
if ARGV.length != 3 then
21
puts "Usage: SimpleGaussian <input> <sigma> <output>";
25
## [ruby director command]
26
# Derive a class from SimpleITK Command class to be used to observe
27
# events and report progress.
28
class MyCommand < Simpleitk::Command
30
# Explicit call to supoer class initlaizer is required to
31
# initialize the SWIG director class to enable overloaded methods
36
# The Command method to be executed on the event from the filter.
38
puts "%s Progress: %0.2f" % [@po.get_name, @po.get_progress]
41
## [ruby director command]
43
reader = Simpleitk::ImageFileReader.new
44
reader.set_file_name( ARGV[0] )
45
image = reader.execute
47
inputPixelType = image.get_pixel_idvalue
50
gaussian = Simpleitk::DiscreteGaussianImageFilter.new
51
gaussian.set_variance ARGV[1].to_f
53
# create a new MyCommand class, the references between the objects is
54
# automatically taked care of. The connection will automatically be
55
# removed when either object is deleted.
56
cmd = MyCommand.new gaussian
57
gaussian.add_command Simpleitk::SitkProgressEvent, cmd
59
image = gaussian.execute image
61
caster = Simpleitk::CastImageFilter.new
62
caster.set_output_pixel_type inputPixelType
63
image = caster.execute image
65
writer = Simpleitk::ImageFileWriter.new
66
writer.set_file_name ARGV[2]