Dear users, I need your suggestions.
I have a stack of images, each stack slice an IHC of a unique hindbrain (obex) section. I've managed to create a macro to create a grid of measurement window ROIs (of uniform dimensions interactively specified by user) which are subsequently used to measure the Area Fraction above threshold per window ROI. The problem is that each hindbrain is a unique shape and variably fills its slice. Thus many of the measurement windows are outside the actual tissue borders. I can't just exclude post-measurement all Area Fraction measurements of zero because there are many such measures made within the obex borders. I've written a macro that creates an "obex ROI" for each stack slice, thinking I could somehow use a reference for selecting measurement window ROIs for measurement or deletion. Also note, that I do not want measurements of partial window ROIs as might be derived from using the "AND" join of the obex ROI and each measurement window. I think the solution is to iterate through the ROI Manager and, within each stack slice, either delete all measurement window ROIs not completely contained within the obex ROI or to only select for use those measurement window ROIs that are completely contained with the obex ROI? Another idea, perhaps less elegant, is to remove measurements post-analysis that do not meet similar spatial criteria. Unfortunately, I'm struggling to get any of these ideas to work. All ideas welcome. Dave |
Dave
What you describe can be done with Java (Not so sure about IJ Macro - I don't really use it) To test if a given subROI is inside the PrimaryROI you would take the following steps: 1) create a working copy of the subROI to be tested (converted to a ShapeRoi object) 2) perform the boolean NOT operation on the subROI and PrimaryROI subROI.not(PrimaryROI); [this subtracts all of the areas common to the two, from the subROI] if the subROI is only partially inside the PrimaryROI then you'll be left with a residualROI (outside the primary). If not, you will be left with an empty ROI. 3) get the height and width of the rectangle that is the bounding box of the residualROI and check to see if they are both 0. If they are both 0, then the subROI must have been inside as what is left has no size. By repeating for all of the subROI objects, you are able to work out which are completely in, which are partially in and which are completely out. Hope this helps Conor -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by daschneider9
As a follow up to previous reply:
I selected subtraction of the ROIs so that you only had to check if anything was left. The same can be obtained by performing an AND boolean, but you would then have to check the area of both the initial subROI and the result of the boolean operation and ensure they're the same size. If they are then the subROI was inside, if they're different, then it was partially in, or not at all. Cheers Conor -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by daschneider9
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(); |
In reply to this post by daschneider9
Dave
You can find some examples of how to make Java plugins on the Fiji website (Fiji.sc). Thankfully, it's possible to create complete plugins inside ImageJ, so you don't need additional software. There's a lot of helpful stuff there and you'll begin to see similarities emerging between Java and IJMacro. It's certainly a good place to start. Good luck! Conor -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |