def range(self, value):
        if value is not None:
            if not np.all(np.isfinite(value)):
                warning('"range" variable is not finite, '
                        'unpredictable results may occur!\n{0}'.format(value))

            # TODO: `self.range` is a copy of `value` to avoid side effects,
            # Is it a smart way to avoid them?
            value = np.copy(np.asarray(value))

            if self._domain is not None:
                assert value.size == self._domain.size, (
                    '"domain" and "range" variables must have same size!')

            value.setflags(write=False)
            self._range = value
            self._create_function()
    def range(self, value):
        if value is not None:
            if not np.all(np.isfinite(value)):
                warning('"range" variable is not finite, '
                        'unpredictable results may occur!\n{0}'.format(value))

            # TODO: `self.range` is a copy of `value` to avoid side effects,
            # Is it a smart way to avoid them?
            value = np.copy(np.asarray(value))

            if self._domain is not None:
                assert value.size == self._domain.size, (
                    '"domain" and "range" variables must have same size!')

            value.setflags(write=False)
            self._range = value
            self._create_function()
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
def main():
    """
    Starts the application.

    Return
    ------
    bool
        Definition success.
    """

    arguments = command_line_arguments()

    if arguments.version:
        print("{0} - {1}".format(__application_name__, __version__))

        return True

    settings = json.load(open(SETTINGS_FILE))
    if arguments.settings_file is not None:
        assert os.path.exists(arguments.settings_file), '"{0}" file doesn\'t exists!'.format(arguments.settings_file)
        settings.update(json.load(open(arguments.settings_file)))

    input_linearity = arguments.input_linearity.lower()
    if input_linearity == "linear":
        input_linear = True
    elif input_linearity == "oecf":
        input_linear = False
    else:
        input_extension = os.path.splitext(arguments.input_image)[1].lower()
        if input_extension in LINEAR_IMAGE_FORMATS:
            input_linear = True
        else:
            input_linear = False

    if arguments.input_image is not None:
        assert os.path.exists(arguments.input_image), '"{0}" input image doesn\'t exists!'.format(arguments.input_image)

        image_path = arguments.input_image
    else:
        image_path = DEFAULT_IMAGE_PATH

    if is_openimageio_installed:
        image = read_image(str(image_path))
        if not input_linear:
            colourspace = RGB_COLOURSPACES[arguments.input_oecf]
            image = colourspace.inverse_transfer_function(image)

        # Keeping RGB channels only.
        image = image[..., 0:3]

        image = image[:: int(arguments.input_resample), :: int(arguments.input_resample)]
    else:
        warning('"OpenImageIO" is not available, image reading is not supported, ' "falling back to some random noise!")

        image = None

    if not arguments.enable_warnings:
        warnings.filterwarnings("ignore")

    ColourAnalysis(
        image,
        arguments.input_image,
        arguments.input_colourspace,
        arguments.input_oecf,
        input_linear,
        arguments.reference_colourspace,
        arguments.correlate_colourspace,
        settings,
        arguments.layout,
    )
    return run()
Example #5
0
def main():
    """
    Starts the application.

    Return
    ------
    bool
        Definition success.
    """

    arguments = command_line_arguments()

    if arguments.version:
        print('{0} - {1}'.format(__application_name__, __version__))

        return True

    settings = json.load(open(SETTINGS_FILE))
    if arguments.settings_file is not None:
        assert os.path.exists(arguments.settings_file), (
            '"{0}" file doesn\'t exists!'.format(arguments.settings_file))
        settings.update(json.load(open(arguments.settings_file)))

    input_linearity = arguments.input_linearity.lower()
    if input_linearity == 'linear':
        input_linear = True
    elif input_linearity == 'oecf':
        input_linear = False
    else:
        input_extension = os.path.splitext(arguments.input_image)[1].lower()
        if input_extension in LINEAR_IMAGE_FORMATS:
            input_linear = True
        else:
            input_linear = False

    if arguments.input_image is not None:
        assert os.path.exists(arguments.input_image), (
            '"{0}" input image doesn\'t exists!'.format(arguments.input_image))

        image_path = arguments.input_image
    else:
        image_path = DEFAULT_IMAGE_PATH

    try:
        image = read_image(str(image_path))
        if not input_linear:
            colourspace = RGB_COLOURSPACES[arguments.input_oecf]
            image = colourspace.decoding_cctf(image)

        # Keeping RGB channels only.
        image = image[..., 0:3]

        image = image[::int(arguments.input_resample),
                ::int(arguments.input_resample)]
    except ImportError:
        warning(
            '"OpenImageIO" is not available, image reading is not supported, '
            'falling back to some random noise!')

        image = None

    if not arguments.enable_warnings:
        warnings.filterwarnings("ignore")

    ColourAnalysis(image,
                   arguments.input_image,
                   arguments.input_colourspace,
                   arguments.input_oecf,
                   input_linear,
                   arguments.reference_colourspace,
                   arguments.correlate_colourspace,
                   settings,
                   arguments.layout)
    return run()