How to create a regular grid of rectangular ROI's?

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

How to create a regular grid of rectangular ROI's?

RDD
I am looking for a convenient way to create a regular grid of rectangular ROI's.
I want, for example, an array of 5x5 rectangular ROI's of each 40x40 pixels that are spaced by 10 pixels.

Currently I achieve this by using the function "Specify ROI" by adapting the data for each ROI, clicking OK and gving a ctrl-T to add it to the ROI manager. Then I have to re-open the function "Specify ROI" again to continue with the next ROI. When I have repeated this 25 times I save the ROI's to be sure I don't have to do it again if I want to re-analyze the same data.

Is there a way to create such an array of ROI's in a more convenient way? I have already tried to read the .roi file format, but apparently it is not a text file. Is it possible to import a text file with the coordinate data?
Reply | Threaded
Open this post in threaded view
|

Re: How to create a regular grid of rectangular ROI's?

Nathaniel Ryckman
Make a macro like this:

x = 0;
y = 0;
width = 40;
height = 40;
spacing = 10;

for(i = 1; i < numRect; i++)
{
  xOffset = xScalar * i + spacing;
  yOffset = yScalar * i;
 
  makeRectangle(x + xOffset, y + xOffset, width, height);

  run("To ROI Manager");
}

I didn't actually do the math, so you'll have to edit the numbers a little. The top-left corner of your image is x = 0 and y = 0.

Good luck!
Reply | Threaded
Open this post in threaded view
|

Re: How to create a regular grid of rectangular ROI's?

Nathaniel Ryckman
In reply to this post by RDD
By the way, I don't know if you realize this, but you can simply drag your .roi file onto your imageJ menu and then the .roi will be displayed on the image that is currently open.
RDD
Reply | Threaded
Open this post in threaded view
|

Re: How to create a regular grid of rectangular ROI's?

RDD
Thanks a lot! I wasn't aware of how powerful macro's can be. After a little adaptation (as shown below) it worked like a charm.

x = 8;
y = 8;
width = 40;
height = 40;
spacing = 3;
numRow = 10;
numCol = 6;

for(i = 0; i < numRow; i++)
{
for(j = 0; j < numCol; j++)
{
xOffset = j * (width + spacing);
print(xOffset);
yOffset = i * (height + spacing);
print(yOffset);
makeRectangle(x + xOffset, y + yOffset, width, height);
roiManager("Add");
if (roiManager("count") > 100)
{
print("Maximum reached: 100 entries have been created.");
exit;
}
}
}


On Thu, Apr 7, 2011 at 10:48 PM, Nathaniel Ryckman [via ImageJ] <[hidden email]> wrote:
By the way, I don't know if you realize this, but you can simply drag your .roi file onto your imageJ menu and then the .roi will be displayed on the image that is currently open.


If you reply to this email, your message will be added to the discussion below:
http://imagej.588099.n2.nabble.com/How-to-create-a-regular-grid-of-rectangular-ROI-s-tp6250398p6251508.html
To unsubscribe from How to create a regular grid of rectangular ROI's?, click here.