Dear Listers,
I have two images with a set of point objects (derived from a previous calculation, i.e. basically, centers of mass of various particles). I want now to calculate the distance of each point (object) in image A to the closest point (object) in image B (and only to this closest one...). I suppose, the code I am looking for should 1) calculate ALL distances from point 1 in image A to ALL points in image B, 2) identify the shortest and 3) return the value of that distance. I had a look at Ben's plugin (http://imagejdocu.tudor.lu/doku.php?id=plugin:analysis:minimum_separation_distance:start) However, this does sort of a different job. On top, I admit that I am not so familiar with java (thanks, Wayne, for the macro language!), so it is not so easy for me to extract the necessary information out of this plugin. Is there anything already available (plugin, macro) that does this job, or at least comes close such that I can build upon it? Or do I have to look more closely at Ben's plugin (maybe someone could point out what I would have to look at!)? Many thanks, Johannes |
Are the xy coordinates of the points in a Results table?
On Tue, May 25, 2010 at 5:54 AM, Johannes-Paul M. Koch < [hidden email]> wrote: > Dear Listers, > > I have two images with a set of point objects (derived from a previous > calculation, i.e. basically, centers of mass of various particles). > > I want now to calculate the distance of each point (object) in image A to > the closest point (object) in image B (and only to this closest one...). > > I suppose, the code I am looking for should 1) calculate ALL distances > from point 1 in image A to ALL points in image B, 2) identify the shortest > and 3) return the value of that distance. > > I had a look at Ben's plugin > ( > http://imagejdocu.tudor.lu/doku.php?id=plugin:analysis:minimum_separation_distance:start > ) > However, this does sort of a different job. On top, I admit that I am not > so familiar with java (thanks, Wayne, for the macro language!), so it is > not so easy for me to extract the necessary information out of this > plugin. > > Is there anything already available (plugin, macro) that does this job, or > at least comes close such that I can build upon it? Or do I have to look > more closely at Ben's plugin (maybe someone could point out what I would > have to look at!)? > > > Many thanks, > Johannes > |
In reply to this post by Johannes-P. Koch
Hi,
assuming that with point objects, you refer to a PointRoi, copy the following BeanShell-snippet into either the Fiji Beanshell Interpreter or save it with the file-ending .bsh and drag it to the Fiji toolbar. import ij.*; import ij.gui.*; points = IJ.getImage().getRoi(); pointsX = points.getXCoordinates(); pointsY = points.getYCoordinates(); for ( i = 0; i < pointsX.length; ++i ) { dMin = Integer.MAX_VALUE; iMin = -1; for ( j = 0; j < pointsX.length; ++j ) { if ( i == j ) continue; dX = pointsX[ j ] - pointsX[ i ]; dY = pointsY[ j ] - pointsY[ i ]; d = dX * dX + dY * dY; if ( dMin > d ) { dMin = d; iMin = j; } } IJ.log( ( i + 1 ) + " " + ( iMin + 1 ) + " " + Math.sqrt( dMin ) ); } It prints n lines with three space separated numbers into the log window: <index> <nearest point index> <minimal distance> Best regards, Stephan On Tue, 2010-05-25 at 14:54 +0200, Johannes-Paul M. Koch wrote: > Dear Listers, > > I have two images with a set of point objects (derived from a previous > calculation, i.e. basically, centers of mass of various particles). > > I want now to calculate the distance of each point (object) in image A to > the closest point (object) in image B (and only to this closest one...). > > I suppose, the code I am looking for should 1) calculate ALL distances > from point 1 in image A to ALL points in image B, 2) identify the shortest > and 3) return the value of that distance. > > I had a look at Ben's plugin > (http://imagejdocu.tudor.lu/doku.php?id=plugin:analysis:minimum_separation_distance:start) > However, this does sort of a different job. On top, I admit that I am not > so familiar with java (thanks, Wayne, for the macro language!), so it is > not so easy for me to extract the necessary information out of this > plugin. > > Is there anything already available (plugin, macro) that does this job, or > at least comes close such that I can build upon it? Or do I have to look > more closely at Ben's plugin (maybe someone could point out what I would > have to look at!)? > > > Many thanks, > Johannes |
Thanks to all of you, got it working nicely!
Johannes On Di, 25.05.2010, 19:12, Stephan Saalfeld wrote: > Hi, > > assuming that with point objects, you refer to a PointRoi, copy the > following BeanShell-snippet into either the Fiji Beanshell Interpreter > or save it with the file-ending .bsh and drag it to the Fiji toolbar. > > > import ij.*; > import ij.gui.*; > > points = IJ.getImage().getRoi(); > pointsX = points.getXCoordinates(); > pointsY = points.getYCoordinates(); > for ( i = 0; i < pointsX.length; ++i ) { > dMin = Integer.MAX_VALUE; > iMin = -1; > for ( j = 0; j < pointsX.length; ++j ) { > if ( i == j ) continue; > dX = pointsX[ j ] - pointsX[ i ]; > dY = pointsY[ j ] - pointsY[ i ]; > d = dX * dX + dY * dY; > if ( dMin > d ) { > dMin = d; > iMin = j; > } > } > IJ.log( ( i + 1 ) + " " + ( iMin + 1 ) + " " + Math.sqrt( dMin ) ); > } > > It prints n lines with three space separated numbers into the log > window: > > <index> <nearest point index> <minimal distance> > > Best regards, > Stephan > > > > > > On Tue, 2010-05-25 at 14:54 +0200, Johannes-Paul M. Koch wrote: >> Dear Listers, >> >> I have two images with a set of point objects (derived from a previous >> calculation, i.e. basically, centers of mass of various particles). >> >> I want now to calculate the distance of each point (object) in image A >> to >> the closest point (object) in image B (and only to this closest one...). >> >> I suppose, the code I am looking for should 1) calculate ALL distances >> from point 1 in image A to ALL points in image B, 2) identify the >> shortest >> and 3) return the value of that distance. >> >> I had a look at Ben's plugin >> (http://imagejdocu.tudor.lu/doku.php?id=plugin:analysis:minimum_separation_distance:start) >> However, this does sort of a different job. On top, I admit that I am >> not >> so familiar with java (thanks, Wayne, for the macro language!), so it is >> not so easy for me to extract the necessary information out of this >> plugin. >> >> Is there anything already available (plugin, macro) that does this job, >> or >> at least comes close such that I can build upon it? Or do I have to look >> more closely at Ben's plugin (maybe someone could point out what I would >> have to look at!)? >> >> >> Many thanks, >> Johannes > > |
In reply to this post by Stephan Saalfeld
Hi,
I am trying to do exactly the same (calculate the minimum distance between objects from image A to objects in image B, so that for any ROI from image A I will get the minimum distance to one of the ROIs in image B), and I'm very happy to see that someone else already figured out how to do this! Briefly, I have the a sample that is stained with two antibodies, and in the end I will get two images of the same field but with two different colours (and patterns). My idea is to apply a threshold to both images and convert them to 2-bit images, then create ROIs using the "Analyse particles" command, and then find out which is the minimum distance between any ROI from image A and its closest neighbour in image B. I tried to use your BeanShell script (I'm not familiar with it), and I'm confused... It seems like that it picks up the XY coordinates of all ROIs listed in ROI Manager and calculates the minimum distance between all of them, not calculating the minimum distance between two different sets of objects. What am I doing wrong? Best regards, Stefano |
Free forum by Nabble | Edit this page |