image_rgba.py 795 B

1234567891011121314151617181920212223242526272829
  1. """Example plot of 2 images containing an
  2. alpha channel for modulating the opacity"""
  3. #Credits: https://github.com/ilorevilo
  4. from vedo import Image, show
  5. import numpy as np
  6. rgbaimage1 = np.random.rand(50, 50, 4) * 255
  7. alpharamp = np.linspace(0, 255, 50).astype(int)
  8. rgbaimage1[:, :, 3] = alpharamp
  9. rgbaimage2 = np.random.rand(50, 50, 4) * 255
  10. rgbaimage2[:, :, 3] = alpharamp[::-1]
  11. img1 = Image(rgbaimage1, channels=4)
  12. img2 = Image(rgbaimage2, channels=4).z(12)
  13. show(img1, img2, __doc__, axes=7, viewup="z").close()
  14. # Second example: a b&w image from a numpy array
  15. img = np.zeros([512,512])
  16. img[0:256, 0:256] = 0
  17. img[0:256, 256:] = 64
  18. img[256:, 0:256] = 128
  19. img[256:, 256:] = 255
  20. img = img.transpose(1,0)
  21. img3 = Image(img)
  22. show(img3, mode="image", bg=(0.4,0.5,0.6), axes=1).close()