Posted by
Herbie on
URL: http://imagej.273.s1.nabble.com/multi-color-overlays-tp5021290p5021291.html
Good day Kenneth,
I understand that you wish to see Java code, but this macro will perhaps
give you an idea of what is a way to go:
Open an image with at least one overlay, then run the macro:
// imagej-macro "_overlayFillColors" (Herbie G., 21. Dec 2017)
run( "To ROI Manager" );
idx = roiManager( "count" );
rois = Array.getSequence( idx );
for ( i=0; i < idx; i++ ) { rois[i] = d2s( 1+rois[i], 0 ); }
Dialog.create("Set Overlay Fill");
Dialog.addChoice( "Index", rois );
Dialog.addSlider( "Opacity", 0, 255, 128 );
Dialog.addSlider( "Red", 0, 255, 0 );
Dialog.addSlider( "Green", 0, 255, 0 );
Dialog.addSlider( "Blue", 0, 255, 0 );
Dialog.show();
idx = parseInt( Dialog.getChoice() ) - 1;
c = padStr( toHex( Dialog.getNumber() ) );
c = c + padStr( toHex( Dialog.getNumber() ) );
c = c + padStr( toHex( Dialog.getNumber() ) );
c = c + padStr( toHex( Dialog.getNumber() ) );
roiManager( "select", idx );
roiManager( "Set Fill Color", c );
run( "From ROI Manager" );
run( "Overlay Options...", "stroke=none width=0 fill=none" ); // removes
lable
close( "ROI Manager" );
exit();
function padStr( hex ) {
if ( lengthOf( hex ) < 2 ) { return "0" + hex; } else { return hex; }
}
// imagej-macro "_overlayFillColors" (Herbie G., 21. Dec 2017)
This macro only sets fill colors but contour coloring works quite similar.
Regards
Herbie
:::::::::::::::::::::::::::::::::::::::::::
Am 06.10.18 um 12:35 schrieb Kenneth Sloan:
> 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>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html