Example #1
0
    InputImageType, OutputImageType, RealOutputPixelType]
GPUNeighborhoodFilterType = itk.GPUNeighborhoodOperatorImageFilter[
    InputGPUImageType, OutputGPUImageType, RealOutputPixelType]

# Create 1D Gaussian operator
OperatorType = itk.GaussianOperator[RealOutputPixelType, Dimension]

oper = OperatorType()
oper.SetDirection(0)
oper.SetVariance(8.0)
oper.CreateDirectional()

# test 1~8 work units for CPU
for number_of_work_units in range(1, 9):
    cpu_filter = NeighborhoodFilterType.New()
    cpu_timer = itk.TimeProbe()

    cpu_timer.Start()

    cpu_filter.SetNumberOfWorkUnits(number_of_work_units)

    cpu_filter.SetInput(input_image)
    cpu_filter.SetOperator(oper)
    cpu_filter.Update()

    cpu_timer.Stop()

    print(
        "CPU NeighborhoodFilter took {} seconds with {} work units.\n".format(
            cpu_timer.GetMean(), cpu_filter.GetNumberOfWorkUnits()))
Example #2
0
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import itk


def LongFunction():
    # CPython loops are much slower than C++,
    # so a smaller range is used in this case.
    for i in range(int(1e5)):
        a = 0.0  # noqa: F841


clock = itk.TimeProbe()

clock.Start()
LongFunction()

clock.Stop()
print('Mean: ' + str(clock.GetMean()))
print('Total: ' + str(clock.GetTotal()))

clock.Start()
LongFunction()

clock.Stop()
print('Mean: ' + str(clock.GetMean()))
print('Total: ' + str(clock.GetTotal()))