// Action Bar description file : _Magic_Montage2
run("Action Bar","/plugins/ActionBar/_Magic_Montage2.txt");
exit();
label=Select panels
icon=noicon
arg=
run("Select None");
setPasteMode("copy");
w = getWidth;
h = getHeight;
getCursorLoc(x, y, z, flags);
id=getImageID;
t=getTitle;
selectImage(id);
xn = info("xMontage");
yn = info("yMontage");
if ((xn==0)||(yn==0)) {exit;}
xc = floor(x/(w/xn));
yc = floor(y/(h/yn));
panelNumber = yc*xn+xc+1;
showStatus(info("image_"+panelNumber ));
makeRectangle(xc*(w/xn),yc*(h/yn),(w/xn),(h/yn));
xstart = x; ystart = y;
x2=x; y2=y;
x2c=xc;y2c=yc;
while (flags&16 !=0) {
getCursorLoc(x, y, z, flags);
if (x!=x2 || y!=y2) {
x2c = floor(x/(w/xn));
y2c = floor(y/(h/yn));
makeRectangle(xc*(w/xn),yc*(h/yn),(w/xn)*(x2c-xc+1),(h/yn)*(y2c-yc+1));
x2=x; y2=y;
wait(10);
}
}
setPasteMode("add");
label=Extract selected
icon=noicon
arg=
t=getTitle;
xn = info("xMontage");
yn = info("yMontage");
pw = getWidth/xn;
ph = getHeight/yn;
run("Duplicate...", "title=[Extract of "+t+"]");
setMetadata("xMontage="+getWidth/pw+"\nyMontage="+getHeight/ph+"\n");
label=Mark
icon=noicon
arg=
roiManager("Add");
setOption("Show All",true);
label=Extract marked
icon=noicon
arg=
id=getImageID;
t=getTitle;
selectImage(id);
roiManager("select",0);
getSelectionBounds(x,y,sw,sh);
setBatchMode(true);
newImage("Extracted Panels of "+t, "RGB", sw,sh,roiManager("count"));
id2=getImageID;
setPasteMode("copy");
for (i=0;i
label=Draw ROI
icon=noicon
arg=
setTool(0);
label=Crop montage
icon=noicon
arg=
setBatchMode(true);
setPasteMode("copy");
w=getWidth;
h= getHeight;
b=bitDepth;
getSelectionBounds(x,y,sw,sh);
t=getTitle;
id=getImageID;
getVoxelSize(xp,yp,zp,unit);
xn = info("xMontage");
yn = info("yMontage");
xc = floor(x/(w/xn));
yc = floor(y/(h/yn));
xpa = x-xc*(w/xn);
ypa= y-yc*(h/yn);
newImage("Crop of "+t,b+"RGB",sw,sh,(xn)*(yn));
id2=getImageID;
for (j=0;j
label=Copy (c)
icon=noicon
arg=
run("Copy");
label=Paste/overlay (v)
icon=noicon
arg=
run("Paste");
label=Fit clipboard in panel
icon=noicon
arg=
getSelectionBounds(x,y,sw,sh);
id=getImageID;
setBatchMode(true);
ffp=sw/sh;
run("Internal Clipboard");
run("RGB Color");
ffc=getWidth/getHeight;
if (ffc>ffp) {
run("Size...", "width="+sw+" height="+sw/ffc+" constrain interpolate");
run("Canvas Size...", "width="+sw+" height="+sh+" position=Center zero");
} else {
run("Size...", "width="+sh*ffc+" height="+sh+" constrain interpolate");
run("Canvas Size...", "width="+sw+" height="+sh+" position=Center zero");
}
run("Copy");
close;
selectImage(id);
setBatchMode(false);
setPasteMode("Copy");
run("Paste");
label=Fill panel with clipboard
icon=noicon
arg=
getSelectionBounds(x,y,sw,sh);
id=getImageID;
setBatchMode(true);
ffp=sw/sh;
run("Internal Clipboard");
run("RGB Color");
ffc=getWidth/getHeight;
if (ffc>ffp) {
run("Size...", "width="+sw*ffc+" height="+sh+" constrain interpolate");
run("Canvas Size...", "width="+sw+" height="+sh+" position=Center zero");
} else {
run("Size...", "width="+sw+" height="+sh/ffc+" constrain interpolate");
run("Canvas Size...", "width="+sw+" height="+sh+" position=Center zero");
}
run("Copy");
close;
selectImage(id);
setBatchMode(false);
setPasteMode("Copy");
run("Paste");
label=Sync crosses
icon=noicon
arg=
w=getWidth;
h= getHeight;
getCursorLoc(x,y,z,flags);
xn = info("xMontage");
yn = info("yMontage");
if ((xn==0)||(yn==0)) {exit("Not a Magic Montage\nset layout first");}
xc = floor(x/(w/xn));
yc = floor(y/(h/yn));
x0 = x-xc*w/xn;
y0 = y-yc*h/yn;
xp =newArray(xn*yn);
yp =newArray(xn*yn);
for (i=0;i
label=A B C D
icon=noicon
arg=
xn = info("xMontage");
yn = info("yMontage");
str=getpref("MM.str","ABCDEFGHIJKLMNOPQRSTUVWXYZ");
lcas=getpref("MM.lcas",0);
antialiasedLabels = getpref("MM.antialiased",1);
n=parseInt(getpref("MM.n","0"));
xoffset=getpref("MM.xoffset",0.05);
yoffset=getpref("MM.yoffset",0.05);
pos=getpref("MM.pos","Clicked quadrant");
getCursorLoc(x, y, z, flags);
iw = getWidth/xn;
ih = getHeight/yn;
co = floor(x/iw);
li = floor(y/ih);
fontsize = ih/10;
if (fontsize<12) fontsize=12;
marque = substring(str,n,n+1);
if (lcas==1) marque= toLowerCase(marque);
opt="";
if (pos == "Clicked quadrant") {
xoffset=0.05; yoffset=0.05;
if (x>((co+0.5)*iw)) xoffset=0.90;
if (y<((li+0.5)*ih)) yoffset=0.85;
}
if (antialiasedLabels==true) opt=opt+"antialiased";
setFont("SanSerif",fontsize, opt);
if (isKeyDown('shift')) { setForegroundColor(255,255,255); } else {setForegroundColor(0,0,0); }
drawString(marque ,co*iw+xoffset*iw,(li+1)*ih-yoffset*ih);
if (isKeyDown('shift')) { setForegroundColor(0,0,0); } else { setForegroundColor(255,255,255); }
drawString(marque ,co*iw+xoffset*iw+1,(li+1)*ih-yoffset*ih+1);
n++; if (n>lengthOf(str)-1) n=0;
setpref ("MM.n",n);
label=...
icon=noicon
arg=
str=getpref("MM.str","ABCDEFGHIJKLMNOPQRSTUVWXYZ");
lcas=getpref("MM.lcas",0);
antialiasedLabels = getpref("MM.antialiased",1);
n=parseInt(getpref("MM.n","0"));
xoffset=getpref("MM.xoffset",0.05);
yoffset=getpref("MM.yoffset",0.05);
pos=getpref("MM.pos","Clicked quadrant");
if (nImages>0) setupUndo;
Dialog.create("Annotation - Options");
Dialog.addString("Labels",str);
Dialog.addCheckbox("Lowercase labels",lcas);
Dialog.addCheckbox("Reset label counter",true);
Dialog.addCheckbox("Antialiased",true);
Dialog.addChoice("Position",newArray("Clicked quadrant","Lower left","Lower right","Upper right","Upper left"),pos);
Dialog.show;
str = Dialog.getString;
lcas = Dialog.getCheckbox;
resetCounter = Dialog.getCheckbox;
if (resetCounter==true) n=0;
antialiasedLabels = Dialog.getCheckbox;
pos=Dialog.getChoice();
if (pos=="Lower left") {xoffset=0.05; yoffset=0.05;}
else if (pos=="Lower right") {xoffset=0.90; yoffset=0.05;}
else if (pos=="Upper left") {xoffset=0.05; yoffset=0.85;}
else if (pos=="Upper right") {xoffset=0.90; yoffset=0.85;}
setpref("MM.str",str);
setpref("MM.lcas",lcas);
setpref("MM.antialiased",antialiasedLabels );
setpref("MM.n","0");
setpref("MM.xoffset",xoffset);
setpref("MM.yoffset",yoffset);
setpref("MM.pos",pos);
label=Borders
icon=noicon
arg=
w = getWidth;
h = getHeight;
xn = info("xMontage");
yn = info("yMontage");
iw=w/xn;
ih=h/yn;
x=newArray(3*(xn+yn));
y=newArray(3*(xn+yn));
for (i=0;i<=xn;i++) {
x[3*i]=i*iw;y[3*i]=0;
x[3*i+1]=i*iw;y[3*i+1]=h;
x[3*i+2]=i*iw;y[3*i+2]=0;
}
n=3*xn+3;
for (i=0;i<=yn;i++) {
x[n+3*i]=0;y[n+3*i]=i*ih;
x[n+3*i+1]=w;y[n+3*i+1]=i*ih;
x[n+3*i+2]=0;y[n+3*i+2]=i*ih;
}
makeSelection ("polyline",x,y);
label=Width
icon=noicon
arg=
run("Line Width...");
label=Colors
icon=noicon
arg=
run("Color Picker...");
label=Draw
icon=noicon
arg=
run("Draw");
label=Duplicate
icon=noicon
arg=
t=getString("New title","copy_"+getTitle);
run("Duplicate...", "title="+t);
label=Capture
icon=noicon
arg=
run("Capture Image");
label=Set montage layout
icon=noicon
arg=
Dialog.create("Set Montage Layout");
Dialog.addNumber("Width:", 2);
Dialog.addNumber("Height:", 2);
Dialog.show;
mw = Dialog.getNumber;
mh = Dialog.getNumber;
setMetadata("xMontage="+mw+"\nyMontage="+mh+"\n");
function info(key) {
i = getMetadata;
List.setList(i);
return List.get(key);
}
function addMetadata(s) {
i = getMetadata;
i=i+"\n"+s;
setMetadata (i);
}
function getpref(s,d) { return call("ij.Prefs.get",s,d); }
function setpref(s,v) { return call("ij.Prefs.set",s,v); }
function swap(a,b,c,d) {
setupUndo;
setBatchMode(true);
if (isKeyDown('shift')) {
makeRectangle(a*(w/xn),b*(h/yn),(w/xn),(h/yn));
run("Copy");
makeRectangle(c*(w/xn),d*(h/yn),(w/xn),(h/yn));
setPasteMode("add");
run("Paste");
setPasteMode("copy");
}
else {
makeRectangle(a*(w/xn),b*(h/yn),(w/xn),(h/yn));
run("Duplicate...", "title=tmp");
selectImage(id);
makeRectangle(c*(w/xn),d*(h/yn),(w/xn),(h/yn));
run("Copy");
makeRectangle(a*(w/xn),b*(h/yn),(w/xn),(h/yn));
run("Paste");
selectWindow("tmp");
run("Select All");
run("Copy");
selectImage(id);
makeRectangle(c*(w/xn),d*(h/yn),(w/xn),(h/yn));
run("Paste");
run("Select None");
}
setBatchMode(false);
}
function spring(x0,y0,x1,y1) {
d = sqrt((y1-y0)*(y1-y0)+(x1-x0)*(x1-x0));
step=3;
r=15;
xa = newArray(floor(d/step));
ya = newArray(xa.length);
for (i=0;i1){
xa[0]=x0;
ya[0]=y0;
xa[xa.length-1]=x1;
ya[ya.length-1]=y1;
}
makeSelection("freeline",xa,ya);
}
setpref("MM.n","0");