extracting a specified number of coordinates from an *.roi file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

extracting a specified number of coordinates from an *.roi file

ajgeffen
Hi -
We are using an old, but trusty, macro with ImageJ 1.43 to process images of fish otoliths and extract the outlines to a series of silhouettes and roi files. These we then save as xy coordinates or text files and process further in a statistical analysis. We are stuck with 2 problems when using this macro now:
1) it won't run with updated versions of ImageJ and we don't know which commands need to be re-written, and more importantly
2) when we manually open the outline *.roi files and save them as coordinates or text files, we get consistently 100 pairs of coordinated which is a good representation of the shape.
However, when we write a line into the macro as a step to save the roi also as a file of xy coordinates, we get varying numbers of pairs, usually between 1500 and 2000 pairs.
This variation in the size of the dataset makes the next step more complicated and we would like very much to be able to specifiy the number of pairs coordinates that are saved for each image outline. We've searched, but can't find how to do that. Does anyone have any advice? Otherwise we need to open and then save the outline roi for each image individually

//version 20150115 modified in Bergen by Audrey Geffen
macro "Otolith Shape Analysis" {
requires("1.43h");
run("Set Measurements...", "area perimeter fit shape feret's display redirect=None decimal=4");
dir = getDirectory("Choose a Directory ");
list = getFileList(dir);
setBatchMode(true); //for fast macro
for (i=0; i<list.length; i++) {
path = dir+list[i];
open(path);
run("Invert");//white on black background
run("Set Scale...", "distance=285.60 known=1 pixel=1 unit=mm");
//calibrate the image
run("Save");//save calibrated image
run("Colors...", "foreground=black background=white selection=blue"); //set color
run("8-bit"); //grayscale
setAutoThreshold("Huang dark"); //BW image
run("Convert to Mask");
run("Fill Holes"); // fill holes in silhouette
run("Create Selection");
run("Enlarge...", "enlarge=0");
run("Fit Spline");
run("Clear Outside");
run("Fill");
run("Measure");
saveAs("Selection", path); //save roi file
run("RGB Color"); //convert from grayscale 8bit to 24bit RGB for shape input
dotIndex = lastIndexOf(path, ".");
if (dotIndex!=-1)
path = substring(path, 0, dotIndex); // remove extension
save(path+"sil.bmp"); //save silhouette image 24bit RGB
close();
}
}



Thanks,
Audrey
_________________________________________
Audrey J. Geffen
Department of Biology/Institutt for biologi
University of Bergen/Universitetet i Bergen
Postboks 7803, N-5020 Bergen, Norway
Tel: +47 55 58 44 35/Fax: +47 55 58 44 50
e-mail: [hidden email]
http://www.uib.no/persons/Audrey.Geffen

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: extracting a specified number of coordinates from an *.roi file

vischer
Hi Audrey,

I understand that you want a Roi to be defined by a constant number of coordinates (or vertices) such as 100.
Here is an example to set the number of vertices of a closed Roi to 100. I tested this on some large and small non-composite rois, but not in combination with your macro. In extreme cases (sharp edges), the result may be slightly different from 100 segments.
In your code, you could replace your statement 'run("Fit Spline")' with the snippet below:


//set number of closed-roi vertices to 100
run("Fit Spline");
nSegs = 100;
Roi.getCoordinates(xx, yy);
len = 0;
cnt = xx.length;
for (jj = 0; jj<xx.length; jj++)//calc perimeter in pixels
        len += sqrt(pow(xx[jj] - xx[(jj+1) % cnt], 2) + pow(yy[jj] - yy[(jj+1) % cnt], 2));
run("Interpolate", "interval="+ len/nSegs + "  adjust");
//for testing:
//Roi.getCoordinates(xx, yy);
//print(xx.length);



Best regards, Norbert






> On 26. Feb 2015, at 11:37, Audrey Geffen <[hidden email]> wrote:
>
> Hi -
> We are using an old, but trusty, macro with ImageJ 1.43 to process images of fish otoliths and extract the outlines to a series of silhouettes and roi files. These we then save as xy coordinates or text files and process further in a statistical analysis. We are stuck with 2 problems when using this macro now:
> 1) it won't run with updated versions of ImageJ and we don't know which commands need to be re-written, and more importantly
> 2) when we manually open the outline *.roi files and save them as coordinates or text files, we get consistently 100 pairs of coordinated which is a good representation of the shape.
> However, when we write a line into the macro as a step to save the roi also as a file of xy coordinates, we get varying numbers of pairs, usually between 1500 and 2000 pairs.
> This variation in the size of the dataset makes the next step more complicated and we would like very much to be able to specifiy the number of pairs coordinates that are saved for each image outline. We've searched, but can't find how to do that. Does anyone have any advice? Otherwise we need to open and then save the outline roi for each image individually
>
> //version 20150115 modified in Bergen by Audrey Geffen
> macro "Otolith Shape Analysis" {
> requires("1.43h");
> run("Set Measurements...", "area perimeter fit shape feret's display redirect=None decimal=4");
> dir = getDirectory("Choose a Directory ");
> list = getFileList(dir);
> setBatchMode(true); //for fast macro
> for (i=0; i<list.length; i++) {
> path = dir+list[i];
> open(path);
> run("Invert");//white on black background
> run("Set Scale...", "distance=285.60 known=1 pixel=1 unit=mm");
> //calibrate the image
> run("Save");//save calibrated image
> run("Colors...", "foreground=black background=white selection=blue"); //set color
> run("8-bit"); //grayscale
> setAutoThreshold("Huang dark"); //BW image
> run("Convert to Mask");
> run("Fill Holes"); // fill holes in silhouette
> run("Create Selection");
> run("Enlarge...", "enlarge=0");
> run("Fit Spline");
> run("Clear Outside");
> run("Fill");
> run("Measure");
> saveAs("Selection", path); //save roi file
> run("RGB Color"); //convert from grayscale 8bit to 24bit RGB for shape input
> dotIndex = lastIndexOf(path, ".");
> if (dotIndex!=-1)
> path = substring(path, 0, dotIndex); // remove extension
> save(path+"sil.bmp"); //save silhouette image 24bit RGB
> close();
> }
> }
>
>
>
> Thanks,
> Audrey
> _________________________________________
> Audrey J. Geffen
> Department of Biology/Institutt for biologi
> University of Bergen/Universitetet i Bergen
> Postboks 7803, N-5020 Bergen, Norway
> Tel: +47 55 58 44 35/Fax: +47 55 58 44 50
> e-mail: [hidden email]
> http://www.uib.no/persons/Audrey.Geffen
>
> --
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html