def METHOD_NAME(tmp_path):
    fname = tmp_path / 'image.mgh'
    img = nb.MGHImage(
        np.random.uniform(-20000, 20000, (5, 5, 5, 5)).astype('float32'), affine=np.eye(4)
    )
    img.to_filename(fname)
    img1 = nb.load(fname)
    sliced_fname = tmp_path / 'sliced.mgh'
    lossless_slice(img1, (slice(None), slice(None), slice(2, 4))).to_filename(sliced_fname)
    img2 = nb.load(sliced_fname)
    assert np.array_equal(img1.get_fdata()[:, :, 2:4], img2.get_fdata())
    assert np.array_equal(img1.dataobj.get_unscaled()[:, :, 2:4], img2.dataobj.get_unscaled())
    assert img1.dataobj.slope == img2.dataobj.slope
    assert img1.dataobj.inter == img2.dataobj.inter