Login  Register

Re: Draw circles on pre-defined point annotations in an image and measure the area/readius of these circles

Posted by Marien Koen on Mar 06, 2014; 10:58am
URL: http://imagej.273.s1.nabble.com/Draw-circles-on-pre-defined-point-annotations-in-an-image-and-measure-the-area-readius-of-these-circs-tp5006356p5006799.html

Thanks Michael


However new problems arose:
1) Can I automatically turn 'Labels' in the ROI Manager on? I tried roiManager("Labels"); but this did not do the trick...
2) After enlarging the circles and pressing 'OK', I get the message window 'Clear Outside: This command requires a selection'. Also no correct area measurements were performed. (see attachment). How can I perform correct area measurements of the enlarged circles? And still save these enlarged circles? And do 'Clear Outside'?

The code looks like this now:
roiManager("Reset");

getSelectionCoordinates(xpoints, ypoints);
image = getInfo("image.filename");
length = lengthOf(image)
image = substring(image,1,length-4)
dir = File.directory;

radius=2;
for (i=0; i<lengthOf(xpoints); i++) {
        makeOval(xpoints[i]-radius, ypoints[i]-radius, 2*radius, 2*radius);
        roiManager("Add");
}

roiManager("Show All");
//setTool("oval");

waitForUser("Select each circle, then CTRL-SHIFT-drag handles to enlarge.\nOK when done.");

saveAs("Selection", dir+image+".roi");

roiManager("Multi Measure");
saveAs("Results", dir+image+".xls");

setBackgroundColor(255, 255, 255);
run("Clear Outside");

saveAs("BMP", dir+image+"_clear.bmp");

close();


Thank you!

Koen

ir. Koen Marien

Imaging Scientist, PhD student

Lab building, 1st floor (campus ZNA Middelheim)

Lindendreef 1, 2020 Antwerpen (Belgium)        Phone: +32 (0)3 218 19 17

https://www.uantwerp.be/en/staff/koen-marien/

________________________________________
Van: Michael Schmid [[hidden email]]
Verzonden: woensdag 5 maart 2014 18:37
Aan: Marien Koen
CC: Michael Schmid
Onderwerp: Re: Draw circles on pre-defined point annotations in an image and measure the area/readius of these circles

Hi Koen,

probably it would be better to post to the ImageJ mailing list (I am just a user like many others...)

I can't reproduce your problem in a quick test. I made a multi-point selection (using 'Process>Find Maxima'), saved the roi and (after running the macro) the image as bmp, closed ImageJ, loaded the image got a new image and loaded the .roi again.

I took the following simplified version of the macro (I did not care about directory, etc.)


//in contrast do 'Delete' 'Reset' works also if the Roi Manager is empty
roiManager("Reset");
getSelectionCoordinates(xpoints, ypoints);
//print(lengthOf(xpoints));
radius=2;
for (i=0; i<lengthOf(xpoints); i++) {
        makeOval(xpoints[i]-radius, ypoints[i]-radius, 2*radius, 2*radius);
        roiManager("Add");
}
roiManager("Show All");
waitForUser("Select each circle, then CTRL-SHIFT-drag handles to enlarge.\nOK when done.");

The Roi Manager got a nice list, both with the saved .bmp and (in a second attempt) with a new image.

The only problem I noticed: 'Labels' has to be enabled in the Roi Manager; otherwise one can't select the circles with the mouse.

And, as written above, roiManager("Delete") needs a roi or several of them in the Roi Manager to delete. If the ROi Manager is closed or empty, it will cause an error 'The list is empty'.

I am using plain ImageJ 1.48s16, not Fiji.

Michael
________________________________________________________________
On Mar 5, 2014, at 16:01, Marien Koen wrote:

> Dear Michael
>
>
> I have tried the code by pasting it into a new macro (Plugins>New>Macro). I did a multi-point selection and ran the macro. It worked!
> This is how the code looks like:
> getSelectionCoordinates(xpoints, ypoints);
> image = File.nameWithoutExtension;
> dir = File.directory;
>
> roiManager("Delete");
>
> radius=2;
> for (i=0; i<lengthOf(xpoints); i++) {
>       makeOval(xpoints[i]-radius, ypoints[i]-radius, 2*radius, 2*radius);
>       roiManager("Add");
> }
> roiManager("Show All");
> waitForUser("Select each circle, then CTRL-SHIFT-drag handles to enlarge.\nOK when done.");
>
> saveAs("Selection", dir+image+".roi");
>
> setBackgroundColor(255, 255, 255);
> run("Clear Outside");
>
> saveAs("BMP", dir+image+"_clear.bmp");
>
> roiManager("Multi Measure");
> saveAs("Results", dir+image+".xls");
>
> close();
>
>
> But could you help me again?
> When I save a multi-point selection, close Fiji and restart it. Open the image and open associated multi-point selection again (.roi). When I run the save macro (Plugins>Macros>Run), it does not work!
>
> I get the window 'Roi Manager': The list is empty., then I press OK, then nothing happens... The ROI Manager is empty, the selection is visible on the image.
> I updated my Fiji to the latest version (Help>Update Fiji)
>
>
> Koen
>
>
> ir. Koen Marien
>
> Imaging Scientist, PhD student
>
> Lab building, 1st floor (campus ZNA Middelheim)
>
> Lindendreef 1, 2020 Antwerpen (Belgium)        Phone: +32 (0)3 218 19 17
>
> https://www.uantwerp.be/en/staff/koen-marien/
>
> ________________________________________
> Van: ImageJ Interest Group [[hidden email]] namens Marien Koen [[hidden email]]
> Verzonden: dinsdag 4 februari 2014 13:56
> Aan: [hidden email]
> Onderwerp: Re: Draw circles on pre-defined point annotations in an image and measure the area/readius of these circles
>
> Thanks Michael! Looks great. I am a total newbie, but I try to work it out!
>
> Best regards
> Koen
>
> ir. Koen Marien
>
> Imaging Scientist, PhD student
>
> Lab building, 1st floor (campus ZNA Middelheim)
>
> Lindendreef 1, 2020 Antwerpen (Belgium)        Phone: +32 (0)3 218 19 17
>
> https://www.uantwerp.be/en/staff/koen-marien/
>
> ________________________________________
> Van: ImageJ Interest Group [[hidden email]] namens Michael Schmid [[hidden email]]
> Verzonden: maandag 3 februari 2014 16:12
> Aan: [hidden email]
> Onderwerp: Re: Draw circles on pre-defined point annotations in an image and measure the area/readius of these circles
>
> Hi Koen,
>
> what you can do:
>
> You can save the (multi-) point selection with Save As>Selection or using the ROI Manager. To see how it is done in a macro, use Plugins>Macro>Record.
>
> Load the selection, and write a macro:
>  getSelectionCoordinates(xpoints, ypoints);
> gives you the coordinates. Then make sure the ROI mamager is empty:
>  roiManager("Delete");
> Have a loop, e.g.,
>  radius=2;
>  for (i=0; i<lengthOf(xpoints); i++) {
>    makeOval(xpoints[i]-radius, ypoints[i]-radius, 2*radius, 2*radius);
>    roiManager("Add");
>  }
>  roiManager("Show All");
>  waitForUser("Select each circle, then CTRL-SHIFT-drag handles to enlarge.\nOK when done.");
>
> //(mind the line break possibly introduced by the mailer; the waitForUser command should be one line)
>
> With 'Show All' in the Roi Manager, you can click on each selection to make it active, then drag its handles with the SHIFT and CTRL keys down to enlarge it to the desired size. (Mac: shift and cmd keys down). CTRL keeps the center and SHIFT constrains it to a circle.
> If you want to have all circles with the same size, this is not necessary, of course.
>
> Finally, have a loop
>  for (i=0; i<roiManager("count"); i++) {
>    roiManager("select", i);
>    getSelectionBounds(x, y, width, height);
>    //and do whatever you want: measure, print something to the log,
>    //or whatever.
>  }
> If you just want to measure, you need no loop, just use
>  roiManager("Multi Measure");
>
> See the description of the macro functions:
>  http://rsb.info.nih.gov/ij/developer/macro/functions.html
>
> Make sure you update ImageJ to the latest daily build; there was a bug possibly affecting macro recording of saving rois.
>
> Michael
> ________________________________________________________________
> On Jan 31, 2014, at 15:28, Marien Koen wrote:
>
>> Hi there
>>
>>
>> I want to do a study that measures the influence of the size of regions of interest (ROIs) and want to do the following:
>>
>> 1) create multiple (n=10-20) point annotations in images and save them, allowing to go to them when later opening the image again
>> 2) draw circles on these point annotations but in such a way that a point annotation is the centre of the circle
>> 3) remember the radius/area/perimeter of these circles and export them in a structured way
>>
>> Ideally I can do this on my very big images (Mirax files), but it may also be possible to create some images (.jpg, .bmp, ...) of certain regios in the Mirax file and do the circle drawing on these.
>>
>>
>> All help and suggestions welcome
>>
>> Thanks!
>> Koen
>>
>>
>>
>> ir. Koen Marien
>>
>> Imaging Scientist, PhD student
>>
>> Lab building, 1st floor (campus ZNA Middelheim)
>>
>> Lindendreef 1, 2020 Antwerpen (Belgium)        Phone: +32 (0)3 218 19 17
>>
>> https://www.uantwerp.be/en/staff/koen-marien/
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

Screenshot542 2014-03-06, 11_56_08.jpg (247K) Download Attachment