Exemplo n.º 1
0
operationPath = "D:\pythonworkspace\TensorflowTraining\exercises\Shen\Practice\ACFdata\Src"
os.chdir(operationPath)

IR_database = os.path.join(os.path.dirname(operationPath), 'IR_database')
IR_logs = os.path.join(os.path.dirname(operationPath), 'IR_logs')
IR_model = os.path.join(os.path.dirname(operationPath), 'IR_Models')

trainDir = os.path.join(IR_database, 'TrainingData', 'TrainFilted10\\')
validateDir = os.path.join(IR_database, 'ValidateData', 'ValidateFilted6\\')
testDir = os.path.join(IR_database, 'TestData', 'TestFilted6\\')

trainLogs = os.path.join(IR_logs, 'IR_Trainlogs', TrainingPlan, DATE)
testLogs = os.path.join(IR_logs, 'IR_testlogs', TrainingPlan, DATE)
modelDir = os.path.join(IR_model, TrainingPlan, DATE)
makeDir.mkdir(modelDir)

#loadModelDir = os.path.join(IR_model,TrainingPlan,'2017-12-27-11-42','IR.ckpt-4999')
#loadModelDir = os.path.join(IR_model,TrainingPlan,'2017-12-27-13-02','IR.ckpt-4999')

#Input Parameter#
IMAGE_WIDTH = 128
IMAGE_HEIGHT = 128
IMAGE_CHANNEL = 3

#Inference Parameter#
size_in = 0
size_out = 0
CLASS_NUM = 2

#Training Parameter#
Exemplo n.º 2
0
def image_augment(filename,angle=None,luminance=None,Contrast=None):
    #img = Image.open(filename)
    img = cv2.imread(filename)
    name = filename.split('_')
    path = os.getcwd()
    currentdir = path.split('\\')    
    paraent_path = os.path.dirname(path)    
    if angle is not None:
        ropath = os.path.join(paraent_path,currentdir[-1]+'_rotate')
        rodirsuccess = mkdir(ropath)
        for a in angle:
#            img = img.rotate(a)
            rows,cols,channels = img.shape
            M = cv2.getRotationMatrix2D((cols/2,rows/2),a,1)
            dst = cv2.warpAffine(img,M,(cols,rows))
            rotation_name = name[0]+'_ro'+str(a)
            for n in name[1:]:
                rotation_name+=('_'+n)         
                save_path = os.path.join(ropath,rotation_name)
            try:
#                img.save(save_path)
                cv2.imwrite(save_path,dst)
            except IOError:
                print("cannot rotation")
    else:
        #print("Don't do any rotation")
        pass
    
    if luminance is not None:
        lupath = os.path.join(paraent_path,currentdir[-1]+'_luminance')
        ludirsuccess = mkdir(lupath)
        for l in luminance:
            img = ImageEnhance.Brightness(img).enhance(l)
            luminance_name = name[0]+'_lu'+str(l)
            for n in name[1:]:
                luminance_name+=('_'+n)         
                save_path = os.path.join(lupath,luminance_name)
            try:
                img.save(save_path)
            except IOError:
                print("cannot enhance luminance")
    else:
        #print("Don't do any lumiance enhancement")
        pass
        
    if Contrast is not None:
        copath = os.path.join(paraent_path,currentdir[-1]+'_contrast')
        codirsuccess = mkdir(copath)
        for C in Contrast:
            img = ImageEnhance.Contrast(img).enhance(C)
            contrast_name = name[0]+'_co'+str(C)
            for n in name[1:]:
                contrast_name+=('_'+n)         
                save_path = os.path.join(copath,contrast_name)
            try:
                img.save(save_path)
            except IOError:
                print("cannot enhance contrast")
    else:
        #print("Don't do any contrast enhancement")
        pass