Re: Eliminate ROI not completely inside primary ROI
Posted by daschneider9 on Jan 24, 2014; 2:40pm
URL: http://imagej.273.s1.nabble.com/Eliminate-ROI-not-completely-inside-primary-ROI-tp5006245p5006260.html
Conor,
I haven't tried learning Java coding and, as you can tell, I pretty amateur when it comes to IJ macro coding. I think similar to your suggestion, however, I realized that I could use a stack of obex masks to query if a selection (not yet a ROI in the manager) is equal to background (0 in my case where the obex mask is black on white background). If so, then add it to the ROI manager and create the next selection. I've shown my coding below and it is working for me but it is very slow: my stack is ~1 gigabyte and the measuring windows are based on dividing the image width and height into 125 columns and rows. If I can figure it out, I'm hoping your suggestion of doing this in Java will be much more time efficient. Any other coding comments are welcome. I'm sure I can stand to learn a lot more.
Thank you for you suggestions,
Dave
//Create custom grids per stack slice
//01. Open obex mask stack
folder="";
folder = getDirectory("Select folder containing obex mask stack");
open();
run("Set Measurements...", " area_fraction display redirect=None decimal=0");
//02. Create ROI grid for the stack
// Initialize all variables.
columns=0; rows=0; spacing=0;
box_w=0; box_h=0; box_cx=0; box_cy=0;
xcenter=0; ycenter=0;
r=0; i=0;
getDimensions(width, height, channelCount, sliceCount, frameCount);
xcenter=width/2; ycenter=height/2;
// Create grid based on user input.
Dialog.create("Grid dimensions");
Dialog.addMessage("Describe the grid to create?")
Dialog.addNumber("Number of columns:", 125);
Dialog.addNumber("Number of rows:", 125);
Dialog.addNumber("Spacing (pixels):", 0);
Dialog.show();
columns=Dialog.getNumber();
rows=Dialog.getNumber();
spacing=Dialog.getNumber();;
for(s=0; s<sliceCount; s++) {
box_w=(width/columns)-spacing;
box_h=(height/rows)-spacing;
box_cx=(spacing+box_w)/2;
box_cy=(spacing+box_h)/2;
setSlice(s+1);
for(r=0; r<rows; r++) {
for(i=0; i<columns; i++) {
//use following line to debug
//print(box_cx);
run("Specify...", "width=&box_w height=&box_h x=&box_cx y=&box_cy centered");
run("Measure");
a = getResult("%Area");
//print(a);
if (a==0) {
run("Add to Manager");
}
box_cx=box_cx+box_w+spacing;
}
i=0;
box_cx=(spacing+box_w)/2;
box_cy=box_cy+box_h+spacing;
}
r=0;
roiManager("Deselect");
}
roiManager("Save", folder+"ROI-obex.zip");
selectWindow("ROI Manager");
run("Close")
selectWindow("Results");
run("Close");
close();