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. 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; } } } |
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 |
This post was updated on .
Thanks a lot for your rapid answer. When I run your macro an error message appears: "No overlay in line 14. Overlay.<add Selection>"
As I never use Overlays before, I don't know what it means and what I have to change in the macro. Moreover, how can I insert my macro in your macro to get a grid with multiple rectangles and not only one in the middle of the image? I tried this but it seems that it doesn't work... run("T1 Head (2.4M, 16-bits)"); width = getWidth; height = getHeight; depth = nSlices; x = 50; y = 50; z0 = depth/4; d = depth/2; numRow= 4; numCol=4; for(i = 0; i< numRow; i++) { for(j=0;j<numCol;j++) { xOffset = j * (width); yOffset = i * (height); for (z=0; z<depth; z++) { if (z>=z0 && z<=z0+d) { makeRectangle(x+ xOffset,y+yOffset,width,height); 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"); Thanks. Thibaut |
Free forum by Nabble | Edit this page |