ROI naming issues and ROI persistent on image

Hiya,

I made a short macro to crop around nuclei from a bigger image (see below):

  • makes cell contour from max proj -> rename to “Cell Contour roi”)
  • dilate
  • get bounds of contour
  • get the bounding rectangle
  • enlarge by XX pixels, -> rename to “Cell Bounding box roi”)
  • crop the original picture and savo various rois

and it generally works but I have 2 problems:

  1. it renames the original cell contour correctly, creates the bounding box and enlarged “make rectangle” correctly, but does not rename it as cell bounding box, but instead renames the initial contour to cell bounding box.
    I though “make rectangle” would deselect the first ROI and select the rectangle that has been created.
    Any ideas what I made wrong?
  2. when I open the cropped images in fiji afterwards, they still have the contour on it, even if I do deselect, or select none, they remain (but not if I open them in Icy for instance).
    How can I get rid of them? (can’t seem tobe able to insert an image)

I need to send these crops to a collaborator for further analysis, so need to get rid of those rois! help!!

Cheers

Debbi

//work in progress macro by Debora Keller Olivier deborakeller0@gmail.com
//initialise
roiManager("Reset");
run("Clear Results");

//select location where images are stored & where processed images should go
//Dialog.create("Batch Processing - SIM Thresholding");
//Dialog.addCheckbox("Use Bio-Formats Importer ", true);

Dialog.create("Number of Pixels to Expand Bounding Box by ");
Dialog.addNumber("Number of Pixels:", 35);
Dialog.show();

//Bio=Dialog.getCheckbox();
L=Dialog.getNumber();
		
input = getDirectory("location where images are stored");
output = getDirectory("Location for results");
list = getFileList(input);

setBatchMode(true);
//sets to false if want to see intermediate images


//loop to sequentially open images (=FUNCTION 1)
for (im=0; im<list.length; im++){{
full = input + list[im];

//if (Bio==true){
run("Bio-Formats Importer", "open=full autoscale color_mode=Composite view=Hyperstack stack_order=XYCZT");
//} else {
//open(full);
//}

//Get the name without the extension
fn=getTitle();
ShortFileName=substring(fn, 0, lastIndexOf(fn,"."));
out = output + ShortFileName;


//make rois of nuclei using channel 1 Lamin MAx Proj
run("Duplicate...", "title=original duplicate");
run("Duplicate...", "duplicate channels=1");
rename("C1");
run("Z Project...", "projection=[Max Intensity]");
run("Gaussian Blur...", "sigma=5");
setAutoThreshold("Default dark");
//run("Threshold...");
setAutoThreshold("Default dark");
setOption("BlackBackground", true);
run("Convert to Mask");
run("Fill Holes");
run("Dilate");
run("Dilate");
//run("Adjustable Watershed", "tolerance=0.5");
//run("Watershed") in case of touching cells;
run("Analyze Particles...", "size=1000-Infinity pixel show=Outlines display exclude clear add");


n=roiManager("Count");
Cells=newArray(n);

//for each roi
for (roi=0;roi<n;roi++){
	selectWindow("original");
	roiManager("Select",roi);
	roiManager("Rename","Cell Contour "+roi+1);
	Roi.getBounds(x, y, w, h);
	makeRectangle(x-L, y-L, w+2*L, h+2*L);
	roiManager("add");
	//roiManager("Rename","Cell-Bounding-Box "+roi+1);
	run("Duplicate...", "duplicate channels=1-3");
	rename(ShortFileName+"_cell" + roi+1);
	print(ShortFileName+"_cell" + roi+1 + "done");
	outcell = out + "_cell" + roi+1;
	saveAs("tiff", outcell); //saves new image crop
	
	}
//cleanup after saving - save all ROI sets	
 roiManager("deselect");
 outROI = out + "_crops";
 roiManager("Save", outROI +".zip");
 roiManager("Reset");


 //output totals
Array.show("Crops in image",Cells);
}
run("Close All");
}

Do you want to create cell ROIs in roiManager[0…n] and bounding boxes in roiManager[n+1…2*n]?

Or do you want to insert the bounding box in the roiManager between the current and the next outline?
A minimal example using one of the sample images would be nice. Not having an image at hand to trace your code, I expect that roi[n+1] will be overwritten by your outline during loop execution.

After you select roi, you rename the roi as Cell Contour [n+1], then you add a rectangular roi, but you don’t select a/its roiManager entry (of the new rectangle ROI) before you rename the rectangle roi. In the roiManager, you need to select the bounding box rectangle first, then apply the commented-out rename command.

1 Like

THanks for this (I was away on lab retreat)-
Yes I want to have both the cell ROIs and bounding boxes.
I thought naively that ROImanager would select the rectange I just created. I will have a play coz I think there will be an indexing issue within ROI manager.
I managed to get rid of overlay by adding “hide overlay” before saving … duh!
cheers