Beispiel #1
0
def isnr(images, fill_value=0.0):
    """
    Streaming, pixelwise signal-to-noise ratio (SNR).

    Parameters
    ----------
    images : iterable of ndarray
        These images should represent identical measurements. ``images`` can also be a generator.
    fill_value : float, optional
        Division-by-zero results will be filled with this value.

    Yields
    ------
    snr : `~numpy.ndarray`
        Pixelwise signal-to-noise ratio

    See Also
    --------
    snr_from_collection : pixelwise signal-to-noise ratio from a collection of measurements
    """
    first, images = peek(images)
    snr = np.empty_like(first)

    images1, images2 = itercopy(images, 2)
    for mean, std in zip(imean(images1), istd(images2)):
        valid = std != 0
        snr[valid] = mean[valid] / std[valid]
        snr[np.logical_not(valid)] = fill_value
        yield snr
Beispiel #2
0
 def test_against_numpy_mean(self):
     """ Test results against numpy.mean"""
     source = [np.random.random((16, 12, 5)) for _ in range(10)]
     stack = np.stack(source, axis=-1)
     for axis in (0, 1, 2, None):
         with self.subTest("axis = {}".format(axis)):
             from_numpy = np.mean(stack, axis=axis)
             out = last(imean(source, axis=axis))
             self.assertSequenceEqual(from_numpy.shape, out.shape)
             self.assertTrue(np.allclose(out, from_numpy))