Posted by
Kenneth Sloan-2 on
URL: http://imagej.273.s1.nabble.com/multi-color-overlays-tp5021290.html
I'm stumbling through an attempt to use Overlays...
Java plugin (not macro)
I would *really* like to put overlays on a single slice of a stack containing multiple FloatProcessor images. I suspect
that this doesn't work. So, while I verify that, I'm working with a single ImagePlus displaying a ColorProcessor.
The desired Overlay has several ROI elements - each with it's own StrokeWidth and Color. Sample code fragment is shown below.
My problem is that all the ROIs are displayed with the same color - the color assigned to the last ROI added to the Overlay.
Question: is this the expected behavior? If not, what am I doing wrong? Should I be using a different technique all together?
In extremis, I suppose that I could re-create the ColorProcessor image on every change to the annotation, and destructively draw the overlay information on the image - but that seems wasteful. I'd really like to leave the image intact, and simply re-create the Overlay.
I suppose another option is to create an Image Roi and draw the multi-colored vector graphics on it. But, the code below seems to be the "right" way to do it. I would appreciate an explanation of why it doesn't work, and advice on the best technique to use.
Here's the relevant code (everything is drawn in the right place and at the right scale, but it's all RED):
// create window for centering
ColorProcessor cpMPOD = fpMPOD.convertToColorProcessor();
// draw overlay showing center
ImagePlus ipMPOD = new ImagePlus("MPOD", cpMPOD);
Overlay crosshairOverlay = new Overlay();
Roi horizontalAxis = new Line(0.0, (double) this.foveaY,
(double) width, (double) this.foveaY);
horizontalAxis.setStrokeWidth(1.0f);
horizontalAxis.setColor(Color.WHITE);
crosshairOverlay.add(horizontalAxis);
Roi verticalAxis = new Line((double) this.foveaX, 0.0,
(double) this.foveaX, (double) height);
verticalAxis.setStrokeWidth(1.0f);
verticalAxis.setColor(Color.WHITE);
crosshairOverlay.add(verticalAxis);
double oval6Radius = 6.0*(double)width/(double)this.angle;
double oval6X = this.foveaX - oval6Radius;
double oval6Y = this.foveaY - oval6Radius;
double oval6Diameter = oval6Radius * 2.0;
Roi circle6Degree = new OvalRoi(oval6X,oval6Y,oval6Diameter,oval6Diameter);
circle6Degree.setStrokeWidth(1.0f);
circle6Degree.setColor(Color.GREEN);
crosshairOverlay.add(circle6Degree);
double oval2Radius = 2.0*(double)width/(double)this.angle;
double oval2X = this.foveaX - oval2Radius;
double oval2Y = this.foveaY - oval2Radius;
double oval2Diameter = oval2Radius * 2.0;
Roi circle2Degree = new OvalRoi(oval2X,oval2Y,oval2Diameter,oval2Diameter);
circle2Degree.setStrokeWidth(1.0f);
circle2Degree.setColor(Color.BLUE);
crosshairOverlay.add(circle2Degree);
double oval1Radius = 1.0*(double)width/(double)this.angle;
double oval1X = this.foveaX - oval1Radius;
double oval1Y = this.foveaY - oval1Radius;
double oval1Diameter = oval1Radius * 2.0;
Roi circle1Degree = new OvalRoi(oval1X,oval1Y,oval1Diameter,oval1Diameter);
circle1Degree.setStrokeWidth(1.0f);
circle1Degree.setColor(Color.RED);
crosshairOverlay.add(circle1Degree);
ipMPOD.setOverlay(crosshairOverlay);
ipMPOD.show();
--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html