image_probe.py 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. """Probe image intensities along a set of radii"""
  2. from vedo import Image, dataurl, Circle, Lines, show
  3. from vedo.pyplot import plot
  4. import numpy as np
  5. img = Image(dataurl+'images/spheroid.jpg')
  6. cpt = [580,600,0]
  7. circle = Circle(cpt, r=500, res=36).wireframe()
  8. pts = circle.points # 3d coords of the points of the circle
  9. centers = np.zeros_like(pts) + cpt # create the same amount of center coords
  10. lines = Lines(centers, pts, res=50) # create Lines with 50 pts of resolution each
  11. lines.interpolate_data_from(img, n=3) # interpolate all msh data onto the lines
  12. print(lines.pointdata) # print all available arrays
  13. rgb = lines.pointdata['JPEGImage'] # extract the rgb intensities
  14. intensities = np.sum(rgb, axis=1) # sum the rgb values into one single intensity
  15. intensities_ray = np.split(intensities, 36) # split array so we can index any radius
  16. mean_intensity = np.mean(intensities_ray, axis=0) # compute the average intensity
  17. # add some optional plotting here:
  18. fig = plot(
  19. mean_intensity,
  20. lc='black', lw=5, spline=True,
  21. xtitle='radial distance', ytitle='intensity', aspect=16/9,
  22. )
  23. for i in range(0,36, 3):
  24. fig += plot(intensities_ray[i], lc=i, lw=1, like=fig)
  25. fig.scale(21).shift(60,-800) # scale up and move plot below the image
  26. show(img, circle, lines, fig, __doc__, size=(625,1000), zoom=1.5)