大批量图像处理(9)———对抗样本噪声展示

攻击前的图片
大批量图像处理(9)———对抗样本噪声展示_第1张图片
攻击后的图片
大批量图像处理(9)———对抗样本噪声展示_第2张图片
作差后归一化放大

大批量图像处理(9)———对抗样本噪声展示_第3张图片

import csv
import os
from PIL import Image
import tensorflow as tf
from scipy.misc import imread
from scipy.misc import imsave
import numpy as np
input_dir = "/home/NEWDISK/CAAD/wujiekd/a_lunwen/ceshi_6"  #原图片
attack_dir = "/home/NEWDISK/CAAD/wujiekd/a_lunwen/ceshi_6strong"  #对抗样本的图片
output_dir="/home/NEWDISK/CAAD/wujiekd/cut_strong"  #输出路径

def output_noise(input_dir):
    filelist = os.listdir(input_dir)
    image=0
    for item in filelist:
        keda_str=input_dir+'/'+item
        print(item)
        print(keda_str)
        if item.endswith('.png'):
            image_kedaa = imread(keda_str, mode='RGB').astype(np.float) / 255.0
            picture_adress = mix_dir + '/' + item
            if os.path.exists(picture_adress):
                img2 = imread(picture_adress, mode='RGB').astype(np.float) / 255.0
                image = image_kedaa-img2
        else:
            continue
        print(image)
        print(image.shape)
        a=np.max(image)
        b=np.min(image)
        image=(image-b)/(a-b)
        with tf.gfile.Open(os.path.join(output_dir, item), 'wb') as f:
            imsave(f, image, format='png')

if __name__ == '__main__':
    output_noise(input_dir)

你可能感兴趣的:(笔记)