Exemplo n.º 1
0
    def __init__(self, image_path: str, destination_path: str, factor: int):
        self.min_factor = 0
        self.max_factor = int(get_greyscale(
            255, 255, 255))  # max greyscale valaue for #FFFFFF

        if not self.min_factor < factor < self.max_factor:
            raise ValueError(
                f"Factor value should be from 0 to {self.max_factor}")

        self.image = Image(image_path)
        self.factor = factor

        self.destination_path = destination_path

        #  raw error table and output image
        self.width, self.height = self.image.get_size()
        self.greyscale_image = self.image2greyscale()
        # error size + 1 than input image because of lack of if statements
        self.error_table = [[0 for _ in range(self.height + 2)]
                            for __ in range(self.width + 2)]

        self.output_image = PillowImage.new("RGB", (self.width, self.height),
                                            self.WHITE)
        self.output_pixels = self.output_image.load()
        self.output_image_name = "output_floyd_steinberg.jpg"
Exemplo n.º 2
0
    def __init__(self,
                 image_path: str,
                 destination_path: str,
                 min_blur: float,
                 max_blur: float,
                 sharpen_area_size: List = None):

        self.image_path = image_path
        self.destination_path = destination_path
        self.input_image = Image(self.image_path)
        self.pixels = self.input_image.pixels

        if not sharpen_area_size:
            sharpen_area_size = [0, 0]

        self.sharpen_min_h, self.sharpen_max_h = sharpen_area_size[
            0], sharpen_area_size[1]
        self.sharpen_size = self.sharpen_max_h - self.sharpen_min_h
        self.sharpen_center = self.sharpen_min_h + self.sharpen_size // 2

        self.filter_elements = []

        self.min_factor = 0.003
        self.max_factor = 0.003

        self.min_blur = min_blur
        self.max_blur = max_blur
Exemplo n.º 3
0
def make_negative(image_path: str, dest_path: str):
    image = Image(image_path)
    width, height = image.get_size()
    output = create_empty_image(width, height)
    output_pixels = output.load()
    for x in range(width):
        for y in range(height):
            red, green, blue = image.pixels[x, y]
            output_pixels[x, y] = (255 - red, 255 - green, 255 - blue)

    output.save(dest_path)
Exemplo n.º 4
0
def make_sepia(image_path: str, dest_path: str, factor: int):
    image = Image(image_path)
    width, height = image.get_size()
    output = create_empty_image(width, height)
    output_pixels = output.load()
    for x in range(width):
        for y in range(height):
            red, green, blue = image.pixels[x, y]
            grey_red = int(get_greyscale(red, green, blue))
            grey_green = int(get_greyscale(red, green, blue))
            grey_blue = int(get_greyscale(red, green, blue))

            output_pixels[x, y] = (grey_red + 2 * factor, grey_green + factor,
                                   grey_blue)

    output.save(dest_path)
Exemplo n.º 5
0
 def __init__(self, image_path: str, scale: float):
     self.image = Image(image_path)
     self.scale = scale
     self.new_image = None