This post was updated on .
Dear all,
I could use some suggestions for how to proceed with the problem of writing a macro to automatically measure the width of an object. I am kind of stumped as to how I can get ImageJ to detect the borders of the object I need to measure, as it will not be the same color in all images. Here is an example of what I am working with: https://drive.google.com/file/d/0B208tul7KbkbQ3VCaFloOU9VVjQ/view?usp=sharing The measurement I need is from point G-H. Any advice would be greatly appreciated. Thank you, Andrew |
IJMacro_AndrewSanchez.ijm
Dear Andrew, please find my suggestion in the uploaded macro. I hope it will stimulate thoughts for improvement. Kind regards, Jens
Jens Rietdorf
Visiting Scientist
Fundação Oswaldo Cruz - Ministério da Saúde, Centro de Desenvolvimento Tecnológico em Saúde (CDTS), Rio de Janeiro, Brasil.
|
Oh wow! That's really interesting. Seems like this is definitely on the right track.
I am going through the script line by line, trying to understand what I can get out of this. I am going to need to do a bit of digging before I can even begin to comprehend how I can use this for my task, so if anybody feels the inspiration to jump in and spell it out for me, that would be awesome. Otherwise I will post back once I wrap my head around this. I ran the macro without line 5 because I got the message "Stack needed" Should I open my image, run Duplicate and then run Images to Stack in order to run Z project? Why did you make the line 20 pixels wide? Couldn't it just be 1 pixel, since I'm only interested in measuring the line's width? Thank you, Andrew |
Andrew,
sorry I should have added some explanation. You can just run the macro, it should open your example file which is the stack you need in line 5. You may have to convert other input RGB images to stacks. To avoid your colour issues there is the z-projection of the 3 colour channels. The line width helps to deal with the edges introduced by the ruler and noise, because it averages. Try to run it with width 1, you will see. Macro outputs the positions of the maxima along the line to the log window, this part of the macro is amended from http://imagej.net/macros/FindMaxima1D.txt Good success, Jens Visiting Scientist Fundação Oswaldo Cruz - Ministério da Saúde, Centro de Desenvolvimento Tecnológico em Saúde (CDTS), Rio de Janeiro, Brazil. Am 28.08.2015 01:21 schrieb "Andrew Sanchez" <[hidden email]>: > Oh wow! That's really interesting. Seems like this is definitely on the > right track. > > I am going through the script line by line, trying to understand what I can > get out of this. I am going to need to do a bit of digging before I can > even begin to comprehend how I can use this for my task, so if anybody > feels > the inspiration to jump in and spell it out for me, that would be awesome. > Otherwise I will post back once I wrap my head around this. > > I ran the macro without line 5 because I got the message "Stack needed" > > Should I open my image, run Duplicate and then run Images to Stack in order > to run Z project? > > Why did you make the line 20 pixels wide? Couldn't it just be 1 pixel, > since I'm only interested in measuring the line's width? > > Thank you, > Andrew > > > > -- > View this message in context: > http://imagej.1557.x6.nabble.com/Automatically-measure-width-tp5014170p5014177.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Jens Rietdorf
Visiting Scientist
Fundação Oswaldo Cruz - Ministério da Saúde, Centro de Desenvolvimento Tecnológico em Saúde (CDTS), Rio de Janeiro, Brasil.
|
This is awesome. It's working really well now, after I've made a few adjustments. Thanks again, Jens.
Do you have any recommendations about how to get the output of the Log window into a format I can easily extract the information I need? I need to subtract the higher x-coordinate from the lower x-coordinate (corresponding to both maxima respectively) to give me the width of the line. Is there a way to get those two numbers into a table within Image? I'm not even sure about how to go about this outside of ImageJ. It would also be nice to have those numbers be linked to the image name. Thank you, Andrew |
I have added 3 lines, which produce an additional output of the maxima position to the results window. This can then be saved as .csv and exported to any spreadsheet processor. Please take a look, I hope that goes into the right direction.
Cheers, Jens IJMacro_AndrewSanchez_02beta.IJMacro_AndrewSanchez_02beta
Jens Rietdorf
Visiting Scientist
Fundação Oswaldo Cruz - Ministério da Saúde, Centro de Desenvolvimento Tecnológico em Saúde (CDTS), Rio de Janeiro, Brasil.
|
Thank you Jens.
another question. Is there a way to ensure that I will get exactly two results for xmax, indicating exactly two results for the edges of the line I am trying to measure? I have tried adjusting the tolerance (currently 900) and line width in makeLine (currently 20). To be honest, I’m not really sure what tolerance does. You will see that by running this macro: fileName = File.nameWithoutExtension; run("Minimum...", "radius=2"); run("RGB Stack"); run("Z Project...", "projection=[Sum Slices]"); run("Find Edges"); w=getWidth(); h=getHeight(); findEdgeA = (h/2.2); findEdgeB = (h/2.45); // Measurement 1 makeLine((w/1.7), findEdgeA, (w/1.7), findEdgeB, 20); tolerance = 900; profile = getProfile(); maxLocs = Array.findMaxima(profile, tolerance); Array.sort(maxLocs); for (jj= 0; jj < maxLocs.length; jj++){ setResult("filename", jj, fileName); setResult("xmax", jj, maxLocs[jj]); if (jj>0) setResult("delta_xmax", jj, (maxLocs[jj]-maxLocs[jj-1])); } updateResults(); With this image open: andrewsanchez.github.io/vlcsnap-2015-10-15-19h01m10s675.png I get only one result for xmax. If you run it with this image: andrewsanchez.github.io/vlcsnap-2015-10-15-18h59m09s003.png you get the correct behavior - two results for xmax and delta_max, which is the difference between the two results for xmax. Is this a problem I need to address with more ways of processing the image besides the current run("Minimum...", "radius=2"); ? Thank you, Andrew |
Free forum by Nabble | Edit this page |