Dear List,
I am trying to write a macro to get a histogram of a selection via the roiManager. When I manually click through the steps I get what I expect. When I try to execute the same steps through a macro I get different results. I have included a snip of my code below. I think that when I select a selection through the roiManager in the macro and then execute run("Histogram") it is not running a histogram on the selected selection I think I've specified. selectWindow("rootDiameterImage"); // Transfer roi from roiManager to new file run("From ROI Manager"); totalRootSegments=roiManager("count"); for(k_rs=0; k_rs <totalRootSegments;k_rs++) { roiManager("Select", k_rs); run("Histogram"); getHistogram(Values,Counts,256); for(i_Hist=1; i_Hist<Values.length; i_Hist++) { thisValue=Values[i_Hist]; thisCount=Counts[i_Hist]; thisProduct=thisValue*thisCount; sumOfValueTimesCount=sumOfValueTimesCount +thisProduct; sumOfCount=sumOfCount+thisCount; } Can anyone see what I am doing wrong? When I manually click in the roiManager for a selection and then run a histogram and examine the values under the histogram "list" I get what I was expecting. When I examine the values within the histogram from the macro I get values not associated with the "selection." Thanks for your assistance, Dan Daniel W. McDonald, Co-founder and President, Phenotype Screening Corporation, 4028 Papermill Road, Suite 10, Knoxville, TN 37909 (865) 385-8641 cell (865) 694-9459 office [hidden email] daniel.w.mcdonald1 on Skype www.phenotypescreening.com -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Good day Dan,
maybe after calling for the histogram you should bring your image again to the front (e.g. by using selectImage(id)), otherwise you get the next histogram from the past histogram -- no? HTH Herbie :::::::::::::::::::::::::::::::::::::::::: Am 30.09.16 um 20:44 schrieb Dan McDonald: > Dear List, > > > > I am trying to write a macro to get a histogram of a selection via the > roiManager. > > > > When I manually click through the steps I get what I expect. When I try to > execute the same steps through a macro I get different results. I have > included a snip of my code below. > > > > I think that when I select a selection through the roiManager in the macro > and then execute run("Histogram") it is not running a histogram on the > selected selection I think I've specified. > > > > selectWindow("rootDiameterImage"); > > // Transfer roi from roiManager to new file > > run("From ROI Manager"); > > totalRootSegments=roiManager("count"); > > for(k_rs=0; k_rs <totalRootSegments;k_rs++) { > > roiManager("Select", k_rs); > > run("Histogram"); > > getHistogram(Values,Counts,256); > > for(i_Hist=1; i_Hist<Values.length; i_Hist++) { > > thisValue=Values[i_Hist]; > > thisCount=Counts[i_Hist]; > > thisProduct=thisValue*thisCount; > > sumOfValueTimesCount=sumOfValueTimesCount +thisProduct; > > sumOfCount=sumOfCount+thisCount; > > } > > > > Can anyone see what I am doing wrong? > > > > When I manually click in the roiManager for a selection and then run a > histogram and examine the values under the histogram "list" I get what I was > expecting. > > > > When I examine the values within the histogram from the macro I get values > not associated with the "selection." > > > > Thanks for your assistance, > > > > Dan > > > > Daniel W. McDonald, > > Co-founder and President, > > Phenotype Screening Corporation, > > 4028 Papermill Road, Suite 10, > > Knoxville, TN 37909 > > (865) 385-8641 cell > > (865) 694-9459 office > > [hidden email] > > daniel.w.mcdonald1 on Skype > > www.phenotypescreening.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 Dan McDonald
> On Sep 30, 2016, at 2:44 PM, Dan McDonald <[hidden email]> wrote:
> > Dear List, > > I am trying to write a macro to get a histogram of a selection via the > roiManager. > > When I manually click through the steps I get what I expect. When I try to > execute the same steps through a macro I get different results. I have > included a snip of my code below. > > I think that when I select a selection through the roiManager in the macro > and then execute run("Histogram") it is not running a histogram on the > selected selection I think I've specified. Remove the run("Histogram”) line, which is not needed and causes a lot histogram windows to open. You can also avoid using the ROI Manager and activate the selections directly from the overlay, as in this example: run("Blobs (25K)"); setAutoThreshold("Default"); run("Analyze Particles...", " show=Overlay"); resetThreshold; for (i=0; i<Overlay.size; i++) { Overlay.activateSelection(i); getHistogram(values, counts, 256); print(i, counts[128]); } -wayne > selectWindow("rootDiameterImage"); > > // Transfer roi from roiManager to new file > > run("From ROI Manager"); > > totalRootSegments=roiManager("count"); > > for(k_rs=0; k_rs <totalRootSegments;k_rs++) { > > roiManager("Select", k_rs); > > run("Histogram"); > > getHistogram(Values,Counts,256); > > for(i_Hist=1; i_Hist<Values.length; i_Hist++) { > > thisValue=Values[i_Hist]; > > thisCount=Counts[i_Hist]; > > thisProduct=thisValue*thisCount; > > sumOfValueTimesCount=sumOfValueTimesCount +thisProduct; > > sumOfCount=sumOfCount+thisCount; > > } > > > Can anyone see what I am doing wrong? > > When I manually click in the roiManager for a selection and then run a > histogram and examine the values under the histogram "list" I get what I was > expecting. > > When I examine the values within the histogram from the macro I get values > not associated with the "selection." > > Thanks for your assistance, > > Dan -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |