Ejemplo n.º 1
0
    def open_image(path):
        image = PIL.Image.open(path)
        pixels = list(image.getdata())
        channels = ImageHelper.__channel_converter(pixels, image.mode)

        return Image(channels, image.height, image.width,
                     ImageHelper.RANGE_OF_BRIGHTNESS)
Ejemplo n.º 2
0
    def get_image_channel(image, channel):
        result = []
        for ind in range(len(image.get_channels()[channel])):
            result.append(image.get_channels()[channel][ind])

        return Image([result], image.get_height(), image.get_width(),
                     image.get_range_of_brightness())
Ejemplo n.º 3
0
    def get_negative_image(image):
        new_channels = list()
        channel_handler = ImageHelper.__get_channel_handler(image)

        for channel in image.get_channels():
            new_channels.append(channel_handler.get_negative(channel))

        return Image(new_channels, image.get_height(), image.get_width(),
                     image.get_range_of_brightness())
Ejemplo n.º 4
0
    def get_binorized_image(image, division):
        new_channels = list()
        channel_handler = ImageHelper.__get_channel_handler(image)

        for channel in image.get_channels():
            new_channels.append(
                channel_handler.binorize_channel(channel, division))

        return Image(new_channels, image.get_height(), image.get_width(),
                     image.get_range_of_brightness())
Ejemplo n.º 5
0
    def get_image_filtered_by_harmonic_mean(image, size=9):
        new_channels = list()
        channel_handler = ImageHelper.__get_channel_handler(image)

        for channel in image.get_channels():
            new_channels.append(
                channel_handler.filter_by_harmonic_mean(channel, size))

        return Image(new_channels, image.get_height(), image.get_width(),
                     image.get_range_of_brightness())
Ejemplo n.º 6
0
    def get_image_with_lowed_brightness(image, max_out_brightness):
        new_channels = list()
        channel_handler = ImageHelper.__get_channel_handler(image)

        for channel in image.get_channels():
            new_channels.append(
                channel_handler.low_brightness(channel, max_out_brightness))

        return Image(new_channels, image.get_height(), image.get_width(),
                     image.get_range_of_brightness())
Ejemplo n.º 7
0
    def get_adaptive_binorized_image(image, block_size, addition_percent=15):
        new_channels = list()
        channel_handler = ImageHelper.__get_channel_handler(image)

        for channel in image.get_channels():
            new_channels.append(
                channel_handler.binorize_adaptive_channel(
                    channel, block_size, addition_percent))

        return Image(new_channels, image.get_height(), image.get_width(),
                     image.get_range_of_brightness())
Ejemplo n.º 8
0
    def get_image_with_some_noise(image, percent=10):

        new_channels = list()
        channel_handler = ImageHelper.__get_channel_handler(image)

        for channel in image.get_channels():
            new_channels.append(
                channel_handler.make_some_noise(channel, percent))

        return Image(new_channels, image.get_height(), image.get_width(),
                     image.get_range_of_brightness())
Ejemplo n.º 9
0
    def get_greyscale_image(image):
        if len(image.get_channels()) == ImageHelper.RGB:
            result = []
            for ind in range(len(image.get_channels()[ImageHelper.R])):
                grey_byte = \
                    int(image.get_channels()[ImageHelper.R][ind] * 299 / 1000 + \
                        image.get_channels()[ImageHelper.GREEN][ind] * 587 / 1000 + \
                        image.get_channels()[ImageHelper.B][ind] * 114 / 1000)
                result.append(grey_byte)
        else:
            result = copy.copy(image.get_channels()[ImageHelper.GREY])

        return Image([result], image.get_height(), image.get_width(),
                     image.get_range_of_brightness())
Ejemplo n.º 10
0
        def erosion(image):
            if len(image.get_channels()) != 1:
                return

            flags_matrix = [[0] * image.get_width()
                            for _ in range(image.get_height())]
            chanel = copy.copy(image.get_channels()[0])

            for row in range(image.get_height()):
                for column in range(image.get_width()):
                    if chanel[row * image.get_width() + column] == 255:
                        flag = False
                        if row != 0:
                            if chanel[(row - 1) * image.get_width() +
                                      column] == 0:
                                if flags_matrix[row - 1][column] != 1:
                                    flag = True
                        if not flag:
                            if row != image.get_height() - 1:
                                if chanel[(row + 1) * image.get_width() +
                                          column] == 0:
                                    if flags_matrix[row + 1][column] != 1:
                                        flag = True
                        if not flag:
                            if column != 0:
                                if chanel[row * image.get_width() + column -
                                          1] == 0:
                                    if flags_matrix[row][column - 1] != 1:
                                        flag = True
                        if not flag:
                            if column != image.get_width() - 1:
                                if chanel[row * image.get_width() + column +
                                          1] == 0:
                                    if flags_matrix[row][column + 1] != 1:
                                        flag = True

                        if flag:
                            flags_matrix[row][column] = 1
                            chanel[row * image.get_width() + column] = 0

            return Image([chanel], image.get_height(), image.get_width(),
                         image.get_range_of_brightness())
Ejemplo n.º 11
0
        def building(image):
            if len(image.get_channels()) != 1:
                return

            flags_matrix = [[0] * image.get_width()
                            for _ in range(image.get_height())]
            chanel = copy.copy(image.get_channels()[0])

            for row in range(image.get_height()):
                for column in range(image.get_width()):
                    if flags_matrix[row][column] == 0:
                        if chanel[row * image.get_width() + column] == 255:
                            if row != 0:
                                if chanel[(row - 1) * image.get_width() +
                                          column] == 0:
                                    chanel[(row - 1) * image.get_width() +
                                           column] = 255
                                    flags_matrix[row - 1][column] = 1
                            if row != image.get_height() - 1:
                                if chanel[(row + 1) * image.get_width() +
                                          column] == 0:
                                    chanel[(row + 1) * image.get_width() +
                                           column] = 255
                                    flags_matrix[row + 1][column] = 1
                            if column != 0:
                                if chanel[row * image.get_width() + column -
                                          1] == 0:
                                    chanel[row * image.get_width() + column -
                                           1] = 255
                                    flags_matrix[row][column - 1] = 1
                            if column != image.get_width() - 1:
                                if chanel[row * image.get_width() + column +
                                          1] == 0:
                                    chanel[row * image.get_width() + column +
                                           1] = 255
                                    flags_matrix[row][column + 1] = 1

            return Image([chanel], image.get_height(), image.get_width(),
                         image.get_range_of_brightness())