
calculate the centre of mass of an image

andyfaff
Function/c centreofMass2D(w,xx,yy) wave w,xx,yy //w is a 2D image wave. //xx and yy are abscissa and ordinates of image wave //xx and yy should be 1 point larger than w, as we are considering an image wave //return C-O-M via a complex value variable ii,jj,totalmass=0,sumrmx=0,sumrmy=0 for(ii=0;ii<dimsize(w,0);ii+=1) for(jj=0;jj<dimsize(w,1);jj+=1) totalmass+=w[ii][jj] sumrmx += w[ii][jj]*(xx[ii]+xx[ii+1])/2 sumrmy+=w[ii][jj]*(yy[jj]+yy[jj+1])/2 endfor endfor return cmplx(sumrmx/totalmass,sumrmy/totalmass) End

Forum

Support

Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More