Duplicate ROIs by type ( selectionType() )

Hi,

I would like to make a macro that allows me to execute those commands:

  • open an image
  • draw ROis
  • if there is rectangle ROIs, duplicate the image from the ROI
  • for other ROis, duplicate the image from the ROI by using clear outside.
    You can see an example of what i want to do below:

Here is the code I’m using:

// Opening an image
open(File.openDialog("Select an Image"));
full_image = getImageID();

// Draw ROI in the image of interest
run("ROI Manager...");
waitForUser("Draw ROI, then hit OK");

rectangle_roi_count = 0;
roi_count = 0;

if (selectionType() ==0){
	rectangle_roi_count = roiManager("count");
	for(i = 0; i < rectangle_roi_count; i++){
		selectImage(full_image);
		roiManager("Select", i);
		run("Duplicate...", " ");
	}
} else if (selectionType() !=0){
		roi_count = roiManager("count");
		for(i = 0; i < roi_count; i++){
		selectImage(full_image);
		roiManager("Select", i);
		run("Duplicate...", " ");
		setBackgroundColor(255, 255, 255);
		run("Clear Outside");
		}
}

Unfortunatly, it doesn’t seems to be working, when there is rectangle ROIs, it duplicate all ROIs including non rectangle.
I don’t know if what I’m trying to do is clear?

Thank you in advance,

Dina

Hi,

So finally the problem is resolved. If anyone is interested here is the code:

// Opening an image
open(File.openDialog("Select an Image"));
full_image = getImageID();

// Draw ROI in the image of interest
run("ROI Manager...");
waitForUser("Draw ROI, then hit OK");
roi_counts = roiManager("count");

for(i = 0; i < roi_counts; i++){
	selectImage(full_image);
	roiManager("Select", i);
	run("Duplicate...", " ");
	if(selectionType() !=-1){
		setBackgroundColor(255, 255, 255);
		run("Clear Outside");
	}
}

Thanks