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
def light_probe_sampling_variance_minimization(
        light_probe,
        lights_count=16,
        luminance_factors=DEFAULT_LUMINANCE_FACTORS):
    """
    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.
    luminance_factors : array_like
        Weighting factors for Luminance conversion.

    Returns
    -------
    list
        list of :class:`Light_Specification` lights.
    """

    light_probe = np.asarray(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 = np.dot(light_probe, luminance_factors)
    regions = find_regions_variance_minimization(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]))
        lights.append(
            Light_Specification(
                (c / np.array(Y.shape))[::-1],
                np.sum(np.sum(light_probe[y_min:y_max, x_min:x_max], 0), 0),
                c))

    return lights