run("Duplicate...", "duplicate slices=Use);

Hi all,
I have image with 4 channels and 10 z stacks. I drew one rectangular ROI in a particular Z slice and added to the ROI manager. In the same image, I drew another rectangular ROI in a another Z slice of the same image. Now I want to duplicate selected ROI from ROI manager one by one including the duplication of all channels but only selecting the particular Z slice that was marked with ROI selection.

Currently I have tried following options:

  1. run(“Duplicate…”, " "); // which duplicates only the current channels and current z stack. (This would be perfect but I need this with all the channels)

  2. run(“Duplicate…”, “duplicate”);// which duplicates all channels and all the z stack.

  3. I can get eventually what I want using the follwing code but then I have to do it manually and I can not automatize it in the macro because every time I need to select different ROI which are in different Z slices. So I have to manually add the slice number.
    run(“Duplicate…”, “duplicate slices=10”);

I am currently using following code: I am adding the ROI to roi manager and then run following code which go through all the ROIs into ROI manager and perform duplication. I would like to make it automatic and not that I have to add the slice number manually for each ROI in the following code.

for (j = 0; j < Roi_manager_list; j++) {
				slices = roiManager("Select", j);
				run("Duplicate...", "duplicate slices=10");
				//run("Duplicate...", " ");
				Current_Slice_title = title1_save + "_PNN"+ "_" + j +".tif";
				Current_Slice_path = input + "/1_Cropped_PNN/";
				File.makeDirectory(Current_Slice_path);
				saveAs("Tiff", Current_Slice_path+Current_Slice_title);
				close();

I would highly appreciate any help.
Thanks a lot
Kind regards
Rahul

Hi Rahul (@Rahul),

Welcome to the forum.

“Make Substack” will help. It’s in
Image > Stacks > Tools > Make Substack....

This macro call:

run("Make Substack...", "channels=1-2 slices=3");

will do the trick (after replacing the numbers appropriately).

Good luck,
John

1 Like

Hi John, Thanks a lot for the quick and kind reply.
Unfortunately, it is problem to make it automatic when I have the ROI selected in the ROI manager which are present in the different Z slices. The macro that I originally posted can make the duplicate or substack of different ROI but none of them are taking the correct Z slice when they are integrated into a larger macro. In other words, if I have two ROI selected and added to the ROI manager and I click on them one after the another, they are going to the same Z slice in the image where they were originally created. But somehow when I make macro to make it automatic (to take all the ROI present in the ROI manager) this information from the ROI manager is not passing to the next code lines whether its Duplicating them or making Substack.

Anyways, Thanks a lot for your reply.

best regards
Rahul

Hi Rahul,

When you select each ROI manager it is associated with the slice it was made on and therefore will go to that slice within your stack. You can then use Stack.getPosition to get that slice and use the variable storing the slice number in your subsequent Duplicate command.

count = roiManager("Count");
img = getTitle();

for (i = 0; i < count; i ++){
	selectWindow(img);
	roiManager("Select", i);
	Stack.getPosition(channel, slice, frame);
	run("Duplicate...", "duplicate slices=" + slice);
}

Hope that helps!

2 Likes

Wow. That was excellent. It totally worked. Great help. Thanks a lot Laura Murphy :slight_smile:

1 Like