Hello,
I am interested in measuring the (shortest) distance of multiple particles to a manually drawn straight line in an image. This could be done manually for each particle, but the results would be less accurate and the process very time-consuming. Since each image contains between 50 and 100 well defined particles, the manual approach is not reasonable. Any ideas? Thanks for your input F Javier Diez-Guerra, PhD Profesor Titular Centro de Biologia Molecular Severo Ochoa Facultad de Ciencias, Universidad Autónoma Ctra Colmenar Viejo Km 15 Cantoblanco, 28049 Madrid SPAIN phone: +34 91 4978051 Fax: +34 91 4978087 e-mail: [hidden email] |
Hi Javier,
> I am interested in measuring the (shortest) distance of multiple > particles to a manually drawn straight line in an image. This could be > done manually for each particle, but the results would be less > accurate and the process very time-consuming. Since each image > contains between 50 and 100 well defined particles, the manual > approach is not reasonable. > > Any ideas? I wrote some Java code (below) to measure the distance between a point and a line (either a "true" line or a line segment). You could take this code, throw it into a Java source file, then write a plugin or macro that for each particle, measures the distance to the user-defined line and spits it out to a text file or something. (I am assuming there is one manually drawn line, and you want the distance to that same line for all 50-100 particles?) Good luck, -Curtis ----- /** * Computes the minimum distance between the point v and the line a-b. * * @param a Coordinates of the line's first endpoint * @param b Coordinates of the line's second endpoint * @param v Coordinates of the standalone endpoint * @param segment Whether distance computation should be * constrained to the given line segment */ public static double getDistance(double[] a, double[] b, double[] v, boolean segment) { int len = a.length; // vectors double[] ab = new double[len]; double[] va = new double[len]; for (int i=0; i<len; i++) { ab[i] = a[i] - b[i]; va[i] = v[i] - a[i]; } // project v onto (a, b) double numer = 0; double denom = 0; for (int i=0; i<len; i++) { numer += va[i] * ab[i]; denom += ab[i] * ab[i]; } double c = numer / denom; double[] p = new double[len]; for (int i=0; i<len; i++) p[i] = c * ab[i] + a[i]; // determine which point (a, b or p) to use in distance computation int flag = 0; if (segment) { for (int i=0; i<len; i++) { if (p[i] > a[i] && p[i] > b[i]) flag = a[i] > b[i] ? 1 : 2; else if (p[i] < a[i] && p[i] < b[i]) flag = a[i] < b[i] ? 1 : 2; else continue; break; } } double sum = 0; for (int i=0; i<len; i++) { double q; if (flag == 0) q = p[i] - v[i]; // use p else if (flag == 1) q = a[i] - v[i]; // use a else q = b[i] - v[i]; // flag == 2, use b sum += q * q; } return Math.sqrt(sum); } |
In reply to this post by F Javier Díez Guerra
This was rejected the first time because of the word "Get" at the beginning.
>Get all points along the line and put them in an array. This works for >any shape line or edge, but you have to manually have it fill in missing >points if the line is horizontal or vertical. > >Calculate the distance from each point of interest to every point on the >line and save only the smallest distance in a different array. > >This is a brute force approach that increases in time by n squared but >unless you have thousands of points, the computer can handle it fine. > > >At 06:53 PM 02/22/06 +0100, you wrote: >>Hello, >> >>I am interested in measuring the (shortest) distance of multiple >>particles to a manually drawn straight line in an image. This could be >>done manually for each particle, but the results would be less accurate >>and the process very time-consuming. Since each image contains between 50 >>and 100 well defined particles, the manual approach is not reasonable. >> >>Any ideas? >> >>Thanks for your input >> >> >> >>F Javier Diez-Guerra, PhD >>Profesor Titular >>Centro de Biologia Molecular Severo Ochoa >>Facultad de Ciencias, Universidad Autónoma >>Ctra Colmenar Viejo Km 15 >>Cantoblanco, 28049 Madrid >>SPAIN >> >>phone: +34 91 4978051 >>Fax: +34 91 4978087 >>e-mail: [hidden email] > >____________________________________________________________________________ >Michael Cammer Analytical Imaging Facility Albert Einstein Coll. of Med. >Jack & Pearl Resnick Campus 1300 Morris Park Ave. Bronx, NY 10461 >(718) 430-2890 Fax: 430-8996 URL: http://www.aecom.yu.edu/aif/ > **This electronic transmission contains information that is privileged.** > > ____________________________________________________________________________ Michael Cammer Analytical Imaging Facility Albert Einstein Coll. of Med. Jack & Pearl Resnick Campus 1300 Morris Park Ave. Bronx, NY 10461 (718) 430-2890 Fax: 430-8996 URL: http://www.aecom.yu.edu/aif/ **This electronic transmission contains information that is privileged.** |
Free forum by Nabble | Edit this page |