def add_noise(out_dir, image_path, channel, sigma):
    file_list = glob.glob((image_path + '*'))
    if (not os.path.exists(out_dir)):
        os.makedirs(out_dir)
    for file in file_list:
        print('Adding noise to: ', file)
        if (channel == 3):
            img_clean = (np.array(Image.open(file), dtype='float32') / 255.0)
        else:
            img_clean = np.expand_dims((np.array(Image.open(file).convert('L'), dtype='float32') / 255.0), axis=2)
        np.random.seed(0)
        img_test = (img_clean + np.random.normal(0, (sigma / 255.0), img_clean.shape).astype(np.float32))
        img_test = np.expand_dims(img_test.transpose((2, 0, 1)), 0)
        filename = file.split('/')[(- 1)].split('.')[0]
        img_test.tofile(os.path.join(out_dir, (filename + '_noise.bin')))
def add_noise(out_dir, image_path, channel, sigma):
    file_list = glob.glob((image_path + '*'))
    if (not os.path.exists(out_dir)):
        os.makedirs(out_dir)
    for file in file_list:
        print('Adding noise to: ', file)
        if (channel == 3):
            img_clean = (np.array(Image.open(file), dtype='float32') / 255.0)
        else:
            img_clean = np.expand_dims((np.array(Image.open(file).convert('L'), dtype='float32') / 255.0), axis=2)
        np.random.seed(0)
        img_test = (img_clean + np.random.normal(0, (sigma / 255.0), img_clean.shape).astype(np.float32))
        img_test = np.expand_dims(img_test.transpose((2, 0, 1)), 0)
        filename = file.split('/')[(- 1)].split('.')[0]
        img_test.tofile(os.path.join(out_dir, (filename + '_noise.bin')))