def testImg(infile='../show/pic_with_noise/lena_7.png', infile_raw='../pic_raw/lena.png', filename='lena'): im_test = np.array(Image.open(infile).convert('L')).reshape(1, pixelNum) scipy.misc.imsave(infile, im_test.reshape(picSize[0], picSize[1])) im_test = im_test.astype('float32') / 255.0 im_label = np.array(Image.open(infile_raw).convert('L')).reshape( 1, pixelNum) '''开始预测''' pred = sess.run(y, feed_dict={x: im_test, keep_prob: 1.0}) im_out = im_test - pred im_out = im_out * 255.0 im_out = im_out.astype(int) for i in range(im_out.shape[0]): for j in range(im_out.shape[1]): if im_out[i][j] < 0: im_out[i][j] = 0 elif im_out[i][j] > 255: im_out[i][j] = 255 pred = pred * 255.0 pred = pred.astype(int) for i in range(pred.shape[0]): for j in range(pred.shape[1]): if pred[i][j] < 0: pred[i][j] = -pred[i][j] elif pred[i][j] > 255: pred[i][j] = 255 scipy.misc.imsave('../vis/0' + filename + '_test.jpg', im_test.reshape(picSize[0], picSize[1])) scipy.misc.imsave('../vis/1' + filename + '.jpg', im_out.reshape(picSize[0], picSize[1])) scipy.misc.imsave('../vis/3' + filename + '_noise.jpg', pred.reshape(picSize[0], picSize[1])) scipy.misc.imsave('../vis/2' + filename + '_label.jpg', im_label.reshape(picSize[0], picSize[1])) print("Before ", end=':') getSNR.getSNR( Image.open(r'../vis/0lena_test.jpg').convert('L'), Image.open(r'../vis/2lena_label.jpg').convert('L')) print("After ", end=':') getSNR.getSNR( Image.open(r'../vis/1lena.jpg').convert('L'), Image.open(r'../vis/2lena_label.jpg').convert('L'))
from src import test_rgb_big import os from PIL import Image from src import getSNR pic_with_noise_path = r'../show/Test12_with_noise/' pic_save_path = r'../show/Test12_after/' noise_path = r'../show/noise/' pic_raw_path = r'../show/Test12/' infile = '09.png' print(infile) #test_rgb_big.testImg(Image.open(pic_with_noise_path + infile).convert('RGB'), pic_save_path, infile, noise_path) print(getSNR.getSNR(Image.open(pic_save_path + infile), Image.open(pic_raw_path + infile))) for infile in os.listdir(pic_save_path): print(infile) print(getSNR.getSNR(Image.open(pic_save_path + infile), Image.open(pic_raw_path + infile)))
print("After ", end=':') getSNR.getSNR( Image.open(r'../vis/1lena.jpg').convert('L'), Image.open(r'../vis/2lena_label.jpg').convert('L')) scipy.misc.imsave('../vis/1lena.jpg', im_out.reshape(256, 256)) scipy.misc.imsave('../vis/3lena_noise.jpg', pred.reshape(256, 256)) scipy.misc.imsave('../vis/2lena_label.jpg', im_label.reshape(256, 256)) print(pred) print(im_out) print(im_label) print("Before ", end=':') getSNR.getSNR( Image.open(r'../vis/0lena_test.jpg').convert('L'), Image.open(r'../vis/2lena_label.jpg').convert('L')) print("After ", end=':') getSNR.getSNR( Image.open(r'../vis/1lena.jpg').convert('L'), Image.open(r'../vis/2lena_label.jpg').convert('L')) print("Ps ", end=':') getSNR.getSNR( Image.open(r'../vis/lena_ps.jpg').convert('L'), Image.open(r'../vis/2lena_label.jpg').convert('L')) print("----------------------------------") testImg(infile=r'../pic_gauss/279.png', infile_raw=r'../pic_raw/279.png', filename='new')