Difficulty to assign different colors to ROIs in overlay

Hi all,

I am trying to store different multi-point ROIs on different stack slices in a plugin. I would like to give different multi-point ROI groups on different slices a different color to enable better distinguishably between them. My current problem is that changing the ROI color consecutively changes the color of all ROIs. Even those I already added to the overlay.
I tried Roi.setColor() but that didn’t work and I assumed that this static method generally assigns the same color to all ROIs.

Here is a code snippet where this takes place:

int binSize = (int) Math.floor(255/inputImp.getStackSize());

int red = 255;
int green = 0;
int blue = 0;

for(int s1=1; s1<inputImp.getStackSize(); s1++) {
				
        inputImp.setSlice(s1);
				
        for(int s2=s1+1; s2<=inputImp.getStackSize(); s2++) {

	        inputImpCopy.setSlice(s2);
	
		Roi roi1 = inputImp.getRoi();
		roi1.setPosition(s1);
		roi1.setFillColor(new Color(red, green, blue));
		overlay1.add(roi1);
		inputImp.setOverlay(overlay1);
		inputImp.killRoi();
					
		Roi roi2 = inputImpCopy.getRoi();
		roi2.setPosition(s1+1);
		roi2.setFillColor(new Color(red, green, blue));
		overlay2.add(roi2);
		inputImpCopy.setOverlay(overlay2);
		inputImpCopy.killRoi();		
	}
	red -= binSize;
	green += binSize;
}

Any hint is greatly appreciated.

Hi @biovoxxel,

When I wanted to paint my segmented cell overlays way back I ended up using setStrokeColor. Maybe you can try that.

In python (not runnable without my colorldicts, but you only need the command anyways):

# rois = rm.getCount()
for roi in range(rois):
	roi_obj = rm.getRoi(roi)
	roi_obj.setStrokeWidth(2)		
	if roi < 19:
		roi_obj.setStrokeColor(Color(*Colors[roi][0:3]))
	else:
		roi_obj.setStrokeColor(eval(Colors_old[roi]))
1 Like

Hi @Sverre,

thanks for the tip. that does the job partially. At least it adjusts the roi colors per slice separately for now.

[Edit]: solved it. I still had a small mistake in. So, roi.setStrokeColor(Color) does the job. Thanks!

1 Like