Login  Register

Re: combine particles in ROI manager automatically

Posted by Tiago Ferreira on Apr 20, 2009; 10:05am
URL: http://imagej.273.s1.nabble.com/combine-particles-in-ROI-manager-automatically-tp3692844p3692853.html

Karel Jansseune <karel.jansseune@...> writes:

>
> For our research we are making images of Arabidopsis plants growing in
> plates andwe try to measure the area of each plant automatically. In this
> way we try to obtain the growth rate of each plant in the plate
> We successfully made a macro to do the analysis of a folder of images and
> return the results in a text file, but now we sometimes have the problem
> that one plant is divided into two during automatic analysis.
>
> Now I was wondering if it is possible to write a macro to instruct ImageJ
> to combine the ROI’s found within a certain distance of each other. (let
> say, if the 2 ROI’s are less than 2mm apart, they should be combined).
>
>
Don't know if this helps, but maybe you could try something like this:

//macro code:
roiManager("Reset");
run("Blobs (25K)");
setAutoThreshold();
run("Set Measurements...", "  centroid");
run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show="+
"Nothing display clear");
minDx=getNumber("Minimum distance between ROIs", 50);
n=roiManager("count");
Mlabel="Distance to previous";
setResult(Mlabel, 0, NaN);
for(i=0; i<nResults-1; i++) {
    x1= getResult('X', i); y1=getResult('Y', i);
    x2= getResult('X', i+1); y2=getResult('Y', i+1);
    distance= sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    setResult(Mlabel, i+1, distance);
}
updateResults;

for(i=2; i<nResults; i++) {
    distance=getResult(Mlabel, i);
    x1= getResult('X', i-1); y1=getResult('Y', i-1);
    x2= getResult('X', i); y2=getResult('Y', i);
    if(distance<= minDx) {
        doWand(x1,y1);
        setKeyDown("shift");
        doWand(x2,y2);
        roiManager("Add")}
}
resetThreshold;
setOption("Show All", true);

// end
T.