Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import skimage
- from skimage import io,data
- # read data
- with open('test.txt') as f:
- lines=f.read()
- data=lines.splitlines()
- R_MEAN=122.67891434
- G_MEAN=116.66876762
- B_MEAN=104.00698793
- WIDTH=227
- HEIGHT=227
- a=np.asarray(data)
- a.resize([3,WIDTH,HEIGHT])
- # add mean value
- mean=np.concatenate((np.full((WIDTH,HEIGHT),B_MEAN),np.full((WIDTH,HEIGHT),G_MEAN),np.full((WIDTH,HEIGHT),R_MEAN)),axis=0)
- mean.resize([3,WIDTH,HEIGHT])
- a=a.astype(np.float64)
- pic=a+mean
- # change the channel from [3,WIDTH,HEIGHT] to [WIDTH,HEIGHT,3]
- picWHC = pic.swapaxes(0, 1).swapaxes(1,2)
- # change the bgr to rgb
- picRGB=picWHC[:, :, (2, 1, 0)]
- picRGB=picRGB/255
- picRGB=np.clip(picRGB,0,1)
- # show and save picture
- io.imsave('test.jpg',picRGB)
Add Comment
Please, Sign In to add comment