//Aaron's macros start here. VERY IMPORTANT-- Hitting the "d" or "q" or "w" keys on your keyboard deletes slices in the top stack! //Beware of hitting d or q or w!! //Changelog: var isFiji=indexOf(getInfo("imagej.dir"),"Fiji")>-1; var zchoices =newArray("Max Intensity","Average Intensity", "Min Intensity","Sum Slices","Standard Deviation","Median"); var imarray=newArray(0); var slcarray=newArray(0); var stillrunning=false; var stackreg=false; var fixbr=false; var whichbright=1; var looper=false; var loopdelay=0; var substack=""; var correctZ=false; var titleforset=""; var everychoice="Concatenate"; var colorSwitchSelectCh=true; var measureNext=false; var measureClear=false; var deleteSlice=true; var measureQueue=false; var measureWand=false; var qprefertime=false; var osdiv=File.separator; var stackregstr="StackReg "; if(isFiji) stackregstr="StackReg"; var waitf=0; var hasSliceLabel=doesClassExist("ajs.tools.Slicelabel_Transfer"); macro "AutoRun" { showStatus("Welcome to AJ macros"); startupstuff(); } function doesClassExist(classname){ fl=getFileList(getDirectory("plugins")); gotAJ=false; for(i=0;i-1)return false; else return true; } } function startupstuff(){ if(getInfo("os.name")!="Mac OS X")call("java.lang.System.setProperty","jogamp.gluegen.UseTempJarCache",false); //a=eval("script","System.setProperty(\"jogamp.gluegen.UseTempJarCache\",\"false\")"); //a=eval("script","System.setProperty(\"com.jogamp.newt.Display.enableHighDPI\",\"true\")"); //print(a); if(doesClassExist("ajs.joglcanvas.JCP")){ call("ajs.joglcanvas.JCP.addJCPopups"); //call("ajs.joglcanvas.JCP.startListener"); } //a=eval("script","System.setProperty(\"sun.java2d.noddraw\",\"true\")"); //a=a+" "+eval("script","System.setProperty(\"sun.awt.nopixfmt\",\"true\")"); //a=a+" "+eval("script","System.getProperty(\"jogamp.gluegen.UseTempJarCache\")"); //a=a+" "+eval("script","System.getProperty(\"sun.awt.nopixfmt\")"); //print(a); } macro "Queue AllNone Action Tool - Ce59D23D24D28D32D64Da4Db1DbeDd2De6Df6Df7Df8Df9Ce6aD15D41D70D80Db6Db9DddDe3Cf6aCf7aD90Dc1Df5Cf7aD0fD1fD2fD3fD4fD5fD6fD7fD8fCf8bD49D56D60D9bDb7Db8DceDecDfaCf8bD9fDa0Cf9cD0bD14D1bD2bD39D3bD4bD58D6bD7bD8bDaaCf9cD5bCfacD18D57D59D94DafCfacD50D74CfbdD22Da5Db0Df4DfbCfceD31D84CfceD06D07D13D29D65DbfDd1De2CfffD00D01D02D03D04D05D08D09D0aD10D11D12D19D1aD20D21D2aD30D3aD40D4aD5aD66D67D68D69D6aD75D76D77D78D79D7aD85D86D87D88D89D8aD95D96D97D98D99D9aDa6Da7Da8Da9Dc0DcfDd0DdeDdfDe0De1DedDeeDefDf0Df1Df2Df3DfcDfdDfeDff"{ if(imarray.length==0){ QueueAll(); print("Added all Images"); } else { imarray=newArray(0); slcarray=newArray(0); print("Queue Cleared"); } selectWindow("Log"); selectWindow("ImageJ"); stillrunning=false; } function QueueAll(){ imarray=newArray(nImages); slcarray=newArray(nImages); for(i=0; i(ys+((high-max)/high*h/zm))) ys=y-(high-max)*h/high/zm; if(y<=(ys-max*h/high/zm)) ys=y+max*h/high/zm-1; newmax=floor((y-ys)*zm/h*high)+max; if(newmax!=oldnewmax)setMinAndMax(min,newmax); showStatus("Min:"+min+" Max:"+newmax+" OldMax:"+max); oldnewmax=newmax; wait(30); } } if(modifiers==8) stackbrowser=false; //a=eval("script", "Animator.csfod=0"); Stack.getPosition(ch,sl,frm); showStatus("Ch: "+ch+" Slice: "+sl+" Frame: "+frm); wait(30); } //a=eval("script", "Animator.csfod=0"); //a=eval("script", "IJ.log(\"\"+Animator.csfod)"); setOption("DisablePopupMenu",false); setTool(tool); } function pullArray(array, ind){ if(ind<0 || ind>=array.length) return array; result=newArray(array.length-1); n=0; for(i=0;i1) { pz=Stack.getFrameInterval(); csl=frm; } return pz*csl; } function checkImarray(resetslices){ if(stillrunning) exit(); stillrunning=true; for(i=0;i1) showMessageWithCancel("Will depth code Ch: "+(ch)+", ok?"); if(bitDepth==24) { isRGB=true; Dialog.create("Ch"); Dialog.addChoice("Which channel?",newArray("red","green","blue")); Dialog.show(); dcch=Dialog.getChoice(); if(dcch=="Red") {ch=1;} else if(dcch="Green"){ch=2;} else ch=3; } else isRGB=false; if(chs>1 || isRGB) { run("Split Channels"); if(isRGB) { selectWindow(title+" (red)"); rename("C1-"+title); selectWindow(title+" (green)"); rename("C2-"+title); selectWindow(title+" (blue)"); rename("C3-"+title); } selectWindow("C"+ch+"-"+title); } else rename("C1-"+title); dcIID=getImageID(); //rename("top"); run("Duplicate...", "title=bot duplicate"); getDimensions(w,h,chs2,sls2,frms2); for(i=1;i<=frms2;i++){ for(j=0;j1) Stack.setPosition(1,j+1,i); else setSlice(j+1); run("Multiply...", "value="+(j/sls2*fac)+" slice"); } } selectImage(dcIID); for(i=1;i<=frms2;i++){ for(j=0;j1) Stack.setPosition(1,j+1,i); else setSlice(j+1); run("Multiply...", "value="+(1-(j/sls2*fac))+" slice"); } } for(i=chs;i>=ch;i--){ if(i==ch) {selectWindow("bot"); rename("C"+(ch+1)+"-"+title);} else {selectWindow("C"+(i)+"-"+title); rename("C"+(i+1)+"-"+title);} } run("RGB putter together [l]"); if(chs>1){Stack.setChannel(ch);setMinAndMax(min,max); Stack.setChannel(ch+1); setMinAndMax(min,max);} //rename(title); } var hyperCopyFrom=0; macro "Copy to Sys [c]" { copytwo=false; wintype=getInfo("window.type"); if(wintype=="Image"){ if(copytwo){ tsize=17; fsize=tsize; title=getTitle(); run("Copy to System"); run("System Clipboard"); getDimensions(w,h,ch,sls,frms); n=1;while((n+1)1) hyperCopyFrom=getImageID; } if(copytwo) close(); } } macro "HyperCopy paste [v]"{ toid=getImageID; if(hyperCopyFrom==0) {snapshot; run("Paste"); exit;} if(hyperCopyFrom==toid) {snapshot; run("Paste"); exit;} selectImage(hyperCopyFrom); getDimensions(wf,hf,chsf,slsf,frmsf); Stack.getPosition(chf,slf,frmf); ftitle=getTitle(); selectImage(toid); run("Restore Selection"); getSelectionBounds(x,y,ws,hs); getDimensions(wt,ht,chst,slst,frmst); minchs=minOf(chsf,chst); //minsls=minOf(slst,slsf); minfrms=minOf(frmsf,frmst); if(!(x==0 && y==0 && ws==wt && hs==ht)) waitForUser("Place paste selection location"); Stack.getPosition(cht,slt,frmt); Dialog.create("Hypercopy paste"); pmode= parseInt(call("ij.gui.Roi.getCurrentPasteMode")); if(pmode>0)pmode--; pmodes=newArray("Copy", "Transparent-white", "Add", "Subtract", "Multiply", "Divide", "Blend", "Difference", "AND", "OR", "XOR", "Min", "Max", "Transparent-zero"); Dialog.addChoice("Paste Mode",pmodes,pmodes[pmode]); Dialog.addMessage("Copying from "+ftitle); Dialog.addMessage("which has "+chsf+" chs "+slsf+" slices and "+frmsf+" frames"); Dialog.addString("Copy from chs: ","1-"+chsf); Dialog.addString("Copy from slices: ",""+slf); Dialog.addString("Copy from frames: ",""+frmf); Dialog.addMessage("Pasting to "+getTitle()); Dialog.addMessage("which has "+chst+" chs "+slst+" slices and "+frmst+" frames"); Dialog.addString("Paste to chs: ","1-"+chst); Dialog.addString("Paste to slices: ",""+slt); Dialog.addString("Paste to frames: ",""+frmt); Dialog.show(); setPasteMode(Dialog.getChoice()); chstr=split(Dialog.getString(),"-"); stchf=parseInt(chstr[0])-1; if(chstr.length>1) endchf=parseInt(chstr[1]); else endchf=stchf+1; slstr=Dialog.getString(); slstr=split(slstr,"-"); stslf=parseInt(slstr[0])-1; if(slstr.length>1) endslf=parseInt(slstr[1]); else endslf=stslf+1; frmstr=Dialog.getString(); frmstr=split(frmstr,"-"); stfrf=parseInt(frmstr[0])-1; if(frmstr.length>1)endfrf=parseInt(frmstr[1]); else endfrf=stfrf+1; chstr=split(Dialog.getString(),"-"); stcht=parseInt(chstr[0])-1; if(chstr.length>1) endcht=parseInt(chstr[1]); else endcht=stcht+1; slstr=Dialog.getString(); slstr=split(slstr,"-"); stslt=parseInt(slstr[0])-1; if(slstr.length>1) endslt=parseInt(slstr[1]); else endslt=stslf+1; frmstr=Dialog.getString(); frmstr=split(frmstr,"-"); stfrt=parseInt(frmstr[0])-1; if(frmstr.length>1)endfrt=parseInt(frmstr[1]); else endfrt=stfrf+1; chdiff=stcht-stchf; sldiff=stslf-stslt; frdiff=stfrf-stfrt; onefr=( (endfrf-stfrf)==1 && (endfrt-stfrt)>1 ); onesl=( (endslf-stslf)==1 && (endslt-stslt)>1 ); for(fr=stfrt;fr1) {Stack.setPosition(ch,sl,minOf(fr+1,frms)); if(fr+1>frms)isend=true;} else if(sls>1){ Stack.setPosition(ch,minOf(sl+1,sls),fr); if(sl+1>frms)isend=true;} else if(ch>1){ Stack.setPosition(minOf(ch+1,chs),sl,fr); if(ch+1>frms)isend=true;} }else fwdbackq(1); if(measureClear)run("Select None"); if(measureWand && (IJ.getToolName()=="wand")){ run("Select None"); getCursorLoc(x,y,z,flags); doWand(x,y); //wait(500); getCursorLoc(x,y,z,flags); setKeyDown("shift"); doWand(x,y); } return isend; } macro "-"; macro "Add-Sub Queue [8]" { checkImarray(false); if(stillrunning) exit("Try Again"); stillrunning=true; if(nImages==0) {imarray=newArray(0); slcarray=newArray(0);} else{ curID=getImageID; subtracting=false; for(i=0; i0 &&(slices==1 || qprefertime)){ csl=fr; slices=frames; frint=Stack.getFrameInterval(); minfrint=minOf(minfrint,frint); tryfrms=true; frfix=minOf(frames*frint,frfix); }else{dofrms=false;} if((csl==slices && fb==1) || (csl==1 && fb==-1)){ loop=true; } getVoxelSize(px,py,pz,unit); if(unit=="Pixel" || unit=="pixel" || (tryfrms&&!dofrms)) cancz=false; minpz=minOf(pz,minpz); slcfix=minOf(slices*pz,slcfix); shortslice=minOf(slices,shortslice); } } for(i=0; ifix)slcarray[i]=fix; new=floor(slcarray[i]/ps); if(new<1) new=1; if(new>shortslice)new=shortslice; } }else { slcarray[i]+=minsize*fb; new=floor(slcarray[i]/ps); } if(dofrms && new!=-1){nfr=new;}else {nsl=new;} //print(""+i+": "+nsl+" "+ps); }else{ slcfix=shortslice-1; if(dofrms){ if(!loop) nfr=fr+fb; else {if(looper) {nfr=fr-slcfix*fb; if(qprefertime)nsl=sl+fb;}} }else{ if(!loop) nsl=sl+fb; else {if(looper) {nsl=sl-slcfix*fb;}} } } Stack.setPosition(ch,nsl,nfr); } } //selectWindow("ImageJ"); selectImage(iid); wait(loopdelay); stillrunning=false; } macro "Set substack [s]"{ checkImarray(false); minslboo=true; firstcheck=true; if(imarray.length==0) run("Add-Sub Queue [8]"); for(i=0;i1) csl=fr; if(minslboo) {minsl=csl+1; minslboo=false;} if(csl1 && frms>1) slsfrm=true; if(sls==1 && frms>1) {csl=fr; sls=frms;} if(w>maxwid) maxwid=w; if(h>maxhei) maxhei=h; if(selectionType==-1)okxy=false; getSelectionBounds(xposs[i], yposs[i], widthtemp, heighttemp); xover=w-xposs[i]; yover=h-yposs[i]; xovermin=minOf(xovermin,xover); xovermax=maxOf(xovermax,xover); yovermin=minOf(yovermin,yover); yovermax=maxOf(yovermax,yover); //xovers[i]=w-xposs[i]; yovers[i]=h-yposs[i]; getLine(x1,y1,x2,y2,lwidth); if(x1>-1) {xposs[i]=x1; yposs[i]=y1; angleposs[i]=-atan2(y2-y1, x2-x1)*180/PI;} else {angles=false;} stkpos[i]=csl; if(dLdcheck==-1)dLdcheck=csl; else if(csl!=dLdcheck)dLdiff=true; endtest=sls-stkpos[i]; startest=stkpos[i]-1; frint=Stack.getFrameInterval(); Stack.getUnits(xunit, yunit, zunit, frunit, pxunit); if(begin){ starter=startest; ender=endtest; minchs=chs; maxchs=chs; bfrint=frint; bfrunit=frunit; begin=false; } else { if(frunit!=bfrunit || (frint/bfrint<0.95 || bfrint/frint<0.95)) setfrint=false; bfrint=(bfrint+frint)/2; bfrunit=frunit; } minchs=minOf(minchs,chs); maxchs=maxOf(maxchs,chs); if(startest1) Dialog.addCheckbox("Command Channels?",false); Dialog.addCheckbox("Fix Brightness?", fixbr); Dialog.addCheckbox("StackReg?",stackreg); if(minchs>1) Dialog.addCheckbox("Keep composite?",kac); if(slsfrm) Dialog.addCheckbox("Do all frames?", allfrms); Dialog.addCheckbox("Locations instead of titles?", false); Dialog.addCheckbox("Trim all queued images to least common volume?",false); Dialog.show(); while(stillrunning){ wait(30);} substack=Dialog.getString(); if(!candoLarge) doLarge=false; else doLarge=Dialog.getCheckbox(); if(okxy) { csec=Dialog.getCheckbox(); max512=Dialog.getCheckbox(); //expand=Dialog.getCheckbox(); supercrop=Dialog.getCheckbox(); } //else {csec=false; max512=false; supercrop=false;} // expand=false;} method=Dialog.getChoice(); resl=Dialog.getCheckbox(); if(maxchs>1) cmdch=Dialog.getCheckbox(); else cmdch=false; fixbr=Dialog.getCheckbox(); stackreg=Dialog.getCheckbox(); if(minchs>1) kac=Dialog.getCheckbox(); if(slsfrm) allfrms=Dialog.getCheckbox(); loclabel=Dialog.getCheckbox(); trim=Dialog.getCheckbox(); //trim=false; if(kac && fixbr){showMessage("AJ macros","Sorry, can't fix brightness if it is composite");fixbr=false;} allfrmstext=""; if(slsfrm&&allfrms) allfrmstext=" all"; if(cmdch){ Dialog.create("Command the channels"); Dialog.addMessage("0 means auto"); for(ci=0;ciendsub) {tempsub=startsub; startsub=endsub; endsub=tempsub; substack=""+startsub+"-"+endsub;} startsubfix = startsub; endsubfix=endsub; } dLname="-"; start=true; red=false; green=false; blue=false; for(i=0; i1) sls=frms; if(sls>=endsub){ title=getTitle(); if(start){ if(lengthOf(title)>4) name=substring(title,0,5)+"--"+substack; else name=title+"--"+substack; } if(doLarge){ if(!substackboo){ startsubfix=(stkpos[i] - starter); endsubfix=(stkpos[i] + ender); substackname= ""+startsubfix + "-" + endsubfix; }else { startsubfix=stkpos[i] - starter+startsub-1; endsubfix=startsubfix+endsub-startsub; if(endsubfix>stkpos[i] + ender) endsubfix = stkpos[i] + ender; substackname=""+startsubfix+"-"+endsubfix; } printstr="Stack "+(i+1)+": "+substackname+" "+title; dLname=dLname+"-"+(stkpos[i]-starter); } if(!substackboo && !doLarge) {run("Z Project...","projection=["+method+"]"+allfrmstext); trim=false;} else { if(trim){ getDimensions(w, h, chs, sls, frms); sorf="slice"; if(sls==1 && frms>1) {sls=frms; Stack.setFrame(sls); sorf="frame";} else Stack.setSlice(sls); for(sl=sls;sl>endsubfix;sl--) { setSlice(nSlices); run("Delete Slice", "delete="+sorf); wait(100); } //if(sls==1 && frms>1) Stack.setFrame(1) else Stack.setSlice(1); setSlice(1); for(sl=1;slwfcrop || h>hfcrop){ makeRectangle(xposs[i]-xminc,yposs[i]-yminc,wfcrop,hfcrop); run("Crop"); wait(400); getDimensions(nw, nh, nchs, nsls, nfrms); if(nchs!=schs) { showStatus("Running crop fixer----"); run("Stack to Hyperstack...", "order=xyczt(default) channels="+schs+" slices="+sls+" frames="+sfrms+" display=Composite"); wait(100); IID=getImageID(); imarray[i]=IID; setLocation(txl,tyl); } } run("Z Project...","projection=["+method+"]"+allfrmstext); }else run("Z Project...","start="+startsubfix+" stop="+endsubfix+" projection=["+method+"]"+allfrmstext); } wait(100); ztitle=getTitle(); zID=getImageID; if(chs>1){ wait(100); if(cmdch){ for(ci=0;ci0) torb="Top-"; if(xc>0) rorl="Left"; } run("Canvas Size...", "width="+widc+" height="+heic+" position="+torb+rorl+" zero"); wait(200+200*waitf); anglebit=""; if(angles) { if(i>0){a2=angleposs[i]; a1=angleposs[0]; rotangle=a2-a1; if((a2*a1)<0 && abs(a1)>90 && abs(a2)>90) {rotangle=(180-abs(a1))*(a1/abs(a1))-(180-abs(a2))*(a2/abs(a2));} run("Rotate... ", "angle="+rotangle+" grid=0 interpolation=Bilinear"); anglebit=" ang: "+d2s(rotangle,1); } } lastbit=""+d2s(xposs[i],1)+","+d2s(yposs[i],1)+anglebit+" "+title; if(doLarge) printstr="Stack "+(i+1)+": "+substackname+" xy: "+lastbit; else printstr="Stack "+(i+1)+": "+lastbit; } if(doLarge || (docsec)||trim) print(printstr); olddata=""; if(start) { endim = getImageID(); rename("AJZPROJECTTEMP"); setLocation(50,400); firstmdata=mdata; firstendsls=zsls; getVoxelSize(pw, ph, pd, unit); }else{ selectWindow("AJZPROJECTTEMP"); getDimensions(widt,heit,endchs,endsls,endfrms); olddata=getMetadata("Info"); finfrms=endfrms+zfrms; run("Concatenate...", " title=[AJZPROJECTTEMP] image1=[AJZPROJECTTEMP] image2=["+ztitle+"] image3=[-- None --]"); //print("order=xyczt(default) channels="+endchs+" slices=1 frames="+finfrms+" display=Composite"); if(chs>1 && kac) run("Stack to Hyperstack...", "order=xyczt(default) channels="+endchs+" slices=1 frames="+finfrms+" display=Composite"); getDimensions(endw,endh,endchs,endsls,endfrms); Stack.setPosition(1,endsls,endfrms); endim = getImageID(); } if(!start && firstendsls==1){Stack.setSlice(1); setMetadata("Label",firstmdata);Stack.setSlice(2);} if(zsls==1&&zfrms==1)setMetadata("Label",mdata); if(doLarge || (docsec)||trim) {if(olddata!="")olddata=olddata+"\n"; setMetadata("Info",olddata+printstr);} if(fixbr){ //Leaving this here, but it doesn't work on composites (yet..) //because you can't multiply on one slice in a composite (yet..) if(!kac)minchsfb=1; else minchsfb=minchs; if(start)firstmean=newArray(minchsfb); for(ci=0;ci1) Stack.setChannel(ci+1); getStatistics(area,mean); if(sl>1){ run("Multiply...", "slice value="+(firstmean[ci]/mean)); } else firstmean[ci] = mean; } } resetMinAndMax(); if(resl){ // ****Currently only RGB versions of reslices**** selectImage(IID); if(angles) run("Select None"); run("Reslice [/]...", "input=1.000 output=1.000 start=Top"); tempIDrsl=getImageID(); if(angles) { selectImage(IID); run("Restore Selection"); selectImage(tempIDrsl);} run("Z Project...", "projection=[Max Intensity]"); zrslid=getImageID(); if(chs>1){ tempID=getImageID(); wait(100); run("Stack to RGB"); zrslid=getImageID(); selectImage(tempID); close();} selectImage(tempIDrsl); close(); selectImage(zrslid); if(start){ setLocation(20, 840); rename(name+"-reslices"); endimrsl=getImageID(); } else{ copyTo(endimrsl); } } if(start) start=false; } }//if isopen } selectImage(endim); rename(name); if(setfrint){Stack.setFrameInterval(frint); Stack.setTUnit(frunit);} if(doLarge){ if(dLdiff)rename(name+dLname); selectWindow("Log");} if(expand){ if(angles){ makeRectangle(xfc,yfc,wfc,hfc); run("Crop"); } makeRectangle(xfcrop,yfcrop,wfcrop,hfcrop); if(supercrop){wait(100+200*waitf); run("Crop");} } setVoxelSize(pw, ph, pd, unit); if(stackreg) run(stackregstr, "transformation=[Rigid Body]"); resetMinAndMax(); selectImage(endim); setSlice(1); selectWindow("ImageJ"); } function copyTo(IID){ run("Select All"); run("Copy"); close(); selectImage(IID); setSlice(nSlices); run("Add Slice"); run("Paste"); } macro "Run on Everything Queued [e]"{ checkImarray(false); while(stillrunning){ wait(30);} if(imarray.length==0){ QueueAll(); while(stillrunning) wait(30); } everyrun=newArray("close without saving","Resize","Concatenate","Despeckle","StackReg","8-bit", "Measure", "setMinAndMax","Make Composite","Front Delete", "Back Delete", "Tile Fwd", "Tile Backwards", "Save to", "Depth Code", "3dify", "Run Code"); Dialog.create("Which"); Dialog.addChoice("What would you like to do?",everyrun, everychoice); Dialog.addString("or Run Macro Code-",""); Dialog.show(); everychoice=Dialog.getChoice; cond=Dialog.getString; if(cond!="") everychoice="Run Code"; start=true; getDimensions(w,h,chs,sls,frms); //pre-run set up if(everychoice=="3dify") fac=getNumber("Eye separation in degrees:",10); if(everychoice=="Resize")rz=getNumber("New w and h resolution?:",w); if(everychoice== "Save to") saveloc=getDirectory("Where?"); if(everychoice=="Tile Backwards"){ for(i=imarray.length;i>0;i--){ if(isOpen(imarray[i-1])){ selectImage(imarray[i-1]); wait(100); } } selectWindow("ImageJ"); return; } //end pre-run set up //running on every image for(i=0;iendsl;csl--) {setSlice(nSlices); run("Delete Slice", "delete=slice"); wait(100);} for(csl=1;csl0 && chkfrms>0 && frms>1) {run("Stack to Hyperstack...", "order=xyczt(default) channels="+chs+" slices="+(newsls*frms)+" frames=1 display=Composite"); chkfrms=2;} //2 means we did get a multiframe stack after one-frame start stack print(getTitle()+"x:"+x[i]+" y:"+y[i]+" sla:"+sla[i]+" sladd:"+sladd[i]+" newsls:"+newsls); } } constr=constr+" image"+(i+1)+"=[-- None --]"; run("Concatenate...", constr); if(chkfrms==2) run("Stack to Hyperstack...", "order=xyczt(default) channels="+chs+" slices="+newsls+" frames="+totfrms+" display=Composite"); setMetadata("Info", infos); } selectWindow("ImageJ"); //post run } function threeDify(title,fac){ selectWindow(title); getDimensions(w,h,chs,sls,frms); if(chs>1)exit("Requires single channel stack"); if(bitDepth>8) run("8-bit"); run("3D Project...", "projection=[Brightest Point] axis=Y-Axis slice=1 initial="+(360-fac)+" total=0 rotation=5 lower=1 upper=255 opacity=0 surface=0 interior=0"); rename("lft"); selectWindow(title); run("3D Project...", "projection=[Brightest Point] axis=Y-Axis slice=1 initial="+(fac)+" total=0 rotation=5 lower=1 upper=255 opacity=0 surface=0 interior=0"); rename("rt"); run("Merge Channels...", "red=lft green=rt blue=rt gray=*None*"); rename(title+" 3d"); } macro "Next image in Queue [n]" { checkImarray(false); if(stillrunning) exit(); imind=-1; for(i=0;i=imarray.length-1) imind=0; else imind++; if(imarray.length>0) selectImage(imarray[imind]); } macro "-"; var abchopts="Do only one channel"; var aballsls=false; macro "Fix Brightness [b]"{ getMinAndMax(min,max); iid=getImageID(); title=getTitle(); getDimensions(w,h,chs,sls,frms); brightchoice=newArray("Gradual Brightness", "Auto Gradual Brightness", "Set all Composites like this"); Dialog.create("Brightness"); Dialog.addChoice("Brightness?",brightchoice, brightchoice[whichbright]); Dialog.show(); wbs=Dialog.getChoice(); whichbright=indexOfArray(brightchoice,wbs); dosls=(frms==1 && sls>1); Stack.getPosition(ch,sl,frm); if(wbs=="Gradual Brightness"){ resetMinAndMax; setSlice(1); resetMinAndMax; getMinAndMax(mino,maxo); for(i=0;i1) run("Duplicate...", "title=temp"); run("Multiply...", "slice value="+maxo/round(maxo-((i/sls)*(maxo-max)))); if(chs>1) {run("Select All"); run("Copy"); close(); selectImage(iid); run("Paste");} } setSlice(sls); resetMinAndMax; } else if(wbs=="Auto Gradual Brightness") { aballzproj=false;abeachsls=false; stc=ch-1;endc=ch; stcn=stc; endcn=endc; //n's for normalizing stsl=sl-1;endsl=sl; if(dosls){stsl=frm-1;endsl=frm;} useResults=false; if(chs>1 || (sls>1 && frms>1)){ Dialog.create("Auto Brightness"); Dialog.addMessage("Ch: "+(ch)+" Sl: "+sl+" Fr: "+frm+" on stack: "+title); if(chs>1)Dialog.addChoice("Multiple ch options:",newArray("Do only one channel","Do all channels separately","Normalize to this channel"),abchopts); if(nResults==frms || (dosls && nResults==sls))Dialog.addCheckbox("Use Means from Results?",false); if(sls>1 && frms>1) { Dialog.addChoice("Adjust brightness over slices or frames?",newArray("Frames","Slices"),"Frames"); Dialog.addChoice("Do whole stack?",newArray("Only current fr/sl","Repeat individually for all frs/sls","Change all based on Z-proj"),"Only current fr/sl"); zchoice=call("ij.Prefs.get","zproject.method",0); if(zchoice<2) zchoice=!zchoice; Dialog.addChoice("If z-proj, how?",zchoices,zchoice); } Dialog.show(); if(chs>1) { abchopts=Dialog.getChoice(); if(abchopts=="Do all channels separately"){stc=0; endc=chs;} if(abchopts=="Normalize to this channel"){stcn=0; endcn=chs;} } if(nResults==frms || (dosls && nResults==sls))useResults=Dialog.getCheckbox(); if(sls>1 && frms>1) { dosls=(Dialog.getChoice()=="Slices"); aballslschoice=Dialog.getChoice(); zchoice=Dialog.getChoice(); abeachsls=(aballslschoice=="Repeat individually for all frs/sls"); aballzproj=(aballslschoice=="Change all based on Z-proj"); if(dosls){stsl=frm-1; endsl=frm;} if(abeachsls){stsl=0;if(dosls){endsl=frms;}else{endsl=sls;}} } } if(dosls) endfrms=sls; else endfrms=frms; means=newArray(endfrms); maxmean=0; alldim=1;if(aballzproj){if(dosls){alldim=frms;}else{alldim=sls;}} if(useResults){ for(i=0;i-1) {selec=true; run("Select None");} else selec=false; if(!dosls && aballzproj && !useResults){ run("Z Project...", "projection=["+zchoice+"] all"); if(chs>0)Stack.setChannel(stc+1); if(selec) run("Restore Selection"); for(j=0;j=digits) result = num; else result= substring(toString(num+digits),1,digs+1); return result; } macro "FrontDeleter [q]"{ call("ajs.tools.StackTrimmer.trimStackFront"); } function oldFrontDeleter(){ Stack.getPosition(channel, sl, frame); getDimensions(w,h,chs,sls,frms); title=getTitle(); framer=false; if(frms>1) { framer=true; if(sls>1) { if(!getBoolean("Delete frames before current frame? (No means delete slices!)")) framer=false; } } if(framer){ Stack.setFrame(1); x=frame; frmorsl="frame"; }else { Stack.setSlice(1); x=sl; frmorsl="slice"; } for(i=1;i1){ framer=true; if(sls>1) { if(!getBoolean("Delete all time points after current? (No means delete slices!)")) framer=false; } } if(framer){ top=frms; x=frm; frmorsl="frame"; }else { top=sls; x=sl; frmorsl="slice"; } while(top>x) { if(getTitle!=title) {wait(100); selectWindow(title);} if(framer) Stack.setFrame(frms); else Stack.setSlice(sls); run("Delete Slice", "delete="+frmorsl); if(sls>1 && frms>1) wait(1000); else wait(100); getDimensions(w, h, chs, sls, frms); if(framer) top=frms; else top=sls; Stack.setPosition(1,sls,frms); } updateDisplay(); } var astitle=""; var astime=getTime(); var astype=""; macro "Addslice [a]" { title=getTitle(); getDimensions(w,h,chs,sls,frms); Stack.getPosition(ch,sl,frm); if(chs*sls*frms>maxOf(chs,maxOf(sls,frms))){ if(title!=astitle || ((getTime()-astime)>20000)){ astitle=title; Dialog.create("add Slice"); Dialog.addChoice("Add",newArray("channel","slice","frame"),"frame"); Dialog.addCheckbox("Prepend",false); Dialog.show(); astype=Dialog.getChoice(); if(Dialog.getCheckbox())astype+=" prepend"; } astime=getTime(); run("Add Slice", "add="+astype); }else{run("Add Slice");} Stack.setPosition(ch,sl,frm); } macro "Deleteslice [d]"{ if(deleteSlice){ title=getTitle(); getDimensions(w,h,chs,sls,frms); Stack.getPosition(ch,sl,frm); if(chs*sls*frms>maxOf(chs,maxOf(sls,frms))){ if(title!=astitle || ((getTime()-astime)>20000)){ astitle=title; Dialog.create("del Slice"); Dialog.addChoice("Delete",newArray("channel","slice","frame"),"frame"); Dialog.show(); astype=Dialog.getChoice(); } astime=getTime(); astlocal=astype; if(endsWith(astype,"prepend"))astlocal=substring(astype,0,indexOf(astype," prepend")); run("Delete Slice", "delete="+astype); }else{run("Delete Slice");} Stack.setPosition(ch,sl,frm); updateDisplay(); }else{ run("Draw","slice"); if(measureNext) run("Next Slice [>]"); } } macro "Z-Project shortcut [z]"{ IID=getImageID; zchoice=call("ij.Prefs.get","zproject.method",0); if(zchoice<2) zchoice=!zchoice; getDimensions(w,h,chs,sls,frms); if(frms>1 && sls==1) {sls=frms; frms=1;} if(chs>1 && frms==1 && sls==1) {sls=chs;} ab=getMetadata("Info"); title=getTitle; frmdo=""; Dialog.create("Z Projectin\'"); Dialog.addNumber("Start slice:",1,0,3,""); Dialog.addNumber("Stop slice:",sls,0,3,""); Dialog.addChoice("Projection Type",zchoices, zchoices[zchoice]); if(frms>1) Dialog.addCheckbox("All Time Frames?",true); Dialog.show(); startsl=Dialog.getNumber; endsl=Dialog.getNumber; projchoice=Dialog.getChoice; if(frms>1) if(Dialog.getCheckbox) frmdo=" all"; run("Z Project...", "start="+startsl+" stop="+endsl+" projection=["+projchoice+"]"+frmdo); zinfoline="Z-proj: "+startsl+"-"+endsl+"/"+sls; ztitle=getTitle(); a=split(ab,"\n"); mdata=""; if(a.length>0 && a.length<5) mdata=a[0]; else if(a.length>5) { if(true){ //getBoolean("Lif Location?") iol=indexOf(title,".lif - "); if(iol>-1){ thistitle=substring(title,iol+7,lengthOf(title)); if(endsWith(thistitle,".tif")) thistitle=substring(thistitle,0,indexOf(thistitle,".tif")); } else thistitle=""; x="???"; y="???"; z="???"; zm="?"; for(i=0;i-1 || ioy>-1 || ioz>-1 || iozm>-1) { string=a[i]; lioq=lengthOf(string); ioe=lastIndexOf(string," = "); if(iozm>-1){dec=0; fac=1.0;} else{ fac=-1000000.00; dec=2;} value=toString(parseFloat(substring(string, ioe+3, lioq))*fac,dec); if(iox>-1) y=value; else if(ioy>-1) x=value; //switch x and y because leica is screwy else if(ioz>-1) z=value; else zm=value; } } } if(x!="???") mdata="Loc: x:"+x+" y:"+y+" z:"+z+" Zoom:"+zm+"\n"+ab; } else {mdata=ab;} } setMetadata("Info",zinfoline+"\n"+mdata); if(hasSliceLabel){ selectImage(IID); if(isKeyDown("shift")){setKeyDown("none");} run("Slicelabel Transfer", "images=["+ztitle+"] additional=[] begin=1"); selectImage(ztitle); } } macro "RGB putter together [l]"{ //requires function getTextLUT() compbit=""; title=getTitle(); IID=getImageID(); ext=".tif"; if(endsWith(title,ext)) title=substring(title,0,lengthOf(title)-4); else ext=""; bits=bitDepth(); getDimensions(ht,wd,chs,sls,fms); if(chs>1) { Stack.getDisplayMode(mode); if(mode!="Composite") { Stack.setDisplayMode("Composite"); for(i=0;i1){ setSlice(nSlices); mdata=getMetadata("Label"); if(mdata!=""){ setSlice(nSlices); mdata=getMetadata("Label"); IID=getImageID(); mdata=split(mdata,"\n"); mdata=mdata[0]; if(startsWith(mdata,"s_")) oifdo=true; else oifdo=false; if(!oifdo){ cycind=lastIndexOf(mdata,"_Cycle")+6; chind=indexOf(mdata,"_Ch")+3; slind=chind+2; currset=indexOf(mdata,"_Current"); if(currset==-1) currset=chind-3; cycl=currset-cycind; sll=6; if(chind<3) exit("Not a prairie or oif stack"); } else { cycind=indexOf(mdata,"T")+1; cycl=3; slind=indexOf(mdata,"Z")+1; sll=3; chind=indexOf(mdata,"C")+3; } if(cycind>6 && lengthOf(mdata)>(cycind+cycl)) cycs=parseInt(substring(mdata,cycind,cycind+cycl)); else cycs=1; if(cycs==0) cycs=1; if(lengthOf(mdata)>(slind+sll)) sls=parseInt(substring(mdata,slind,slind+sll)); else sls=1; chs=parseInt(substring(mdata,chind,chind+1)); if(nSlices!=cycs*chs*sls) { if(nSlices==cycs*sls*(chs-1)) chs--; else{ newones=getString("What's the chs sls frms?",""+chs+" "+sls+" "+cycs); newones=split(newones," "); chs=newones[0]; sls=newones[1]; cycs=newones[2];} } if(nSlices!=cycs*chs*sls) exit("Chs, sls, and frames do not match"); if(!oifdo)run("Stack to Hyperstack...", "order=xyzct channels="+chs+" slices="+sls+" frames="+cycs+" display=Composite"); else { run("Stack to Hyperstack...", "order=xytzc channels="+chs+" slices="+sls+" frames="+cycs+" display=Composite"); if(chs==3) {Stack.setChannel(1);run("Blue"); Stack.setChannel(3); run("Red");} } rename(title+ext); } } else showMessage("I don't know what you wanted to happen."); } function getTextLUT(imageID,ch){ selectImage(imageID); getDimensions(w,h,chs,sls,frms); if(ch>chs) exit("ch too high"); if(bitDepth ==24) exit("RGB image"); if(Stack.isHyperstack)Stack.setChannel(ch); getLut(reds,greens,blues); max=maxOf(reds[128],maxOf(greens[128],blues[128])); red=(max==reds[128]); green=(max==greens[128]); blue=(max==blues[128]); if(red) { result="Red"; if(green) result="Yellow"; if(blue) { result="Magenta"; if(green) result="Grays"; } } else if(green) { result="Green"; if(blue) result="Cyan"; } else if(blue) result="Blue"; return ""+result; } //print(getTextLUT(getImageID,2)); macro "RGB Lut cycle [g]"{ if(stillrunning) exit(); if(bitDepth==24) exit(); stillrunning=true; rgbCycle(1); stillrunning=false; } macro "RGB Lut cycle back [r]"{ if(stillrunning) exit(); if(bitDepth==24) exit(); stillrunning=true; rgbCycle(-1); stillrunning=false; } function rgbCycle(rgbcyc){ lutchoice=newArray("Red","Green","Blue","Grays","Cyan","Magenta","Yellow"); Stack.getPosition(ch,sl,frm); curlut=getTextLUT(getImageID,ch); n=indexOfArray(lutchoice,curlut); n+=rgbcyc; if(n>6) n=0; if(n<0) n=6; run(lutchoice[n]); } macro "-"{} var chSwitchArray=newArray("100000","010000","001000","000100","000010","000001","1111111111"); var chSwitchLength=6; macro "Ch1Switch [1]"{ if(stillrunning) exit(); switcher(chSwitchArray[0]); } macro "Ch2Switch [2]"{ if(stillrunning) exit(); switcher(chSwitchArray[1]); } macro "Ch3Switch [3]"{ if(stillrunning) exit(); switcher(chSwitchArray[2]); } macro "Ch4Switch [4]"{ if(stillrunning) exit(); switcher(chSwitchArray[3]); } macro "Ch5Switch [5]"{ if(stillrunning) exit(); switcher(chSwitchArray[4]); } macro "Ch6Switch [6]"{ if(stillrunning) exit(); switcher(chSwitchArray[5]); } macro "Ch-Switch [7]"{ if(stillrunning) exit(); switcher(chSwitchArray[6]); } function switcher(colorStr){ stillrunning=true; if(Stack.isHyperStack || is("Composite")){ title=getTitle; getDimensions(w,h,chs,sls,frms); chSwitchLength=maxOf(chSwitchLength,chs); Stack.getPosition(ch,sl,frm); Stack.getActiveChannels(string); chSwitchLength=minOf(chSwitchLength,lengthOf(string)); chswitchs=newArray(chSwitchLength); ch2change=newArray(chSwitchLength); for(i=0;i-1){if(colorSwitchSelectCh && chswitchs[color] && !((color+1)==ch)) { Stack.setChannel(color+1); if(isOpen("B&C")){selectWindow(title); selectWindow("B&C"); selectWindow(title);} }} } else showStatus("Color Switch reqiures Composite"); stillrunning=false; } macro "-"{} macro "Quick Import [i]" { run("TwoPhoton Import"); } macro "Extract XY locations [j]"{ run("Get 2p Info"); }