Login  Register

Re: Overlay Scalebar Plugins

Posted by Lim Soon Yew on May 25, 2011; 2:28am
URL: http://imagej.273.s1.nabble.com/Overlay-Scalebar-Plugins-tp3684468p3684470.html

Dear Frank,

Thank you for the overlay scalebar macro. It works nicely.

Best Regards,
John Lim
________________________________________
From: ImageJ Interest Group [[hidden email]] On Behalf Of Frank Sprenger [[hidden email]]
Sent: Monday, May 23, 2011 11:41 PM
To: [hidden email]
Subject: Re: Overlay Scalebar Plugins

Dear John,

I took a scalebar macro that Wayne at some point created and hacked around it a bit to create a scalebar overlay macro tool

I am sure that this kind of macro is not written very well, but for me it works. Give it a try

Best

Frank



pixelH = getHeight();
pixelW = getWidth();
getPixelSize(scale, pixelSize, x);
Dialog.create("Scale Bar Parameters");
Dialog.addNumber("Length in current units:", 10);
choice1 = newArray("black", "white", "red", "green", "blue", "yellow", "magenta", "cyan");
Dialog.addChoice("Color:", choice1);
choice2 = newArray("Top Left", "Top Right", "Bottom Left", "Bottom Right");
Dialog.addChoice("Position:", choice2);
Dialog.addCheckbox("Black Box", false);
Dialog.addCheckbox("Hide text", false);

Dialog.show();

inLength = Dialog.getNumber();
inColor = Dialog.getChoice();
inPos = Dialog.getChoice();

if (Dialog.getCheckbox()==true){
        bb=1;
        }else
        bb=0;

if (Dialog.getCheckbox()==true){
        ht=1;
        }else
        ht=0;

sbLength = inLength / pixelSize;
sbHeight = pixelH / 100;

if (inColor == "white"){
        setColor(255,255,255);
}else if (inColor == "black"){
setColor(0,0,0);
}else if (inColor == "red"){
setColor(255,0,0);
}else if (inColor == "green"){
setColor(0,255,0);
}else if (inColor == "blue"){
setColor(0,0,255);
}else if (inColor == "yellow"){
setColor(255,255,0);
}else if (inColor == "magenta"){
setColor(255,0,255);
}else if (inColor == "cyan"){
setColor(0,255,255);
}


if (inPos == "Top Left") {
        sbXcoord = pixelW / 30;
        sbYcoord = pixelH / 30;
} else if (inPos == "Top Right") {
        sbXcoord = pixelW - sbLength - (pixelW / 30);
        sbYcoord = pixelH / 30;
} else if (inPos == "Bottom Left") {
        sbXcoord = pixelW / 30;
        sbYcoord = pixelH - sbHeight - (pixelH / 30);
} else if (inPos == "Bottom Right") {
        sbXcoord = pixelW - sbLength - (pixelW / 30);
        sbYcoord = pixelH - sbHeight - (pixelH / 30);
}

if (bb==1)
{
inColor2="black";
sbreclenght = (sbLength + (sbLength*0.2));
if (sbreclenght < 50)
{
x = 50;
sbreclenght = x;
}else;
if (ht==1)
{
sbrecheight = (2.5*sbHeight);
sbrecYcoor = (sbYcoord-(0.75*sbHeight));
}else;
if (ht==0)
{
sbrecheight = (5*sbHeight);
sbrecYcoor = (sbYcoord-(3*sbHeight));
}else;
sbrecXcoor = (sbXcoord-(sbreclenght*0.1));
makeRectangle(sbrecXcoor, sbrecYcoor, sbreclenght,sbrecheight);
run("Add Selection...", "stroke=" + inColor + " width=1 fill=" + inColor2);
}else;

makeRectangle(sbXcoord, sbYcoord, sbLength, sbHeight);
run("Add Selection...", "stroke=" + inColor + " width=1 fill=" + inColor);

if (ht==0)
{
textSize = pixelH / 50;
textYcoord = sbYcoord - (pixelH / 200);
label = toString(inLength) + " " + scale;

setFont("SansSerif", textSize);
Overlay.drawString(label, sbXcoord, textYcoord);
Overlay.add;
Overlay.show;
}