from PIL import Image 
from PIL import ImageChops

PATH_JAGODA = "/home/cugur/Downloads/matf/dozs/2024/week4/data/jagoda_002.jpg"
PATH_MUVA = "/home/cugur/Downloads/matf/dozs/2024/week4/data/muva_002.jpg"

with Image.open(PATH_JAGODA) as imgJ, Image.open(PATH_MUVA) as imgM:

    imgJ.show()
    imgM.show()

    print("Rezuolucije slika: ", imgJ.size, imgM.size)

    # alpha - intentizet piksela druge slike
    for alpha in (0, 0.1, 0.25, 0.5, 1):
        img1 = ImageChops.blend(imgJ, imgM, alpha)
        img1.show()

    # min i max odgovaraju lighter i darker opcijama: za rezultujucu vrednost piksela uzmi manji ili veci od vrednosti corresponding piksela originalnih slika 
    imgL = ImageChops.lighter(imgJ, imgM)
    imgL.show() 

    imgD = ImageChops.darker(imgJ, imgM)
    imgD.show()

    # Pitanje: da li je botan redosled lika u lighter i darker transformacijama?
    imgL1 = ImageChops.lighter(imgJ, imgM)
    imgL1.show() 

    imgL2 = ImageChops.lighter(imgM, imgJ)
    imgL2.show() 

    # Odgovor ne, jer je min(a, b) = min(b, a)

    # Kako redosled utice na druge trasformacije, npr. difference?
    img4 = ImageChops.difference(imgJ, imgM)
    img4.show()

    img5 = ImageChops.difference(imgM, imgJ)
    img5.show()

    # Odgovor je ne, jer postoji apsolutna vrednost u formuli racunanja rezultujeg piksela i abs(a-b) = abs(b-a)

    # Pitanje: Kako se direktno vidi matrica piksela? Slika img5 je dimenzija 250 x 200
    pixels = img5.load()
    for i in range(250):
        for j in range(200):
            print("i={}, j={}, pixels[{}, {}] = {}".format(i, j, i, j, pixels[i, j]))

    # Prikazati sabiranje i mnozenje:
    # Adds two images, dividing the result by scale and adding the offset. If omitted, scale defaults to 1.0, and offset to 0.0. 
    # At least one of the images must have mode "1".
    # Rezultujuci pixel se racuna prema formuli: out = ((image1 + image2) / scale + offset)
    for s in (0.1, 1, 5, 10, 20):
        imgS = ImageChops.add(imgJ, imgM, s)
        imgS.show()

    # Superimposes two images on top of each other.
    # If you multiply an image with a solid black image, the result is black. 
    # If you multiply with a solid white image, the image is unaffected. 
    # Rezultujuci pixel se racuna prema formuli: out = image1 * image2 / MAX
    imgMul = ImageChops.multiply(imgJ, imgM)
    imgMul.show()
