def test_smooth_img(): # This function only checks added functionalities compared # to _smooth_array() shapes = ((10, 11, 12), (13, 14, 15)) lengths = (17, 18) fwhm = (1., 2., 3.) img1, mask1 = testing.generate_fake_fmri(shape=shapes[0], length=lengths[0]) img2, mask2 = testing.generate_fake_fmri(shape=shapes[1], length=lengths[1]) for create_files in (False, True): with testing.write_tmp_imgs(img1, img2, create_files=create_files) as imgs: # List of images as input out = image.smooth_img(imgs, fwhm) assert_true(isinstance(out, list)) assert_true(len(out) == 2) for o, s, l in zip(out, shapes, lengths): assert_true(o.shape == (s + (l,))) # Single image as input out = image.smooth_img(imgs[0], fwhm) assert_true(isinstance(out, nibabel.Nifti1Image)) assert_true(out.shape == (shapes[0] + (lengths[0],)))
def test_smooth_img(): # This function only checks added functionalities compared # to _smooth_array() shapes = ((10, 11, 12), (13, 14, 15)) lengths = (17, 18) fwhm = (1., 2., 3.) img1, mask1 = testing.generate_fake_fmri(shape=shapes[0], length=lengths[0]) img2, mask2 = testing.generate_fake_fmri(shape=shapes[1], length=lengths[1]) for create_files in (False, True): with testing.write_tmp_imgs(img1, img2, create_files=create_files) as imgs: # List of images as input out = image.smooth_img(imgs, fwhm) assert_true(isinstance(out, list)) assert_true(len(out) == 2) for o, s, l in zip(out, shapes, lengths): assert_true(o.shape == (s + (l, ))) # Single image as input out = image.smooth_img(imgs[0], fwhm) assert_true(isinstance(out, nibabel.Nifti1Image)) assert_true(out.shape == (shapes[0] + (lengths[0], ))) # Check corner case situations when fwhm=0, See issue #1537 # Test whether function smooth_img raises a warning when fwhm=0. assert_warns(UserWarning, image.smooth_img, img1, fwhm=0.) # Test output equal when fwhm=None and fwhm=0 out_fwhm_none = image.smooth_img(img1, fwhm=None) out_fwhm_zero = image.smooth_img(img1, fwhm=0.) assert_array_equal(out_fwhm_none.get_data(), out_fwhm_zero.get_data())
def test_smooth_img(): # This function only checks added functionalities compared # to _smooth_array() shapes = ((10, 11, 12), (13, 14, 15)) lengths = (17, 18) fwhm = (1., 2., 3.) img1, mask1 = data_gen.generate_fake_fmri(shape=shapes[0], length=lengths[0]) img2, mask2 = data_gen.generate_fake_fmri(shape=shapes[1], length=lengths[1]) for create_files in (False, True): with testing.write_tmp_imgs(img1, img2, create_files=create_files) as imgs: # List of images as input out = image.smooth_img(imgs, fwhm) assert_true(isinstance(out, list)) assert_true(len(out) == 2) for o, s, l in zip(out, shapes, lengths): assert_true(o.shape == (s + (l,))) # Single image as input out = image.smooth_img(imgs[0], fwhm) assert_true(isinstance(out, nibabel.Nifti1Image)) assert_true(out.shape == (shapes[0] + (lengths[0],))) # Check corner case situations when fwhm=0, See issue #1537 # Test whether function smooth_img raises a warning when fwhm=0. assert_warns(UserWarning, image.smooth_img, img1, fwhm=0.) # Test output equal when fwhm=None and fwhm=0 out_fwhm_none = image.smooth_img(img1, fwhm=None) out_fwhm_zero = image.smooth_img(img1, fwhm=0.) assert_array_equal(out_fwhm_none.get_data(), out_fwhm_zero.get_data()) data1 = np.zeros((10, 11, 12)) data1[2:4, 1:5, 3:6] = 1 data2 = np.zeros((13, 14, 15)) data2[2:4, 1:5, 3:6] = 9 img1_nifti2 = nibabel.Nifti2Image(data1, affine=np.eye(4)) img2_nifti2 = nibabel.Nifti2Image(data2, affine=np.eye(4)) out = image.smooth_img([img1_nifti2, img2_nifti2], fwhm=1.)
def test_smooth_img(): # This function only checks added functionalities compared # to _smooth_array() shapes = ((10, 11, 12), (13, 14, 15)) lengths = (17, 18) fwhm = (1., 2., 3.) img1, mask1 = data_gen.generate_fake_fmri(shape=shapes[0], length=lengths[0]) img2, mask2 = data_gen.generate_fake_fmri(shape=shapes[1], length=lengths[1]) for create_files in (False, True): with testing.write_tmp_imgs(img1, img2, create_files=create_files) as imgs: # List of images as input out = image.smooth_img(imgs, fwhm) assert isinstance(out, list) assert len(out) == 2 for o, s, l in zip(out, shapes, lengths): assert o.shape == (s + (l, )) # Single image as input out = image.smooth_img(imgs[0], fwhm) assert isinstance(out, nibabel.Nifti1Image) assert out.shape == (shapes[0] + (lengths[0], )) # Check corner case situations when fwhm=0, See issue #1537 # Test whether function smooth_img raises a warning when fwhm=0. with pytest.warns(UserWarning): image.smooth_img(img1, fwhm=0.) # Test output equal when fwhm=None and fwhm=0 out_fwhm_none = image.smooth_img(img1, fwhm=None) out_fwhm_zero = image.smooth_img(img1, fwhm=0.) assert_array_equal(get_data(out_fwhm_none), get_data(out_fwhm_zero)) data1 = np.zeros((10, 11, 12)) data1[2:4, 1:5, 3:6] = 1 data2 = np.zeros((13, 14, 15)) data2[2:4, 1:5, 3:6] = 9 img1_nifti2 = nibabel.Nifti2Image(data1, affine=np.eye(4)) img2_nifti2 = nibabel.Nifti2Image(data2, affine=np.eye(4)) out = image.smooth_img([img1_nifti2, img2_nifti2], fwhm=1.)