Hi list,
I want to do some automated measurements with a macro measureing regions wich I selected via doWand(x,y); Now I want to summarize all pixel grayvalues inside this selected ROI and save the sum in a variable. I'm new to ImageJ and didn't find a way yet. So at the moment I have my x,y coordinates for my doWand command and the selected ROI. Does someone have an idea how to summarize all the values in my macro? my algorithm looks like this: run("Find Maxima...", "noise=10 output=List exclude"); for(i=0; i<nResults; i++) { x=getResult("X", i); y=getResult("Y", i); doWand(x,y); thanks in advance and kind regards |
Hi GuPInt,
probably the easiest option would be to deselect all at the beginning, then use setKeyDown("shift") before each 'doWand'. This makes the Wand add to the selection. When done with all points, use getStatistics or getRawStatistics to get the desired information on the complete area. Alternatively, you could add all ROIs created by 'doWand' to the ROI Manager; then you could use ROI Manager 'OR (Combine)'. Both ways, overlapping regions (if any) will be counted only once. --- Concerning 'doWand', I would suggest to use 'doWand(x, y, tolerance, mode)', with mode = "4-connected" or "8-connected". This is more reliable than the classic 'doWand' command, which usually uses 8-connected mode, but sometimes switches to 4-connected, depending on the image data. Michael ________________________________________________________________ On Oct 11, 2013, at 16:09, GuPInt wrote: > Hi list, > > I want to do some automated measurements with a macro measureing regions > wich I selected via doWand(x,y); > Now I want to summarize all pixel grayvalues inside this selected ROI and > save the sum in a variable. > I'm new to ImageJ and didn't find a way yet. So at the moment I have my x,y > coordinates for my doWand command and the selected ROI. Does someone have an > idea how to summarize all the values in my macro? > > my algorithm looks like this: > > run("Find Maxima...", "noise=10 output=List exclude"); > > for(i=0; i<nResults; i++) { > x=getResult("X", i); > y=getResult("Y", i); > doWand(x,y); > > > thanks in advance and kind regards -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Michael,
thank you very much for your advice with the doWand command I'll change that. I want to measure each region one after the other and save the details of the regions like this: Regionnr=numberofregion Pixels=numberofpixels, sum=sumofallvalues but with your method I'll summarize all regions at once or did I get you wrong? Kind regards |
Hi GuPInt,
ok, your original message was not clear to me, I read it as 'get the (total, overall) sum of all pixels inside all the ROIs'. For getting the individual sums: You will need the Results table for the coordinates, so maybe the easiest solution is saving the results of getRawStatistics in Arrays, e.g. like the following (a rough idea, I have not tried): run("Find Maxima...", "noise=10 output=List exclude"); roiNPixels = newArray(nResults); roiSums = newArray(nResults); for(i=0; i<nResults; i++) { x=getResult("X", i); y=getResult("Y", i); doWand(x,y,0,"8-connected"); getRawStatistics(nPixels, mean); roiNPixels[i] = nPixels; roiSums[i] = mean*nPixels; } If you want, you can close the Results Table thereafter and populate a new table with the data stored in the array using a loop and setResult. Alternatively, instead of setting arrays, you can directly write to two new columns of the Result table, e.g. setResult("nPixels", i, nPixels). As far as I know, then you will have to live with the 'X' and 'Y' columns; one can't delete a column of the ResultsTable. Michael ________________________________________________________________ On Oct 14, 2013, at 17:08, GuPInt wrote: > Hi Michael, > > thank you very much for your advice with the doWand command I'll change > that. > I want to measure each region one after the other and save the details of > the regions like this: Regionnr=numberofregion Pixels=numberofpixels, > sum=sumofallvalues > but with your method I'll summarize all regions at once or did I get you > wrong? > > Kind regards -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Michael,
your idea works perfectly thank you very much :-) Still I changed the algorithm a bit. So here is my result in case someone esle has a similar question: run("Find Maxima...", "noise=10 output=list exclude"); for(i=0;i<nResults;i++) { x=getResult("X", i); y=getResult("Y", i); doWand(x,y,0,"8-connected"); getRawStatistics(nPixels, mean); count=nPixels; sum=mean*nPixels; IJ.log("object "+i+" | counted pixels: "+count+" | sum of greyvalues: "+sum); } selectWindow("Log"); saveAs("Text", ....); run("Close"); selectWindow("Testimage.bmp"); run("Close"); |
Free forum by Nabble | Edit this page |