I know this has been posted elsewhere and that this is no means a difficult problem but I'm very new to writing macros in FIJI and am having a hard time even understanding the solutions described in various online resources.
I have a series of images all in the same folder and want to apply the same operations to them all and save the resultant excel files and images in an output folder. Specifically, I'd like to open, smooth the image, do a Max intensity Z projection, then threshold the images to the same relative value. This thresholding is one step causing a problem. By relative value I mean that I would like to set the threshold so that the same % of the intensity histogram is included. Currently, in FIJI if you go to image>adjust>threshold you can move the sliders such that a certain percentage of the image is thresholded and it will display that value for you in the open window. In my case 98% is what I am trying to achieve, eg thresholding all but the top 2% of the data. Once the threshold is applied to the MIP, I convert it to binary and do particle analysis and save the results (summary table, results, image overlay. My approach has been to try and automate all the steps/ do batch processing but I have been having a hard time adapting what I have written to work based on instructions found online. Instead I've been just opening every image in the directory one by one and applying the macro that I wrote, then saving the results manually. Obviously this is a tedious approach so any help would be much appreciated! What I have been using for my simple macro: run("Smooth", "stack"); run("Z Project...", "projection=[Max Intensity]"); setAutoThreshold("Default"); //run("Threshold..."); run("Convert to Mask"); run("Make Binary"); run("Analyze Particles...", " show=[Overlay Masks] display exclude clear include summarize in_situ"); |
I think that this link from the mailing list archives will help.
http://imagej.1557.x6.nabble.com/Percentile-value-td3690983.html --aryeh On 14/02/2016 4:16 AM, wustlmed wrote: > I know this has been posted elsewhere and that this is no means a difficult > problem but I'm very new to writing macros in FIJI and am having a hard time > even understanding the solutions described in various online resources. > > I have a series of images all in the same folder and want to apply the same > operations to them all and save the resultant excel files and images in an > output folder. Specifically, I'd like to open, smooth the image, do a Max > intensity Z projection, then threshold the images to the same relative > value. > > This thresholding is one step causing a problem. By relative value I mean > that I would like to set the threshold so that the same % of the intensity > histogram is included. Currently, in FIJI if you go to > image>adjust>threshold you can move the sliders such that a certain > percentage of the image is thresholded and it will display that value for > you in the open window. In my case 98% is what I am trying to achieve, eg > thresholding all but the top 2% of the data. > > Once the threshold is applied to the MIP, I convert it to binary and do > particle analysis and save the results (summary table, results, image > overlay. > > My approach has been to try and automate all the steps/ do batch processing > but I have been having a hard time adapting what I have written to work > based on instructions found online. Instead I've been just opening every > image in the directory one by one and applying the macro that I wrote, then > saving the results manually. Obviously this is a tedious approach so any > help would be much appreciated! > > What I have been using for my simple macro: > > run("Smooth", "stack"); > run("Z Project...", "projection=[Max Intensity]"); > > setAutoThreshold("Default"); > //run("Threshold..."); > run("Convert to Mask"); > > run("Make Binary"); > run("Analyze Particles...", " show=[Overlay Masks] display exclude > clear include summarize in_situ"); > > > > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/Thresholding-and-batch-processing-in-FIJI-ImageJ-tp5015626.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by wustlmed
Hi Miles,
> I have a series of images all in the same folder and want to apply the > same operations to them all and save the resultant excel files and > images in an output folder. You can use the Process > Batch > Macro... command for this. For further details, see the Batch Processing page of the ImageJ wiki: http://imagej.net/Batch_Processing I also posted this same answer to your cross-post on StackOverflow: http://stackoverflow.com/a/35423532/1207769 Regards, Curtis -- Curtis Rueden LOCI software architect - http://loci.wisc.edu/software ImageJ2 lead, Fiji maintainer - http://imagej.net/User:Rueden Did you know ImageJ has a forum? http://forum.imagej.net/ On Sat, Feb 13, 2016 at 8:16 PM, wustlmed <[hidden email]> wrote: > I know this has been posted elsewhere and that this is no means a difficult > problem but I'm very new to writing macros in FIJI and am having a hard > time > even understanding the solutions described in various online resources. > > I have a series of images all in the same folder and want to apply the same > operations to them all and save the resultant excel files and images in an > output folder. Specifically, I'd like to open, smooth the image, do a Max > intensity Z projection, then threshold the images to the same relative > value. > > This thresholding is one step causing a problem. By relative value I mean > that I would like to set the threshold so that the same % of the intensity > histogram is included. Currently, in FIJI if you go to > image>adjust>threshold you can move the sliders such that a certain > percentage of the image is thresholded and it will display that value for > you in the open window. In my case 98% is what I am trying to achieve, eg > thresholding all but the top 2% of the data. > > Once the threshold is applied to the MIP, I convert it to binary and do > particle analysis and save the results (summary table, results, image > overlay. > > My approach has been to try and automate all the steps/ do batch processing > but I have been having a hard time adapting what I have written to work > based on instructions found online. Instead I've been just opening every > image in the directory one by one and applying the macro that I wrote, then > saving the results manually. Obviously this is a tedious approach so any > help would be much appreciated! > > What I have been using for my simple macro: > > run("Smooth", "stack"); > run("Z Project...", "projection=[Max Intensity]"); > > setAutoThreshold("Default"); > //run("Threshold..."); > run("Convert to Mask"); > > run("Make Binary"); > run("Analyze Particles...", " show=[Overlay Masks] display exclude > clear include summarize in_situ"); > > > > > > > -- > View this message in context: > http://imagej.1557.x6.nabble.com/Thresholding-and-batch-processing-in-FIJI-ImageJ-tp5015626.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 |
In reply to this post by Aryeh Weiss
Thanks Aryeh,
I looked through the link you suggested and unfortunately the suggested code isn't working for me. I copied it directly into the editor and keep getting an error in line 9 which says cumHist[0] = values[counts[0]<]> ;. Like I said I'm new at this and so I'm not sure how to troubleshoot this. Furthermore, I think the output of this script would be a some value that could hopefully be fed into the threshold function allowing me to draw the cutoff at a certain percentage of values, but what I'm not sure is how to pass that value along to the threshold function. I looked at some documentation and it seems like you can pass different predetermined methods like Li or Triangle for the threshold but not specific values. -M |
On 21/02/2016 12:59 AM, wustlmed wrote:
> Thanks Aryeh, > > I looked through the link you suggested and unfortunately the suggested code > isn't working for me. I copied it directly into the editor and keep getting > an error in line 9 which says cumHist[0] = values[counts[0]<]> ;. Like I > said I'm new at this and so I'm not sure how to troubleshoot this. I cut and pasted eh macro from that link into my script editor, and it worked. I had to repair a few lines that were split in the pasted code. Since this line is close to the top , I suggest that you step through the macro, using print statements to verify each line. > Furthermore, I think the output of this script would be a some value that > could hopefully be fed into the threshold function allowing me to draw the > cutoff at a certain percentage of values, but what I'm not sure is /how/ to > pass that value along to the threshold function. I looked at some > documentation and it seems like you can pass different predetermined methods > like Li or Triangle for the threshold but not specific values. I think that setThreshold will do that http://imagej.nih.gov/ij/developer/macro/functions.html#setThreshold An excellent way to get started is to peruse the macro function list to get a feel for what is there, and also to look at the many examples that yo can find here: http://imagej.nih.gov/ij/macros/ In this list, I found three macros that have "threshold" in their title. You might some some useful ideas in those. Best regards --aryeh -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thanks again for your help.
This post here: http://imagej.1557.x6.nabble.com/Threshold-as-a-percentage-of-image-histogram-td3695671.html Seems to be a good solution to finding the cutoff value, i, above which only the desired percent of pixels remain. What is nice is that one can specify a certain percent, say 2% and it will tell what intensity to draw the cutoff at such that only 2% of the data remains above the threshold. Still I'm running into an error when I use this in the setThreshold function. I confirmed firstly that the output, i, is correct by using the output value in the Image>Adjust>Threshold sliders and saw the surviving percent is indeed what I had asked for in the macro. However, when I added the line setThreshold(0,i) the result is vastly different- basically the entire image is thresholded, nothing survives the cutoff- and I'm at a loss why. Perhaps you see my mistake? run("Duplicate...", "title=duplicate"); // Input a tissue threshold percentage 0-100 tissueThreshPerc = 98; nBins = 256; getHistogram(values, count, nBins); size = count.length; // find culmulative sum cumSum = 0; for (i = 0; i<count.length; i++) { cumSum += count[i]; } //totalNumberOfPixels = getWidth() * getHeight() //print(totalNumberOfPixels) tissueValue = cumSum * tissueThreshPerc / 100; print(tissueValue); // cumulative sum of before cumSumValues = count; for (i = 1; i<count.length; i++) { cumSumValues[i] += cumSumValues[i-1]; } // find tissueValue for (i = 1; i<cumSumValues.length; i++) { if (cumSumValues[i-1] <= tissueValue && tissueValue <= cumSumValues[i]) // output tissue threshold: print(i); <b>setThreshold(0,i); } |
Free forum by Nabble | Edit this page |