def test_save_image(datadirs):
    _, formatsdir, _, _ = datadirs
    formats = ['gif', 'png', 'jpg', 'bmp', 'tif', 'npy']
    for format in formats:
        inpath = formatsdir + 'nut_color.' + format
        outpath = formatsdir + 'temp_nut_color.' + format
        image = ni.load_image(inpath)
        ni.save_image(outpath, image)
        loaded = ni.load_image(outpath)
        os.remove(outpath)
        # Saved and loaded JPG images can vary greatly (lossy format) when using
        # skimage and a direct comparision fails under Windows 7, Anaconda.
        # Therefore, only shape and mean value are verified for JPG images.
        if format == 'jpg':
            assert abs(np.mean(image) - np.mean(loaded)) < 0.1
            assert loaded.shape == (213, 320, 3)
        else:
            nt.assert_allclose(image, loaded)
def assert_equal_image(imagepath, image, rtol=0.01, atol=0.01):
    if CREATE_DATA:
        ni.save_image(imagepath, image)
    expected = ni.load_image(imagepath)
    nt.assert_allclose(expected, image, rtol=rtol, atol=atol)