def test_align_no_mask():
    """ Test that alignment of images with no masks works """
    reference = camera()
    image = ndi.shift(camera(), shift=(-7, 12))
    aligned = align(image, reference=reference)

    assert np.allclose(reference[7::, 0:-12], aligned[7::, 0:-12])
def test_align_with_mask():
    """ Test that alignment of images with no masks works """
    reference = camera()
    image = ndi.shift(camera(), shift=(-7, 12))

    mask = np.ones_like(reference, dtype=bool)
    mask[75:100, 50:100] = False

    aligned = align(image, reference=reference, mask=mask)

    assert np.allclose(reference[7::, 0:-12], aligned[7::, 0:-12])
    def test_misaligned_canned_images(self):
        """ shift images from skimage.data by entire pixels.
	   	We don't expect perfect alignment."""
        original = TEST_IMAGE
        misaligned = ndi.shift(original, (randint(-4, 4), randint(-4, 4)))

        aligned = align(misaligned, reference=original)

        # edge will be filled with zeros, we ignore
        diff = np.abs(original[5:-5, 5:-5] - aligned[5:-5, 5:-5])

        # Want less than 1% difference
        percent_diff = np.sum(diff) / (diff.size *
                                       (original.max() - original.min()))
        self.assertLess(percent_diff, 1)
 def test_no_side_effects(self):
     """ Test that aligned images are not modified in-place """
     im = np.array(TEST_IMAGE[0:64, 0:64])
     im.setflags(write=False)
     aligned = align(im, reference=im, fill_value=np.nan)
     self.assertEqual(im.dtype, TEST_IMAGE.dtype)
def test_align_no_side_effects():
    """ Test that aligned images are not modified in-place """
    im = np.array(camera()[0:64, 0:64])
    im.setflags(write=False)
    aligned = align(im, reference=im, fill_value=np.nan)
    assert im.dtype == camera().dtype