1

I am trying to plot the 2nd moments onto a image file (the image file is a numpy array for brightness distribution). I have a rough understanding that 2nd moment is sort of like moment of inertia (Ixx,Iyy) which is a tensor but I am not too sure how to calculate it and how it would translate into two intersecting lines with the centroid at its intersection. I tried using scipy.stats.mstats.moment but I am unsure what to put as axis if I just want two 2nd moments that intersects at centroid.

Also it returns an array but I am not exactly sure what the values in the array signify, and how that relate to what I am going to plot (because the scatter method in the plotting module takes in at least 2 corresponding values in order to be plotted) ?

Thank you.

ROBOTPWNS
  • 4,299
  • 6
  • 23
  • 36
  • Not to plug one of my own answers, but see: http://stackoverflow.com/questions/9005659/compute-eigenvectors-of-image-in-python/9007249#9007249 Basically, `scipy.stats.moment` expects x,y,z coordinates. You can easily pass in an array of i,j,z (where i,j are the row, column coords and z is the brightness - See the first example in the linked question), but this is computationally inefficient for a regularly-gridded image. For regularly-gridded images, you can make a few shortcuts that will speed things up for large images. – Joe Kington Mar 10 '14 at 12:30
  • @JoeKington I tried calculating moments about x,y and then plotting them, but the plot seems completely irrelavant to the image in my brightness distribution 'x_moment =stats.moment(data, moment=2,axis=0) ; y_moment =stats.moment(data, moment=2,axis=1) ;import matplotlib.pyplot as plt ;img_plot = ;plt.imshow(data,cmap=cm.gray, norm = log_norm,origin="lower") ;for yindex,yvalue in np.ndenumerate(y_moment): ;for xindex, xvalue in np.ndenumerate(x_moment): ;plt.scatter(yvalue,xvalue, c='r', s=10) plt.show() ` – ROBOTPWNS Mar 10 '14 at 19:53

0 Answers0