#Abdullah Abuolaim
#Images to 4D Numpy array of size (t x s) x h x w x c. 

import numpy as np
import cv2
from copy import deepcopy

scene=['Scene1','Scene2','Scene3','Scene4','Scene5','Scene6','Scene7','Scene8','Scene9','Scene10']
incI=1
zFill=2
imgEx='.jpg'
focusDisArr=np.load('focusDisArr.npy')

imgSize = cv2.imread('Data\\'+scene[0]+'\\IMAGE_'+str(int(0+incI)).zfill(zFill)+'_'+focusDisArr[0]+imgEx)
widthToScale=1500
widPercent = (widthToScale/float(imgSize.shape[1]))
heightToScale = int((float(imgSize.shape[0])*float(widPercent)))

for sc in range(0,len(scene)):
    print(scene[sc])
    if scene[sc]=='Scene1' or scene[sc]=='Scene2' or scene[sc]=='Scene3'or scene[sc]=='Scene4':
        numOfFrames=51
    elif scene[sc]=='Scene5':
        numOfFrames=61
    elif scene[sc]=='Scene6' or scene[sc]=='Scene7' or scene[sc]=='Scene8':
        numOfFrames=71
    elif scene[sc]=='Scene9' or scene[sc]=='Scene10':
        numOfFrames=91
    
    allImages=[]
    for i in range (0,numOfFrames):
        print(i)
        for j in range(0,len(focusDisArr)):
            tempImg = cv2.imread('Data\\'+scene[sc]+'\\IMAGE_'+str(int(i+incI)).zfill(zFill)+'_'+focusDisArr[j]+imgEx)
            restempImg=cv2.resize(tempImg,(widthToScale,heightToScale), interpolation = cv2.INTER_CUBIC)
            bCh, rCh = deepcopy(restempImg[:,:,0]),deepcopy(restempImg[:,:,2])
            restempImg[:,:,0], restempImg[:,:,2] = rCh, bCh
            allImages.append(restempImg)
    
    np.save(scene[sc]+'_w1.5k.npy', np.asarray(allImages))