from PIL import Image
import matplotlib.pyplot as plt
import matplotlib.image as imglib
import numpy as np

"""
img = Image.open("image_1.jpg")
width, height = img.size
print(width, height)
img.show()
"""

"""
img = Image.open("image_1.jpg")
width, height = img.size
img45 = img.rotate(45)
area = (width/2-200, height/2-200, width/2+200, height/2+200)
img_crop = img.crop(area)
newsize = (width//4, height//4)
img_resize = img.resize(newsize)
img_transpose = img.transpose(Image.FLIP_LEFT_RIGHT)
img45.save("data/image_1_45.jpg")
img_crop.save("data/image_1_cropped.jpg")
img_resize.save("data/image_1_resized.jpg")
print("Old image size:", img.size)
print("New image size:", img_resize.size)
img45.show()
img_crop.show()
img_resize.show()
img_transpose.show()
"""

# Black and White conversion

"""
img = Image.open("image_1.jpg")
img1 = img.convert("L")
img2 = img.convert("1")
img1.show()
img2.show()
"""

# Breaking apart image to RGB

"""
img = Image.open("image_1.jpg")
width, height = img.size
data = img.getdata()
R = []
G = []
B = []
for i in data:
    R.append((i[0], 0, 0))
    G.append((0, i[1], 0))
    B.append((0, 0, i[2]))
imgR = Image.new(mode = "RGB", size = (width, height))
imgG = Image.new(mode = "RGB", size = (width, height))
imgB = Image.new(mode = "RGB", size = (width, height))
imgR.putdata(R)
imgG.putdata(G)
imgB.putdata(B)
imgR.show()
imgG.show()
imgB.show()
"""


# Convert to binary

"""
img = Image.open("image_1.jpg")
width, height = img.size
data = img.getdata()
BIN = []
for i in data:
    avg1 = (i[0]+i[1]+i[2])/3
    if avg1 < 60:
        BIN.append((255, 255, 255))
    else:
        BIN.append((0, 0, 0))

imgBIN = Image.new(mode = "RGB", size = (width, height))
imgBIN.putdata(BIN)
imgBIN.show()
"""
# Create an image

"""
pixels =[
[ [255,0,0],[255,255,255],[0,0,0],[0,255,0],[255,0,255] ],
[ [255,255,0],[0,255,255],[0,0,255],[100,100,100],[50,50,50] ]
]
array = np.array(pixels, dtype=np.uint8)
plt.imshow(array)
plt.show()
"""

# Overlay pixels on an image


img= imglib.imread("image_1.jpg")
data = img.copy()
data[0:100,0:100]=[255, 0, 0]
data[100:200,100:200]=[0, 255, 0]
data[200:300,200:300]=[0, 0, 255]
data[300:400,300:400]=[255, 0, 255]
data[400:500,400:500]=[0, 255, 255]
data[500:600,500:600]=[255, 255, 255]
plt.imshow(data)
plt.show()




