Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Mar 13, 2014; 6:08pm
URL: http://imagej.273.s1.nabble.com/Creation-of-a-3D-ROIs-tp5006882p5006905.html
On Mar 12, 2014, at 6:41 AM, Galathorn wrote:
> Hi all,
>
> I would like to create a rectangular 3D ROI grid to measure the spatial
> homogeneity of particles in a 3D volume. I tried the following macro but it
> only works in 2D. When I make a 3D object and if I modify the macro adding a
> third component it doesn't work... I'm not very good for coding macros, I
> found the model of the code for 2D ROI grid in this forum. Any idea? Thanks.
Here is an example macro that opens the "T1 Head" sample stack, creates a 3D ROI (as an overlay) and measures each ROI in the 3D ROI. It uses an overlay because that is faster and more reliable than using the ROI Manager.
-wayne
run("T1 Head (2.4M, 16-bits)");
width = getWidth;
height = getHeight;
depth = nSlices;
x0 = width/4;
y0 = height/4;
z0 = depth/4;
w = width/2;
h = height/2;
d = depth/2;
for (z=0; z<depth; z++) {
if (z>=z0 && z<=z0+d) {
makeRectangle(x0,y0,w,h);
Overlay.addSelection;
Overlay.setPosition(z+1);
}
}
run("Clear Results");
setOption("Stack Position");
for (i=0; i<Overlay.size; i++) {
Overlay.activateSelection(i);
run("Measure");
}
run("Select None");
> x = 130;
> y = 80;
> width =160;
> height = 160;
> spacing = 0;
> numRow = 4;
> numCol = 4;
>
> 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") > 500)
> {
> print("Maximum reached: 500 entries have been created.");
> exit;
> }
> }
> }
>
> --
> View this message in context:
http://imagej.1557.x6.nabble.com/Creation-of-a-3D-ROIs-tp5006882.html> Sent from the ImageJ mailing list archive at Nabble.com.
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html