예제 #1
0
    def test_centroid(self):
        """Test :func:`colour.utilities.array.centroid` definition."""

        a = np.arange(5)
        np.testing.assert_array_equal(centroid(a), np.array([3]))

        a = np.tile(a, (5, 1))
        np.testing.assert_array_equal(centroid(a), np.array([2, 3]))

        a = np.tile(np.linspace(0, 1, 10), (10, 1))
        np.testing.assert_array_equal(centroid(a), np.array([4, 6]))

        a = tstack([a, a, a])
        np.testing.assert_array_equal(centroid(a), np.array([4, 6, 1]))
예제 #2
0
def luminance_variance(a):
    """
    Computes the Luminance variance of given :math:`a` 2-D array.

    Parameters
    ----------
    a : array_like
        :math:`a` 2-D array to compute the Luminance variation.

    Returns
    -------
    numeric
        :math:`a` 2-D array Luminance variance.

    Examples
    --------
    >>> a = np.tile(np.arange(5), (5, 1))
    >>> luminance_variance(a)  # doctest: +ELLIPSIS
    12.2474487...
    """

    x, y = np.mgrid[0:np.shape(a)[0], 0:np.shape(a)[1]]

    x_centroid, y_centroid = centroid(a)

    variance = np.sqrt(np.sum(a * ((y - y_centroid)**2 + (x - x_centroid)**2)))

    return variance
예제 #3
0
    def test_centroid(self):
        """
        Tests :func:`colour.utilities.array.centroid` definition.
        """

        a = np.arange(5)
        np.testing.assert_array_equal(centroid(a), np.array([3]))

        a = np.tile(a, (5, 1))
        np.testing.assert_array_equal(centroid(a), np.array([2, 3]))

        a = np.tile(np.linspace(0, 1, 10), (10, 1))
        np.testing.assert_array_equal(centroid(a), np.array([4, 6]))

        a = tstack([a, a, a])
        np.testing.assert_array_equal(centroid(a), np.array([4, 6, 1]))
예제 #4
0
def light_probe_sampling_variance_minimization_Viriyothai2009(
        light_probe, lights_count=16, colourspace=RGB_COLOURSPACES['sRGB']):
    """
    Sample given light probe to find lights using *Viriyothai (2009)* variance
    minimization light probe sampling algorithm.

    Parameters
    ----------
    light_probe : array_like
        Array to sample for lights.
    lights_count : int
        Amount of lights to generate.
    colourspace : `colour.RGB_Colourspace`, optional
        *RGB* colourspace used for internal *Luminance* computation.

    Returns
    -------
    list
        list of
        :class:`colour_hdri.sampling.variance_minimization.Light_Specification`
        lights.

    References
    ----------
    :cite:`Viriyothai2009`
    """

    light_probe = as_float_array(light_probe)

    iterations = np.sqrt(lights_count).astype(np.int_)
    if iterations**2 != lights_count:
        warning(
            '{0} lights requested, {1} will be effectively computed!'.format(
                lights_count, iterations**2))

    Y = RGB_luminance(light_probe, colourspace.primaries,
                      colourspace.whitepoint)
    regions = find_regions_variance_minimization_Viriyothai2009(Y, iterations)

    lights = []
    for region in regions:
        y_min, y_max, x_min, x_max = region
        c = centroid(Y[y_min:y_max, x_min:x_max])
        c = (c + np.array([y_min, x_min]))
        light_probe_c = light_probe[y_min:y_max, x_min:x_max]
        lights.append(
            Light_Specification((c / np.array(Y.shape))[::-1],
                                np.sum(np.sum(light_probe_c, 0), 0), c))

    return lights