コード例 #1
0
ファイル: chunk.py プロジェクト: kvmani/kikuchipy
def get_image_quality(
    patterns: Union[np.ndarray, da.Array],
    frequency_vectors: Optional[np.ndarray] = None,
    inertia_max: Union[None, int, float] = None,
    normalize: bool = True,
) -> np.ndarray:
    """Compute the image quality in a chunk of EBSD patterns.

    The image quality is calculated based on the procedure defined by
    Krieger Lassen [Lassen1994]_.

    Parameters
    ----------
    patterns
        EBSD patterns.
    frequency_vectors
        Integer 2D array with values corresponding to the weight given
        each FFT spectrum frequency component. If None (default), these
        are calculated from
        :func:`~kikuchipy.util.pattern.fft_frequency_vectors`.
    inertia_max
        Maximum inertia of the FFT power spectrum of the image. If None
        (default), this is calculated from the `frequency_vectors`.
    normalize
        Whether to normalize patterns to a mean of zero and standard
        deviation of 1 before calculating the image quality. Default
        is True.

    Returns
    -------
    image_quality_chunk : numpy.ndarray
        Image quality of patterns.
    """
    dtype_out = np.float64

    image_quality_chunk = np.empty(patterns.shape[:-2], dtype=dtype_out)

    for nav_idx in np.ndindex(patterns.shape[:-2]):
        # Get (normalized) pattern
        if normalize:
            pattern = pattern_processing.normalize_intensity(
                pattern=patterns[nav_idx])
        else:
            pattern = patterns[nav_idx]

        # Compute image quality
        image_quality_chunk[nav_idx] = pattern_processing.get_image_quality(
            pattern=pattern,
            normalize=False,
            frequency_vectors=frequency_vectors,
            inertia_max=inertia_max,
        )

    return image_quality_chunk
コード例 #2
0
ファイル: test_pattern.py プロジェクト: hakonanes/kikuchipy
    def test_get_image_quality_pattern(
        self, dummy_signal, idx, normalize, frequency_vectors, inertia_max, answer
    ):
        p = dummy_signal.inav[idx].data.astype(np.float32)
        iq = get_image_quality(
            pattern=p,
            normalize=normalize,
            frequency_vectors=frequency_vectors,
            inertia_max=inertia_max,
        )

        assert np.allclose(iq, answer, atol=1e-4)
コード例 #3
0
ファイル: test_pattern.py プロジェクト: hakonanes/kikuchipy
    def test_get_image_quality_flat(self):
        p = np.ones((1001, 1001)) * 5
        iq = get_image_quality(pattern=p, normalize=False)

        assert np.allclose(iq, 1, atol=1e-2)
コード例 #4
0
ファイル: test_pattern.py プロジェクト: hakonanes/kikuchipy
    def test_get_image_quality_white_noise(self):
        p = np.random.random((1001, 1001))
        iq = get_image_quality(pattern=p, normalize=True)

        assert np.allclose(iq, 0, atol=1e-2)