Guest User

Untitled

a guest
Mar 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import numpy as np
  2. import skimage
  3. from skimage import io,data
  4. # read data
  5. with open('test.txt') as f:
  6. lines=f.read()
  7. data=lines.splitlines()
  8. R_MEAN=122.67891434
  9. G_MEAN=116.66876762
  10. B_MEAN=104.00698793
  11. WIDTH=227
  12. HEIGHT=227
  13. a=np.asarray(data)
  14. a.resize([3,WIDTH,HEIGHT])
  15. # add mean value
  16. mean=np.concatenate((np.full((WIDTH,HEIGHT),B_MEAN),np.full((WIDTH,HEIGHT),G_MEAN),np.full((WIDTH,HEIGHT),R_MEAN)),axis=0)
  17. mean.resize([3,WIDTH,HEIGHT])
  18. a=a.astype(np.float64)
  19. pic=a+mean
  20. # change the channel from [3,WIDTH,HEIGHT] to [WIDTH,HEIGHT,3]
  21. picWHC = pic.swapaxes(0, 1).swapaxes(1,2)
  22. # change the bgr to rgb
  23. picRGB=picWHC[:, :, (2, 1, 0)]
  24. picRGB=picRGB/255
  25. picRGB=np.clip(picRGB,0,1)
  26. # show and save picture
  27. io.imsave('test.jpg',picRGB)
Add Comment
Please, Sign In to add comment