标签:最大 过程 plot ctr bic numpy 今天 解决 import
今天帮师姐解决一个bug,测试了Python图像resize前后颜色不一致问题。
代码片段执行的功能:图像指定倍数超分辨率,输入为[0-1] float型数据,输出为格式不限的图像
bug:输入图像与输出图像颜色不一致
1 import h5py 2 import numpy as np 3 import matplotlib.pyplot as plt 4 from PIL import Image 5 from scipy import misc 6 7 8 def get_result_array(): 9 file_name = "./butterfly_GT.bmp" 10 img_no_expand = misc.imread(file_name, flatten=False, mode=‘YCbCr‘) 11 img_no_expand = img_no_expand / 255.0 12 # img_no_expand = np.uint8(img_no_expand*255) 13 h, w = img_no_expand.shape[:2] 14 print(img_no_expand.shape) 15 h *= 2 16 w *= 2 17 data = list() 18 19 data.append(misc.imresize(img_no_expand[:, :, 0], [h, w], ‘bicubic‘)[:,:,None]) 20 data.append(misc.imresize(img_no_expand[:, :, 1], [h, w], ‘bicubic‘)[:,:,None]) 21 data.append(misc.imresize(img_no_expand[:, :, 2], [h, w], ‘bicubic‘)[:,:,None]) 22 data_out = np.concatenate(data, axis=2) 23 img = misc.toimage(arr=data_out, mode="YCbCr") 24 img.save("out_3.jpg") 25 26 27 if __name__==‘__main__‘: 28 get_result_array()
运行代码:
左图为输入图像,右图为输出图像。为了便于对比,把输出图像缩放至与输入图像一致,由图可见,输出图像色彩严重失真。
1 import h5py 2 import numpy as np 3 import matplotlib.pyplot as plt 4 from PIL import Image 5 from scipy import misc 6 7 8 def get_result_array(): 9 file_name = "./butterfly_GT.bmp" 10 img_no_expand = misc.imread(file_name, flatten=False, mode=‘YCbCr‘) 11 img_no_expand = img_no_expand / 255.0 12 # img_no_expand = np.uint8(img_no_expand*255) 13 h, w = img_no_expand.shape[:2] 14 print(img_no_expand.shape) 15 h *= 2 16 w *= 2 17 data = list() 18 data.append(misc.imresize(img_no_expand[:, :, 0], [h, w], ‘bicubic‘, mode="F")[:,:,None]) 19 data.append(misc.imresize(img_no_expand[:, :, 1], [h, w], ‘bicubic‘, mode="F")[:,:,None]) 20 data.append(misc.imresize(img_no_expand[:, :, 2], [h, w], ‘bicubic‘, mode="F")[:,:,None]) 21 data_out = np.concatenate(data, axis=2) 22 img = misc.toimage(arr=data_out, mode="YCbCr") 23 img.save("out_4.jpg") 24 25 26 if __name__==‘__main__‘: 27 get_result_array()
标签:最大 过程 plot ctr bic numpy 今天 解决 import
原文地址:http://www.cnblogs.com/nwpuxuezha/p/7236155.html