Guest User

Untitled

a guest
Aug 9th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. import Mrc
  2. import datadoc
  3. import numpy as np
  4. import pylab
  5. import scipy.stats.stats
  6. import sys
  7.  
  8. points = []
  9. imageShape = None
  10. for filename in sys.argv[1:]:
  11.     data = datadoc.DataDoc(Mrc.bindFile(filename)).imageArray[0,0,0]
  12.     print filename, "%d" % data.mean()
  13.     imageShape = data.shape
  14.     points.append((data.mean(), data))
  15. points.sort(lambda a, b: cmp(a[0], b[0]))
  16.  
  17. xVals = np.array([item[0] for item in points])
  18. yVals = np.array([item[1] for item in points])
  19. yVals.shape = len(yVals), np.product(imageShape)
  20.  
  21. result, residuals, rank, singular_values, rcond = np.polyfit(xVals, yVals, 1, full = True)
  22. slopes = result[0]
  23. intercepts = result[1]
  24.  
  25. slopes.shape = imageShape
  26. intercepts.shape = imageShape
  27. yVals.shape = (len(yVals),) + imageShape
  28.  
  29. result = np.zeros(imageShape, dtype = np.float32)
  30. for i in xrange(slopes.shape[0]):
  31.     print i
  32.     for j in xrange(slopes.shape[1]):
  33.         xen = xVals * slopes[i,j] + intercepts[i,j]
  34.         yen = yVals[:,i,j]
  35.         result[i,j] = scipy.stats.stats.pearsonr(xen, yen)[0]
  36.  
  37. result.shape = np.product(result.shape)
  38. yVals.shape = len(xVals), result.shape
  39.  
  40. print result.shape, result.dtype
  41. indices = np.argsort(result) # This fails
  42.  
  43. colors = ['r', 'g', 'b', 'c', 'm', 'y', 'k']
  44. for i in indices[:len(colors)]:
  45.     pylab.plot(xVals, yVals[:, i], colors[i])
  46.  
  47. pylab.grid()
  48. pylab.xlabel('Mean image intensity')
  49. pylab.ylabel('Specific pixel intensity')
  50. pylab.title("Response curves for %d most nonlinear pixels" % len(colors))
  51. pylab.show()
Advertisement
Add Comment
Please, Sign In to add comment