Beispiel #1
0
    def __call__(self, _image, nb_channels, random_state):
        alpha_sample = self.alpha.draw_sample(random_state=random_state)
        assert 0 <= alpha_sample <= 1.0, (
            "Expected 'alpha' to be in the interval [0.0, 1.0], "
            "got %.4f." % (alpha_sample, ))
        direction_sample = self.direction.draw_sample(
            random_state=random_state)

        deg = int(direction_sample * 360) % 360
        rad = np.deg2rad(deg)
        x = np.cos(rad - 0.5 * np.pi)
        y = np.sin(rad - 0.5 * np.pi)
        direction_vector = np.array([x, y])

        matrix_effect = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]],
                                 dtype=np.float32)
        for x, y in itertools.product([-1, 0, 1], [-1, 0, 1]):
            if (x, y) != (0, 0):
                cell_vector = np.array([x, y])
                distance_deg = np.rad2deg(
                    ia.angle_between_vectors(cell_vector, direction_vector))
                distance = distance_deg / 180
                similarity = (1 - distance)**4
                matrix_effect[y + 1, x + 1] = similarity
        matrix_effect = matrix_effect / np.sum(matrix_effect)
        matrix_effect = matrix_effect * (-1)
        matrix_effect[1, 1] = 1

        matrix_nochange = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]],
                                   dtype=np.float32)

        matrix = ((1 - alpha_sample) * matrix_nochange +
                  alpha_sample * matrix_effect)

        return [matrix] * nb_channels
Beispiel #2
0
    def create_matrices(_image, nb_channels, random_state_func):
        alpha_sample = alpha_param.draw_sample(random_state=random_state_func)
        ia.do_assert(0 <= alpha_sample <= 1.0)
        direction_sample = direction_param.draw_sample(
            random_state=random_state_func)

        deg = int(direction_sample * 360) % 360
        rad = np.deg2rad(deg)
        x = np.cos(rad - 0.5 * np.pi)
        y = np.sin(rad - 0.5 * np.pi)
        direction_vector = np.array([x, y])

        matrix_effect = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]],
                                 dtype=np.float32)
        for x in [-1, 0, 1]:
            for y in [-1, 0, 1]:
                if (x, y) != (0, 0):
                    cell_vector = np.array([x, y])
                    distance_deg = np.rad2deg(
                        ia.angle_between_vectors(cell_vector,
                                                 direction_vector))
                    distance = distance_deg / 180
                    similarity = (1 - distance)**4
                    matrix_effect[y + 1, x + 1] = similarity
        matrix_effect = matrix_effect / np.sum(matrix_effect)
        matrix_effect = matrix_effect * (-1)
        matrix_effect[1, 1] = 1

        matrix_nochange = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]],
                                   dtype=np.float32)

        matrix = (
            1 - alpha_sample) * matrix_nochange + alpha_sample * matrix_effect

        return [matrix] * nb_channels