from tokenize import String

from skimage import io

from pixel import *


class Editor(object):

    def __init__(self, origin_path: String, edit_path: String):
        """
        This class is the editor which edits a given image and stores a new one.

        :param origin_path: The original image which should be edited.
        :param edit_path: The edited image which should be stored.
        """
        self.image_path = origin_path
        self.edit_path = edit_path

    def do_convolution_with(self, option: String) -> None:
        """
        This method iterates over the image and changes each pixel by a given method.
        Notice, that the image must be a RGB-image (MxNx3).

        :param option: The options defined in FILTER.
        :return: None
        """
        image = io.imread(fname=self.image_path)
        height, width, _ = image.shape  # len(image), len(image[0, 0:, 0:]) wont work for .png-images.
        edited_image = np.zeros((height, width, 3), dtype=np.float64)
        edited_pixels = 0
        for v in range(height):
            for u in range(width):
                pixel = Pixel(image, v, u)
                edited_image[v, u] = pixel.filter_with(option)
                edited_pixels += 1
                if edited_pixels % 10000 == 0:
                    print('Finished with: ' + str(edited_pixels) + ' of ' + str(width * height))

        io.imsave(arr=edited_image, fname=self.edit_path)