I am currently working on measuring the offset of a Light Field and X-Ray Field. I have two images, Light and X-ray (Green Light) Using the Imagej tools for finding the edges and doing some threshold I came with the edges of the light field (18x24L) and x-ray field (18x24X). Using overlay, I overlaid the Light edge onto the X-Ray Edge. I am looking to find the distance of the xray edge and the light edge on all four sides automatically, using a macro or plugin. If I could draw a line that goes through the the two edges (Light and Xray) on each side, and finding the coordinates of the intercepts of the line with the edges I can find the distance of those intercepts. the other thought I had was to use the plot profile of the edges and find the distance of the highest peaks in the profile but there is no macro that does that automatically. Any thoughts? Please see attachments sent in two emails |
This looks like a mammography project.
As I understand it, you want to draw eight lines; four fit to the four edges of the light field, and four to the edges of the x-ray field. € To fit the horizontal edges to lines, you might want to do a linear fit of the edges to a linear function y=mx+b, using only the central 50% of the field (to avoid complications at the corners). Note that the y-intercept of such a line, with the y-axis passing through the center of the field, would be the same (or almost the same) as the average of the y-values of the points. € For the vertical edges, do something similar but fitting to x=my+b. € Be careful to define what you mean by the distances between the edges. If two lines have different slopes, obviously the distance between them varies with position. If this is to determine regulatory compliance, use the regulations for guidelines. One suggestion would be to define "horizontal" and "vertical" axis that pass through the center of the fields, with the slope of the horizontal axis equal to the average of the slopes of the horizontal edges, and the slope of the vertical axis equal to the average of the slopes of the vertical edges. You could then define the distance between two horizontal edges as the distance between the intersection of each edge with the vertical axis. I would suggest doing this as a plugin rather than a macro, simply because I know it could be done in a plugin and I do not know if it could be done in a macro. -- David M. Gauntt, Ph.D. Associate Professor, Division of Medical Physics and Engineering UAB Department of Radiology mailto:[hidden email] 205-975-3777 On 2/27/12 1:12 PM, "Juan Navarro" <[hidden email]> wrote: > >I am currently working on measuring the offset of a Light Field and >X-Ray Field. I have two images, Light and X-ray (Green Light) >Using >the Imagej tools for finding the edges and doing some threshold I came >with the edges of the light field (18x24L) and x-ray field (18x24X). >Using overlay, I overlaid the Light edge onto the X-Ray Edge. >I am looking to find the distance of the xray edge and the light edge on >all four sides automatically, using a macro or plugin. > >If > I could draw a line that goes through the the two edges (Light and >Xray) on each side, and finding the coordinates of the intercepts of the > line with the edges I can find the distance of those intercepts. >the > other thought I had was to use the plot profile of the edges and find >the distance of the highest peaks in the profile but there is no macro >that does that automatically. > >Any thoughts? Please see attachments sent in two emails |
David,
Yes it is a mammography project. In theory, it makes a lot of sense, getting the equations of the lines on the four edges of every one of the fields and then measure the distance of the intercepts. You say, "you might want to use a linear fit". I am not very familiar with the process but I was doing some research and I am assuming I can accomplish this using the Curve Fit tool and using Straight Line. Is that correct? I did so but it is not giving me a slope that would be close to a horizontal line. I might be doing it wrong. I get something like this: Formula: y = a+bx Time: 1ms Number of iterations: 111 (2000) Number of restarts: 2 (2) Sum of residuals squared: 37.0328 Standard deviation: 2.7215 R^2: 0.9218 Parameters: a = -3.2524 b = 4.9943 Thank you very much for the help, Juan > Date: Mon, 27 Feb 2012 20:48:00 +0000 > From: [hidden email] > Subject: Re: Light-Xray Field > To: [hidden email] > > This looks like a mammography project. > > As I understand it, you want to draw eight lines; four fit to the four > edges of the light field, and four to the edges of the x-ray field. > > € To fit the horizontal edges to lines, you might want to do a linear fit > of the edges to a linear function y=mx+b, using only the central 50% of > the field (to avoid complications at the corners). Note that the > y-intercept of such a line, with the y-axis passing through the center of > the field, would be the same (or almost the same) as the average of the > y-values of the points. > > € For the vertical edges, do something similar but fitting to x=my+b. > > € Be careful to define what you mean by the distances between the edges. > If two lines have different slopes, obviously the distance between them > varies with position. If this is to determine regulatory compliance, use > the regulations for guidelines. One suggestion would be to define > "horizontal" and "vertical" axis that pass through the center of the > fields, with the slope of the horizontal axis equal to the average of the > slopes of the horizontal edges, and the slope of the vertical axis equal > to the average of the slopes of the vertical edges. You could then define > the distance between two horizontal edges as the distance between the > intersection of each edge with the vertical axis. > > I would suggest doing this as a plugin rather than a macro, simply because > I know it could be done in a plugin and I do not know if it could be done > in a macro. > > > -- > David M. Gauntt, Ph.D. > Associate Professor, > Division of Medical Physics and Engineering > UAB Department of Radiology > > mailto:[hidden email] > 205-975-3777 > > > > > > > > On 2/27/12 1:12 PM, "Juan Navarro" <[hidden email]> wrote: > > > > >I am currently working on measuring the offset of a Light Field and > >X-Ray Field. I have two images, Light and X-ray (Green Light) > >Using > >the Imagej tools for finding the edges and doing some threshold I came > >with the edges of the light field (18x24L) and x-ray field (18x24X). > >Using overlay, I overlaid the Light edge onto the X-Ray Edge. > >I am looking to find the distance of the xray edge and the light edge on > >all four sides automatically, using a macro or plugin. > > > >If > > I could draw a line that goes through the the two edges (Light and > >Xray) on each side, and finding the coordinates of the intercepts of the > > line with the edges I can find the distance of those intercepts. > >the > > other thought I had was to use the plot profile of the edges and find > >the distance of the highest peaks in the profile but there is no macro > >that does that automatically. > > > >Any thoughts? Please see attachments sent in two emails |
I've never used the curve fit tool; I just took a look at it.
It takes a text input rather than an image input. Don't use it to analyze an image; use it to analyze a text file (or copied text) containing a set of point described as (x,y) coordinates. The results that you are getting are for the set of test data that appears in the "Curve Fitter" window when you first open the plugin. For fitting lines, it would be just as simple (perhaps simpler) to use the LINEST function of Microsoft Excel. I would suggest for a first step that you write a plugin that writes to a text window the coordinates (x,y) of every pixel in the current selection with a pixel value below some threshold (128 would be a good threshold for your images). You can then copy these values into the curve fitter window to do the linear fit. The results you could then copy into an Excel spreadsheet to do the final calculations. -- David M. Gauntt, Ph.D. Associate Professor, Division of Medical Physics and Engineering UAB Department of Radiology mailto:[hidden email] 205-975-3777 On 2/27/12 10:23 PM, "Juan Navarro" <[hidden email]> wrote: >David, > >Yes it is a mammography project. >In theory, it makes a lot of sense, getting the equations of the lines on >the four edges of every one of the fields and then measure the distance >of the intercepts. > >You say, "you might want to use a linear fit". I am not very familiar >with the process but I was doing some research and I am assuming I can >accomplish this using the Curve Fit tool and using Straight Line. Is that >correct? > >I did so but it is not giving me a slope that would be close to a >horizontal line. I might be doing it wrong. >I get something like this: > >Formula: y = a+bx >Time: 1ms >Number of iterations: 111 (2000) >Number of restarts: 2 (2) >Sum of residuals squared: 37.0328 >Standard deviation: 2.7215 >R^2: 0.9218 >Parameters: > a = -3.2524 > b = 4.9943 > >Thank you very much for the help, > >Juan > > > >> Date: Mon, 27 Feb 2012 20:48:00 +0000 >> From: [hidden email] >> Subject: Re: Light-Xray Field >> To: [hidden email] >> >> This looks like a mammography project. >> >> As I understand it, you want to draw eight lines; four fit to the four >> edges of the light field, and four to the edges of the x-ray field. >> >> € To fit the horizontal edges to lines, you might want to do a linear >>fit >> of the edges to a linear function y=mx+b, using only the central 50% of >> the field (to avoid complications at the corners). Note that the >> y-intercept of such a line, with the y-axis passing through the center >>of >> the field, would be the same (or almost the same) as the average of the >> y-values of the points. >> >> € For the vertical edges, do something similar but fitting to x=my+b. >> >> € Be careful to define what you mean by the distances between the edges. >> If two lines have different slopes, obviously the distance between them >> varies with position. If this is to determine regulatory compliance, >>use >> the regulations for guidelines. One suggestion would be to define >> "horizontal" and "vertical" axis that pass through the center of the >> fields, with the slope of the horizontal axis equal to the average of >>the >> slopes of the horizontal edges, and the slope of the vertical axis equal >> to the average of the slopes of the vertical edges. You could then >>define >> the distance between two horizontal edges as the distance between the >> intersection of each edge with the vertical axis. >> >> I would suggest doing this as a plugin rather than a macro, simply >>because >> I know it could be done in a plugin and I do not know if it could be >>done >> in a macro. >> >> >> -- >> David M. Gauntt, Ph.D. >> Associate Professor, >> Division of Medical Physics and Engineering >> UAB Department of Radiology >> >> mailto:[hidden email] >> 205-975-3777 >> >> >> >> >> >> >> >> On 2/27/12 1:12 PM, "Juan Navarro" <[hidden email]> wrote: >> >> > >> >I am currently working on measuring the offset of a Light Field and >> >X-Ray Field. I have two images, Light and X-ray (Green Light) >> >Using >> >the Imagej tools for finding the edges and doing some threshold I came >> >with the edges of the light field (18x24L) and x-ray field (18x24X). >> >Using overlay, I overlaid the Light edge onto the X-Ray Edge. >> >I am looking to find the distance of the xray edge and the light edge >>on >> >all four sides automatically, using a macro or plugin. >> > >> >If >> > I could draw a line that goes through the the two edges (Light and >> >Xray) on each side, and finding the coordinates of the intercepts of >>the >> > line with the edges I can find the distance of those intercepts. >> >the >> > other thought I had was to use the plot profile of the edges and find >> >the distance of the highest peaks in the profile but there is no macro >> >that does that automatically. >> > >> >Any thoughts? Please see attachments sent in two emails > |
In reply to this post by Juan Navarro
Hough transforms do a very good job of finding straight lines in images. There is a plug-in for ImageJ that performs Hough transforms on images, which I have successfully used to find collimation boundaries in x-ray images. The Linear-Hough plug-in is found among those provided by Burger and Bruge which are posted on http://rsbweb.nih.gov/ij/plugins/index.html in the section for Links to External Sites.
The Hough transform maps each selected pixel in an image to a sinusoid in the transform-image. For straight lines, all of these sinusoids overlap at a single transform-image location corresponding to the (R, theta) coordinates of the line. BTW - This representation is much better than slope and intercept, as the slope can be infinite for the common case of a vertical line. I found it necessary to slightly modify the Burger&Bruge plugin for several reasons for best results. The most important fix was to properly recognize the continuity of the Hough transform at the 0-degree and 360-degree boundaries of the transform image. The original plugin can find two lines (one near 0-degrees and one near 360-degrees) where there is in fact only one. I noted that one of your sample images has rounded corners and that the lines are not perfectly straight. I don't think either of these imperfections will substantially reduce the effectiveness of a Hough transform approach. Good Luck, Richard VanMetter |
Thanks Richard,
I got two Plugins from B&B site. One is the "Plugin Hough Linear" and "Plugin Hough Linear Ovlay". I used the Image that contains the edges found in the Light Field and I ran the Plugin Hough Linear. I requests me for Angular Steps, Radial Steps, Number of Lines, and Min. points/line. I used 360,256,10,150 respectively. I get this: 1: HoughLine angle=1.065, radius=0.000, count=18887 2: HoughLine angle=2.077, radius=0.000, count=18887 3: HoughLine angle=1.571, radius=-524.911, count=17280 4: HoughLine angle=1.571, radius=-456.071, count=17280 5: HoughLine angle=1.571, radius=-413.045, count=17280 6: HoughLine angle=1.571, radius=-370.020, count=17280 7: HoughLine angle=1.571, radius=-326.994, count=17280 8: HoughLine angle=1.571, radius=-283.969, count=17280 9: HoughLine angle=1.571, radius=-240.943, count=17280 10: HoughLine angle=1.571, radius=-197.917, count=17280 A new image pops up as well with the edges of the light and Green lines drawn on it. Can you elaborate a little bit on what these results are and how that helps me finding the line. I understand that the results are in polar coordinates, what is the origin the coordinate system? Thanks again, Juan > Date: Thu, 1 Mar 2012 09:03:24 -0500 > From: [hidden email] > Subject: Re: Light-Xray Field > To: [hidden email] > > Hough transforms do a very good job of finding straight lines in images. There is a plug-in for ImageJ that performs Hough transforms on images, which I have successfully used to find collimation boundaries in x-ray images. The Linear-Hough plug-in is found among those provided by Burger and Bruge which are posted on http://rsbweb.nih.gov/ij/plugins/index.html in the section for Links to External Sites. > > The Hough transform maps each selected pixel in an image to a sinusoid in the transform-image. For straight lines, all of these sinusoids overlap at a single transform-image location corresponding to the (R, theta) coordinates of the line. BTW - This representation is much better than slope and intercept, as the slope can be infinite for the common case of a vertical line. > > I found it necessary to slightly modify the Burger&Bruge plugin for several reasons for best results. The most important fix was to properly recognize the continuity of the Hough transform at the 0-degree and 360-degree boundaries of the transform image. The original plugin can find two lines (one near 0-degrees and one near 360-degrees) where there is in fact only one. > > I noted that one of your sample images has rounded corners and that the lines are not perfectly straight. I don't think either of these imperfections will substantially reduce the effectiveness of a Hough transform approach. > > Good Luck, > Richard VanMetter |
In reply to this post by Juan Navarro
The coordinate values of the Hough transform represent an angle between 0 and PI radians and a distance (in pixels) measured from the center of the image which may be positive or negative. The coordinate system is located at the center of the image with the positive x axis to the right and the positive y axis toward the bottom. An Hough angle is that between the positive x axis and a line extending from the origin to orthogonally intersect the HoughLine (this is easier to draw than to describe). For example, a HoughtLine with zero angle is a vertical. If it has a positive distance, it is to the right of the center. A horizontal HoughLine has an angle of PI/2 with positive distance corresponding to lines below the center.
In your results: - Radius zero corresponds to lines passing through the center of your image. - The angle 1.571 is PI/2. With a negative radius, they horizontal lines above the center. Thus many horizontal lines are being reported above the center of the image. Note they all have identical strength (number of pixels contributing). I suspect you have too many non-zero pixels in the image you are sending to the Hough transform. If you haven't done so already, consider setting all pixels that you do not want to be considered as part of a line to zero. I believe, the Burger and Bruge code counts all non-zero pixels as equal contributors to the transform. You can of course modify their code for a more nuanced accumulation of the Hough transform. Richard in response to --------------------------------------------------------------------------------------------------------------------------------------------------------------- I got two Plugins from B&B site. One is the "Plugin Hough Linear" and "Plugin Hough Linear Ovlay". I used the Image that contains the edges found in the Light Field and I ran the Plugin Hough Linear. I requests me for Angular Steps, Radial Steps, Number of Lines, and Min. points/line. I used 360,256,10,150 respectively. I get this: 1: HoughLine angle=1.065, radius=0.000, count=18887 2: HoughLine angle=2.077, radius=0.000, count=18887 3: HoughLine angle=1.571, radius=-524.911, count=17280 4: HoughLine angle=1.571, radius=-456.071, count=17280 5: HoughLine angle=1.571, radius=-413.045, count=17280 6: HoughLine angle=1.571, radius=-370.020, count=17280 7: HoughLine angle=1.571, radius=-326.994, count=17280 8: HoughLine angle=1.571, radius=-283.969, count=17280 9: HoughLine angle=1.571, radius=-240.943, count=17280 10: HoughLine angle=1.571, radius=-197.917, count=17280 A new image pops up as well with the edges of the light and Green lines drawn on it. Can you elaborate a little bit on what these results are and how that helps me finding the line. I understand that the results are in polar coordinates, what is the origin the coordinate system? |
Free forum by Nabble | Edit this page |