def test_gradient_magnitude(self): """ Test if the gradient magnitude filter produces the same results, independent from the dtype of the input array. """ dtypes = [ scipy.int8, scipy.int16, scipy.int32, scipy.int64, scipy.uint8, scipy.uint16, scipy.uint32, scipy.uint64, scipy.float32, scipy.float64, scipy.float128 ] arr_base = scipy.random.randint(0, 100, (20, 30, 40, 50)) arr_reference = gradient_magnitude(arr_base) # test different dtypes for dtype in dtypes: arr = gradient_magnitude(arr_base.astype(dtype)) self.assertTrue( (arr == arr_reference).all(), 'Difference for dtype {} encountered.'.format(dtype)) # test if voxel spacing is taken into account arr = gradient_magnitude(arr_base, [1.1, 1.2, 1.3, 4]) self.assertFalse((arr == arr_reference).all(), 'Implementation ignores the passed voxel spacing.')
def main(): # parse cmd arguments parser = getParser() parser.parse_args() args = getArguments(parser) # prepare logger logger = Logger.getInstance() if args.debug: logger.setLevel(logging.DEBUG) elif args.verbose: logger.setLevel(logging.INFO) # check if output image exists (will also be performed before saving, but as the gradient might be time intensity, a initial check can save frustration) if not args.force: if os.path.exists(args.output): raise ArgumentError('The output image {} already exists.'.format( args.output)) # loading image data_input, header_input = load(args.input) logger.debug('Input array: dtype={}, shape={}'.format( data_input.dtype, data_input.shape)) # execute the gradient map filter logger.info('Applying gradient map filter...') data_output = filter.gradient_magnitude( data_input, header.get_pixel_spacing(header_input)) logger.debug('Resulting array: dtype={}, shape={}'.format( data_output.dtype, data_output.shape)) # save image save(data_output, args.output, header_input, args.force) logger.info('Successfully terminated.')
def main(): # parse cmd arguments parser = getParser() parser.parse_args() args = getArguments(parser) # prepare logger logger = Logger.getInstance() if args.debug: logger.setLevel(logging.DEBUG) elif args.verbose: logger.setLevel(logging.INFO) # check if output image exists (will also be performed before saving, but as the gradient might be time intensity, a initial check can save frustration) if not args.force: if os.path.exists(args.output): raise ArgumentError('The output image {} already exists.'.format(args.output)) # loading image data_input, header_input = load(args.input) logger.debug('Input array: dtype={}, shape={}'.format(data_input.dtype, data_input.shape)) # execute the gradient map filter logger.info('Applying gradient map filter...') data_output = filter.gradient_magnitude(data_input, header.get_pixel_spacing(header_input)) logger.debug('Resulting array: dtype={}, shape={}'.format(data_output.dtype, data_output.shape)) # save image save(data_output, args.output, header_input, args.force) logger.info('Successfully terminated.')
def test_gradient_magnitude(self): """ Test if the gradient magnitude filter produces the same results, independent from the dtype of the input array. """ dtypes = [scipy.int8, scipy.int16, scipy.int32, scipy.int64, scipy.uint8, scipy.uint16, scipy.uint32, scipy.uint64, scipy.float32, scipy.float64, scipy.float128] arr_base = scipy.random.randint(0, 100, (20, 30, 40, 50)) arr_reference = gradient_magnitude(arr_base) # test different dtypes for dtype in dtypes: arr = gradient_magnitude(arr_base.astype(dtype)) self.assertTrue((arr == arr_reference).all(), 'Difference for dtype {} encountered.'.format(dtype)) # test if voxel spacing is taken into account arr = gradient_magnitude(arr_base, [1.1, 1.2, 1.3, 4]) self.assertFalse((arr == arr_reference).all(), 'Implementation ignores the passed voxel spacing.')