Hey Everyone
I just got introduced to Imagej. so very beginner, and i would like if someone can help me with this issue. i am trying to analyse an x-ray image. what i want to do is, calculate the angle between two bones on that image. this is what i am thinking : drawing a line (Y1) in the center lenght of the first bone, and another line (Y2) in the lenght of the second bone, and calculate the angle between Y1 and Y2. Please how can i achieve this ? or is it achieveble. any help will be appreciate thanks |
If I understand your question correctly, you want to determine the angle between two lines that do not intersect in the image (otherwise you should simply use the angle tool). You can do this in two ways, I suppose. Both are quite easy:
a. Figure out the angle of line A relative to a horizontal line, then that of line B relative to a horizontal line, and compute the difference between them, or b. Prompt the user (through a macro) for two line selections and record the start and end coordinates (you can also do this manually by drawing a line and clicking on Ctrl-M, or going to Analyze -> Measure). Then calculate the point of intersection between the two lines with some basic math, and calculate the angle using the end point coordinates of the lines and the point of intersection. Cheers, Cornel
Cornel M. Pop
PhD Student Max Planck Institute For Evolutionary Anthropology |
Thanks for your answer, sure i can do that manually. But i would like to know if it is possible to automate the procedure using a macro. I have 6000 X-rays to measure the angle between to bones.
i was strategy is so : if i can somehow draw a line though the long. axis of bone1, and another line though the long. axis of bone2, then i can simply measure the angle between the 2 lines. so how can i find the axis in the first place ? is it possible to do it this way ? : ( it is an x-ray pict ) lets say 1 cm from the top of the picture, we scan that row for the first pixel that turns white ( the first edge of the bone ), here we have a dot A1, the we continue scanning until we finde the first pixel that turnes black (the second edge of bone ), this is dot A2, we draw a line between Y1(A1,A2) we do the same procedure, we go just further down lets say 10 cm from the top, we then have another line Y2(B1,B2). A line that goes from the middel of Y1 to the middel of Y2, will be the axis of the bone does it make sens ? can it be done ... any idea how ? thank you |
Ok, that's a more interesting problem. The short answer is yes, it is possible, but probably not trivial, depending on how complex the X-ray images are. I think you need to work on a method of detecting the bones of interest reliably, and then measuring their properties, such as axis and angle. You can probably get decent results quickly by thresholding the image and matching object (bone) characteristics (e.g. relationship of length to width) to those expected for the bones you are trying to analyze. Once you have the ROIs for the bones of interest reliably identified, you can easily determine angles and a whole bunch of other properties. If your object detection method is reliable, you can process the whole series of X-rays with very little intervention.
I hope that helps! Cheers, Cornel
Cornel M. Pop
PhD Student Max Planck Institute For Evolutionary Anthropology |
that's in fact exactly what i did, i used the "define edge" option, and then played with the threshold. now it i am getting a steady and satisfaying results, when automating the procedure with many x-ray pictures.
the next step where i am stuck, is how to proceed ( i am a very very beginner to imagej ) .. if the next step is to scan the row ( at 1 cm from the top ) for the 1 pixel that changes color ... then how to do it ? any ideas / exemples how to do more straitforward analyses on width of the bone ? cheers |
Well, first you have to define what a centimeter is (in pixels), and what the value of the pixel you are looking for should be (i.e. 0 for black, and 255 for white). Then you can loop through the whole row of interest and scan for the pixel in question. Something like this should do it for grayscale images:
imgTopDistance = 220; // change this to whatever 1cm is in pixels. pixelOfInterestValue = 156; // the value you are looking for. imgW = getWidth(); for(i = 0; i < imgW; i++) { pixelValue = getPixel(i, imgTopDistance); if(pixelValue == pixelOfInterestValue) { // Do whatever you need to do with this pixel (i.e. store the position in two arrays [one for x, and the other for y values, as imageJ doesn't currently support two-dimensional arrays] for later processing) print("Found value of interest at: "+i+","+imgTopDistance); } } However, it would be much better to just work on selections, if you managed to get to the point where you can automate the detection/selection of individual bones. For example, you could fit an ellipse (Edit->Selection->Fit Ellipse, or run("Fit Ellipse"); if working within a macro), and then simply run Analyze->Measure (or run("Measure"); from within a macro) to get the angle of the ellipse relative to the x axis of the image. I think this should result in a pretty decent approximation of the true angle. You could also use Feret's diameter (and angle), but for roughly rectangular objects it may not work all that well. The point is, you have quite a few options if working with selections, or object outlines. Do you have a sample x-ray image that you could share? Cheers, C.
Cornel M. Pop
PhD Student Max Planck Institute For Evolutionary Anthropology |
Free forum by Nabble | Edit this page |