예제 #1
0
    def test_misaligned_canned_images_notfast(self):
        """ shift images from skimage.data by entire pixels.
	   	We don't expect perfect alignment."""
        original = data.camera()
        misaligned = shift_image(original, (randint(-4, 4), randint(-4, 4)))

        aligned = align(misaligned, reference=original, fast=False)

        # 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)
예제 #2
0
    def test_misaligned_canned_images_fast(self):
        """ shift images from skimage.data by entire pixels.
	   We don't expect perfect alignment."""
        original = data.camera()
        misaligned = [
            shift_image(original, (randint(-4, 4), randint(-4, 4)))
            for _ in range(5)
        ]

        aligned = ialign(misaligned, reference=original, fast=True)

        # TODO: find a better figure-of-merit for alignment
        for im in aligned:
            # edge will be filled with zeros, we ignore
            diff = np.abs(original[5:-5, 5:-5] - im[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)
예제 #3
0
# build. Therefore, we render the image locally instead.

import matplotlib.pyplot as plt
import numpy as np
from skimage.registration import phase_cross_correlation

from skued import diffread, shift_image

ref = diffread("Cr_1.tif")
im = diffread("Cr_2.tif")

mask = np.ones_like(ref, dtype=np.bool)
mask[0:1250, 950:1250] = False

shift = phase_cross_correlation(im, ref, reference_mask=mask)
shifted = shift_image(im, -1 * shift)

fig, ((ax1, ax2, ax3), (ax4, ax5, ax6)) = plt.subplots(nrows=2, ncols=3, figsize=(9, 6))
ax1.imshow(ref, vmin=0, vmax=200)
ax2.imshow(im, vmin=0, vmax=200)
ax3.imshow(ref - im, cmap="RdBu_r", vmin=-100, vmax=100)
ax4.imshow(mask, vmin=0, vmax=1, cmap="binary")
ax5.imshow(shifted, vmin=0, vmax=200)
ax6.imshow(ref - shifted, cmap="RdBu_r", vmin=-100, vmax=100)

for ax in (ax1, ax2, ax3, ax4, ax5, ax6):
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)

ax1.set_title("Reference")
ax2.set_title("Data")
예제 #4
0
    def test_out_of_bounds(self):
        """ Test that shifting by more than the size of an array
		returns an array full of the fill_value parameter """
        arr = np.random.random(size=(64, 64)) + 1  # no zeros in this array
        shifted = shift_image(arr, (128, 128), fill_value=0.0)
        self.assertTrue(np.allclose(np.zeros_like(arr), shifted))
예제 #5
0
 def test_return_type(self):
     """ Test that a shifted array will cast accordingly to the fill_value """
     arr = np.random.randint(0, 255, size=(64, 64), dtype=np.uint8)
     shifted = shift_image(arr, shift=(10, 10),
                           fill_value=np.nan)  # np.nan is float
     self.assertEqual(shifted.dtype, np.float)
예제 #6
0
 def test_back_and_forth(self):
     """ Test shift_image in two directions """
     arr = np.random.random(size=(64, 64))
     shifted1 = shift_image(arr, (5, -3))
     shifted2 = shift_image(shifted1, (-5, 3))
     self.assertTrue(np.allclose(arr[5:-5, 5:-5], shifted2[5:-5, 5:-5]))
예제 #7
0
 def test_shift_float16(self):
     """ Interpolation requires float32 or more bits. """
     arr = np.random.random(size=(64, 64)).astype(np.float16)
     shifted1 = shift_image(arr, (5, -3))
     shifted2 = shift_image(shifted1, (-5, 3))
     self.assertTrue(np.allclose(arr[5:-5, 5:-5], shifted2[5:-5, 5:-5]))
예제 #8
0
 def test_trivial(self):
     """ Shift an array by (0,0) """
     arr = np.random.random(size=(64, 64))
     shifted = shift_image(arr, (0, 0))
     self.assertTrue(np.allclose(arr, shifted))
예제 #9
0
 def test_fill_value(self):
     """ Test that shifted array edges are filled with the correct value """
     arr = np.random.random(size=(64, 64))
     shifted = shift_image(arr, shift=(0, 10), fill_value=np.nan)
     self.assertTrue(np.all(np.isnan(shifted[:10, :])))