Gabriel Landini
2011-02-13 13:43:23 UTC
Hi,
I am trying to smooth an ROI by doing a running a series of average of size 3
on the coordinates of the ROI:
//------------8<----------------------
getSelectionCoordinates(x, y);
run("Select None");
makeSelection("polygon", x, y);
l=x.length;
print(l);
nx=newArray(l);
ny=newArray(l);
for (i=1;i<l-1;i++){
nx[i]=round(((x[i-1]+x[i]+x[i+1])/3)+random-0.5);
ny[i]=round(((y[i-1]+y[i]+y[i+1])/3)+random-0.5);
}
nx[0]=round(((x[l-1]+x[0]+x[1])/3)+random-0.5);
ny[0]=round(((y[l-1]+y[0]+y[1])/3)+random-0.5);
nx[l-1]=nx[0];
ny[l-1]=ny[0];
run("Select None");
makeSelection("polygon", nx, ny);
//------------8<----------------------
Although this kind-of-works to show the idea, the number of ROI coordinates
remains constant while the ROI slowly contracts, which means that there must
be several repeated ROI coordinates (which cannot be seen as they overlap).
So this has the disadvantage that after several passes some coordinates are
made of many superimposed points that do not get smoothed at the rate one
would expect.
Is there any way of getting rid of the repeated ROI coordinates other than
creating a new array which is populated with only the unique coordinates?
I also tried a version of ROI closing, but this is not exactly what I want:
for (i=1;i<10;i++) {
run("Enlarge...", "enlarge="+i);
run("Enlarge...", "enlarge=-"+i);
}
Thanks for any pointers
Cheers
Gabriel
I am trying to smooth an ROI by doing a running a series of average of size 3
on the coordinates of the ROI:
//------------8<----------------------
getSelectionCoordinates(x, y);
run("Select None");
makeSelection("polygon", x, y);
l=x.length;
print(l);
nx=newArray(l);
ny=newArray(l);
for (i=1;i<l-1;i++){
nx[i]=round(((x[i-1]+x[i]+x[i+1])/3)+random-0.5);
ny[i]=round(((y[i-1]+y[i]+y[i+1])/3)+random-0.5);
}
nx[0]=round(((x[l-1]+x[0]+x[1])/3)+random-0.5);
ny[0]=round(((y[l-1]+y[0]+y[1])/3)+random-0.5);
nx[l-1]=nx[0];
ny[l-1]=ny[0];
run("Select None");
makeSelection("polygon", nx, ny);
//------------8<----------------------
Although this kind-of-works to show the idea, the number of ROI coordinates
remains constant while the ROI slowly contracts, which means that there must
be several repeated ROI coordinates (which cannot be seen as they overlap).
So this has the disadvantage that after several passes some coordinates are
made of many superimposed points that do not get smoothed at the rate one
would expect.
Is there any way of getting rid of the repeated ROI coordinates other than
creating a new array which is populated with only the unique coordinates?
I also tried a version of ROI closing, but this is not exactly what I want:
for (i=1;i<10;i++) {
run("Enlarge...", "enlarge="+i);
run("Enlarge...", "enlarge=-"+i);
}
Thanks for any pointers
Cheers
Gabriel