# 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)

[((460, 488), 'os.listdir', 'os.listdir', (['srcTrainFilePath'], {}), '(srcTrainFilePath)\n', (470, 488), False, 'import os\n'), ((516, 543), 'os.listdir', 'os.listdir', (['srcTestFilePath'], {}), '(srcTestFilePath)\n', (526, 543), False, 'import os\n'), ((619, 666), 'cv2.imread', 'cv2.imread', (['(srcTrainFilePath + srcTrainFileName)'], {}), '(srcTrainFilePath + srcTrainFileName)\n', (629, 666), False, 'import cv2\n'), ((872, 936), 'cv2.resize', 'cv2.resize', (['srcTrainImage', 'newSize'], {'interpolation': 'cv2.INTER_AREA'}), '(srcTrainImage, newSize, interpolation=cv2.INTER_AREA)\n', (882, 936), False, 'import cv2\n'), ((1071, 1134), 'cv2.imwrite', 'cv2.imwrite', (['(dstTrainFilePath + srcTrainFileName)', 'dstTrainImage'], {}), '(dstTrainFilePath + srcTrainFileName, dstTrainImage)\n', (1082, 1134), False, 'import cv2\n'), ((1207, 1252), 'cv2.imread', 'cv2.imread', (['(srcTestFilePath + srcTestFileName)'], {}), '(srcTestFilePath + srcTestFileName)\n', (1217, 1252), False, 'import cv2\n'), ((1456, 1519), 'cv2.resize', 'cv2.resize', (['srcTestImage', 'newSize'], {'interpolation': 'cv2.INTER_AREA'}), '(srcTestImage, newSize, interpolation=cv2.INTER_AREA)\n', (1466, 1519), False, 'import cv2\n'), ((1652, 1712), 'cv2.imwrite', 'cv2.imwrite', (['(dstTestFilePath + srcTestFileName)', 'dstTestImage'], {}), '(dstTestFilePath + srcTestFileName, dstTestImage)\n', (1663, 1712), False, 'import cv2\n')]