# Prepare my dataset for Digital Pathology

import os
import math
import cv2

import pdb

rootFolder = "F:\DataBase\LymphnodePathology"
trainFolder = rootFolder + "\\trainDataSet"
testFolder = rootFolder + "\\testDataSet"

srcTrainFilePath = trainFolder + "\\20X\\"
dstTrainFilePath = trainFolder + "\\5X\\"
srcTestFilePath  = testFolder  + "\\20X\\"
dstTestFilePath  = testFolder  + "\\5X\\"

factor = 4

if __name__ == '__main__':
    srcTrainFileNameList = os.listdir(srcTrainFilePath)
    srcTestFileNameList  = os.listdir(srcTestFilePath)

    for srcTrainFileName in srcTrainFileNameList:
        srcTrainImage = cv2.imread(srcTrainFilePath + srcTrainFileName)

        imgHeight, imgWidth, _ = srcTrainImage.shape
        newWidth = int(imgWidth / factor)
        newHeight = int(imgHeight / factor)
        newSize = (newWidth, newHeight)

        dstTrainImage = cv2.resize(srcTrainImage, newSize, interpolation=cv2.INTER_AREA)

        print("Train File Name : %s, (%d, %d) => (%d, %d)" %(srcTrainFileName, imgWidth, imgHeight, newSize[0], newSize[1]))
        cv2.imwrite(dstTrainFilePath + srcTrainFileName, dstTrainImage)

    for srcTestFileName in srcTestFileNameList:
        srcTestImage = cv2.imread(srcTestFilePath + srcTestFileName)

        imgHeight, imgWidth, _ = srcTestImage.shape
        newWidth = int(imgWidth / factor)
        newHeight = int(imgHeight / factor)
        newSize = (newWidth, newHeight)

        dstTestImage = cv2.resize(srcTestImage, newSize, interpolation=cv2.INTER_AREA)

        print("Test File Name : %s, (%d, %d) => (%d, %d)" %(srcTestFileName, imgWidth, imgHeight, newSize[0], newSize[1]))
        cv2.imwrite(dstTestFilePath + srcTestFileName, dstTestImage)

[((21, 27, 21, 55), 'os.listdir', 'os.listdir', ({(21, 38, 21, 54): 'srcTrainFilePath'}, {}), '(srcTrainFilePath)', False, 'import os\n'), ((22, 27, 22, 54), 'os.listdir', 'os.listdir', ({(22, 38, 22, 53): 'srcTestFilePath'}, {}), '(srcTestFilePath)', False, 'import os\n'), ((25, 24, 25, 71), 'cv2.imread', 'cv2.imread', ({(25, 35, 25, 70): 'srcTrainFilePath + srcTrainFileName'}, {}), '(srcTrainFilePath + srcTrainFileName)', False, 'import cv2\n'), ((32, 24, 32, 88), 'cv2.resize', 'cv2.resize', (), '', False, 'import cv2\n'), ((35, 8, 35, 71), 'cv2.imwrite', 'cv2.imwrite', ({(35, 20, 35, 55): '(dstTrainFilePath + srcTrainFileName)', (35, 57, 35, 70): 'dstTrainImage'}, {}), '(dstTrainFilePath + srcTrainFileName, dstTrainImage)', False, 'import cv2\n'), ((38, 23, 38, 68), 'cv2.imread', 'cv2.imread', ({(38, 34, 38, 67): 'srcTestFilePath + srcTestFileName'}, {}), '(srcTestFilePath + srcTestFileName)', False, 'import cv2\n'), ((45, 23, 45, 86), 'cv2.resize', 'cv2.resize', (), '', False, 'import cv2\n'), ((48, 8, 48, 68), 'cv2.imwrite', 'cv2.imwrite', ({(48, 20, 48, 53): '(dstTestFilePath + srcTestFileName)', (48, 55, 48, 67): 'dstTestImage'}, {}), '(dstTestFilePath + srcTestFileName, dstTestImage)', False, 'import cv2\n')]