FIJI make overlay bug

roi-manager
overlay
fiji
Tags: #<Tag:0x00007fd543157000> #<Tag:0x00007fd543156e20> #<Tag:0x00007fd543156c40>

#1

I am running FIJI v 1.51p on Max OS 10.10.5.

I’m having trouble adding overlays to multichannel hyperstacks, using a selection defined by an ROI from within the RoiManager. I initially encountered this problem when generating overlays from ROIs within a macro, but I have realized that the same problem also occurs from within the ImageJ GUI, which I have described below:

I have a two-channel hyperstack, and would like to add an overlay to both channels, using an ROI defined only by a feature in channel 2.

I define a selection based on some pixels in channel 2 and add this selection as an ROI to RoiManager.

I deactivate the option “Set stack positions” from within “Image > Overlay > Overlay Options…”. According to the ImageJ documentation, this configuration should allow an overlay defined in one channel to be added to all channels in a multichannel hyperstack. (This option does work as documented when an overlay is made directly from a selection, without going through RoiManager.)

I select the ROI from within RoiManager.

I make the overlay using Image > Overlay > Add Selection… .

The result: the overlay only gets added to channel 2 and NOT to channel 1 under this configuration. (When the option “Set stack positions” is activated from within “Image > Overlay > Overlay Options…”, then the overlay gets added to all channels of the hyperstack.)

This problem also occurs when an overlay is generated from an ROI defined in the other channel.

Thanks!


#2

Could you provide a small macro that reproduces this problem? The following macro works as expected. It creates an ROI on channel 2, slice 3 of a hyperstack, adds it to an overlay, and runs the Image>Overlay>List Elements command, which shows that the ROI is at the expected position of (0,3,0).

run("Confocal Series (2.2MB)");
Stack.setPosition(2,3,1);
makeOval(100, 145, 144, 176);
run("Add Selection...");
run("Select None");
run("List Elements");

#3

I’ve added lines 1, 5, and 6 to your script. The macro works as expected with lines 5 and 6 omitted (i.e., the overlay is visible in both channels), whereas including lines 5 and 6 makes the overlay visible only in channel 2. The only difference is using a selection from the RoiManager, not explicitly changing the Overlay Options.

/* 1 */	run("Overlay Options...", "stroke=cyan width=1 fill=none")
/* 2 */	run("Confocal Series (2.2MB)");
/* 3 */	Stack.setPosition(2,3,1);
/* 4 */	makeOval(100, 145, 144, 176);
/* 5 */	roiManager("add");
/* 6 */	roiManager("select", 0);
/* 7 */	run("Add Selection...");
/* 8 */	run("Select None");
/* 9 */	run("List Elements");

#4

Your modified version of the macro will work as expected if you add ‘set’ (“Set stack positions”) to the first line. Without the ‘set’, the ROI is added to the overlay using its ROI Manager position of (2,3,1).

run("Overlay Options...", "stroke=cyan width=2 fill=none set")
run("Confocal Series (2.2MB)");
Stack.setPosition(2,3,1);
makeOval(100, 145, 144, 176);
roiManager("add");
roiManager("select", 0);
run("Add Selection...");
run("Select None");
run("List Elements");

#5

OK, I realize your solution works but I don’t understand why.

In macro 1 below, the overlay gets displayed in ALL slices and in BOTH channels. However, in macro 2, the overlay gets displayed ONLY in slice 3 and ONLY in channel 2. Why? The stack position is explicitly defined at (2, 3, 1) in either case. Why would unselecting the “set” parameter override this position in macro 1 but not in macro 2? This behavior was to me totally unexpected when I had first encountered it.

macro "1" {
	run("Overlay Options...", "stroke=cyan width=2 fill=none")
	run("Confocal Series (2.2MB)");
	Stack.setPosition(2,3,1);
	makeOval(100, 145, 144, 176);
	//roiManager("add");
	//roiManager("select", 0);
	run("Add Selection...");
	run("Select None");
}

macro "2" {
	run("Overlay Options...", "stroke=cyan width=2 fill=none")
	run("Confocal Series (2.2MB)");
	Stack.setPosition(2,3,1);
	makeOval(100, 145, 144, 176);
	roiManager("add");
	roiManager("select", 0);
	run("Add Selection...");
	run("Select None");
}

#6

The ROI in the second macro has its position set to (2,3,1) by the ROI Manager and this position is used when the ROI is added to the overlay. Use the Edit>Selection>Properties command, or the “Properties” button in the ROI Manager, to see the position of an ROI. Use Overlay.setPosition(0,0,0) to reset the position of an ROI added to an overlay. The following version of your second macro does this.

run("Overlay Options...", "stroke=cyan width=2 fill=none")
run("Confocal Series (2.2MB)");
Stack.setPosition(2,3,1);
makeOval(100, 145, 144, 176);
roiManager("add");
roiManager("select", 0);  
run("Add Selection...");
Overlay.setPosition(0,0,0);
run("Select None");

#7

With the latest ImageJ daily build (1.51p2), when adding an ROI from a hyperstack to the ROI Manager, the channel position is set to 0 (display in all channels) if the display mode is “Composite”. This is similar to what happens when an ROI is added to an overlay.


#8

@Wayne

Thank you very much for all of the above suggestions.

However, I am still experiencing issues with making overlays through a macro, particularly using batch mode. The example script below reproduces a problem I have encountered in a macro that I have been developing.

Basically, a set of ROIs is generated per frame of a hyperstack, and then converted into an overlay that is added to that respective frame (the script only iterates over two frames for simplicity). The script produces the expected output when batch mode is OFF. However, setting batch mode to ON generates overlays that are completely different.

(I am running FIJI v 1.51q4 on Mac OS 10.10.5)

setBatchMode(false);

run("Overlay Options...", "stroke=cyan width=0.1 fill=none set");
run("Mitosis (26MB, 5D stack)");

for( frame = 1; frame <= 2; frame++ ) {

run("Select None");
roiManager("reset");

// generate ROIs
run("Duplicate...", "duplicate channels=1 slices=1 frames=" + frame);	// generates a new window
run("Find Maxima...", "noise=1000 output=[Single Points] exclude");		// generates a new window
run("Options...", "iterations=1 count=1 do=Dilate");
run("Analyze Particles...",	"add slice");
run("Close");
run("Close");

// combine ROIs
nROI = roiManager("count"); 
roiArray = newArray(nROI);	
for( roi = 0; roi < nROI; roi++ ) {
	roiArray[roi] = roi;
}
roiManager("Select", roiArray);
roiManager("Combine");
roiManager("Delete");
roiManager("Add");

// convert combined ROI to overlay
roiManager("Select", 0);
run("Add Selection...");
Overlay.setPosition(1, 1, frame);
}

run("Select None");
roiManager("reset");

setBatchMode(false);

#9

Your macro performs fine in batch mode if you don´t add the combined ROI to the ROI manager but add it directly to the overlay.
Lines 25-32 in the macro:

roiManager("Select", roiArray);
roiManager("Combine");
roiManager("Delete");
//roiManager("Add");

// convert combined ROI to overlay
//roiManager("Select", 0);
run("Add Selection...");

The reason that this problem arises is, because the batch-mode ROI manager is somehow different from the non-batch mode ROI manager. In batch mode, it seems that when the combined ROI is added to the ROI manager it is also added to the overlay. I modified your macro to illustrate this (added lines marked with //#########). When run in batch mode, there is an overlay present even before the command “Add selection …” is called for the first time. When batch mode is set to “false” (line 2), this is not the case. Maybe @Wayne can tell if this is a bug or expected behaviour in batch mode. Here´s the modified macro:

overinfo="--------";// ##########
setBatchMode(true);

run("Overlay Options...", "stroke=cyan width=0.1 fill=none set");
run("Mitosis (26MB, 5D stack)");

for( frame = 1; frame <= 2; frame++ ) {

run("Select None");
roiManager("reset");

// generate ROIs
run("Duplicate...", "duplicate channels=1 slices=1 frames=" + frame);	// generates a new window
run("Find Maxima...", "noise=1000 output=[Single Points] exclude");		// generates a new window
run("Options...", "iterations=1 count=1 do=Dilate");
run("Analyze Particles...",	"add slice");
run("Close");
run("Close");
// combine ROIs
nROI = roiManager("count"); 
roiArray = newArray(nROI);	
for( roi = 0; roi < nROI; roi++ ) {
	roiArray[roi] = roi;
}
roiManager("Select", roiArray);
roiManager("Combine");
roiManager("Delete");
roiManager("Add");

overinfo=overinfo+"\nframe "+frame+". Info about any overlay present [no overlay added for this frame yet]: "+getInfo("overlay");// ########
// convert combined ROI to overlay
roiManager("Select", 0);
run("Add Selection...");
Overlay.setPosition(1, 1, frame);
}

run("Select None");
roiManager("reset");

setBatchMode(false);
print(overinfo);// ############