var AJver="--AJ macros 09-14-16--"; //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!! //My global variable below. Most of these are for default choice, etc. Many are covered in AJprefs.txt in the imageJ folder //Changelog: //--AJ macros 07-16-13-- //bugs // //--AJ macros 07-11-13-- //Added OIF Olympus 2-photon compatibility //Added a delay variable on the [9] and [0] looping // which is set under AJprefs //Various bug fixes // -fixed up the update feature a bit // //--AJ macros 12-05-12-- // did a bunch of stuff var isFiji=true; var chchoicearray= newArray("1","2","RGB","GBR","BRG", "Both-sep","1chOnly"); var chchoicedefault=chchoicearray[3]; 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 propxy=0.6; var propz=1.0; var substack=""; var correctZ=false; var defdozee=false; var autoplace=false; var prefname=getDirectory("startup")+"AJprefs.txt"; var prefsloaded=false; var halfsize=false; var titleforset=""; var everychoice="close without saving"; var pgreens=newArray(-15728896,-13172992,-11600128,-16711913,-10813696,-10551552,-8257792); var preds=newArray(-65536,-57088); var colorSwitchSelectCh=true; var measureNext=false; var measureClear=false; var deleteSlice=true; var measureQueue=false; var measureWand=false; var qprefertime=false; var addSlice=true; var os=getInfo("os.name"); var osdiv="\\"; //windows var stackregstr="StackReg "; var waitf=0; var WINXADD=26; var WINYADD=58; var WINYPERDIM=22; var hasSliceLabel=(File.exists(getDirectory("plugins")+"AJ"+File.separator+"Slicelabel_transfer.jar") ||File.exists(getDirectory("plugins")+"AJ"+File.separator+"Slicelabel_transfer.java")); macro "AutoRun" { showStatus("Welcome to AJ macros loading Prefs"); startupstuff(); loadPrefs(); showStatus("AJ macros load complete"); } function startupstuff(){ if(startsWith(os,"Mac")||startsWith(os,"Linux")) osdiv="/"; isFiji=indexOf(getInfo("imagej.dir"),"Fiji")>-1; if(isFiji) stackregstr="StackReg"; a=eval("script","System.setProperty(\"jogamp.gluegen.UseTempJarCache\",\"false\")"); } function loadPrefs(){ //repeat in case StartupMacros is reloaded without AutoRun startupstuff(); if(File.exists(prefname)) { prefs=File.openAsString(prefname); prefs=split(prefs,"\n"); if(prefs[0]!=AJver) {printprefs(); exit();} looper=evalPrefs(prefs,"looper"); whichbright=evalPrefs(prefs,"whichbright"); propxy=parseFloat(evalPrefs(prefs,"propxy")); propz=parseFloat(evalPrefs(prefs,"propz")); //end of short chchoicedefault=toString(evalPrefs(prefs,"chchoicedefault")); stackreg=evalPrefs(prefs,"stackreg"); fixbr=evalPrefs(prefs,"fixbr"); colorSwitchSelectCh=evalPrefs(prefs,"colorSwitchSelectCh"); measureNext=evalPrefs(prefs,"measureNext"); prefsloaded=true; } } //prefs should be an array of the preferences file split by \n function evalPrefs(prefs, key){ for(i=0;i-1){ tkey=substring(prefstring,0,ioe); if(key==tkey){ a=substring(prefstring,(ioe+1),lengthOf(prefstring)); if(key=="pgreens" || key=="preds") { endtemp=split(a,","); end=newArray(lengthOf(endtemp)); for(i=0;i-1) end=parseFloat(a); else if(!isNaN(parseInt(a))) end=parseInt(a); else end=a; return end; } } } } function printprefs(){ f=File.open(prefname); print(f, AJver); print(f, "looper="+looper); print(f, "whichbright="+whichbright); print(f, "propxy="+propxy); print(f, "propz="+propz); print(f, "chchoicedefault="+chchoicedefault); print(f, "stackreg="+stackreg); print(f, "fixbr="+fixbr); print(f, "colorSwitchSelectCh="+colorSwitchSelectCh); print(f, "measureNext="+measureNext); File.close(f); } 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); 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); stsl=slt-1;endsl=slt; stfr=frmt-1;endfr=frmt; if(minsls>1 || minfrms>1) { Dialog.create("Hypercopy paste"); Dialog.addCheckbox("Copy slice by slice or frame by frame?",false); Dialog.addMessage("Not checking just pastes on the current slice and frame."); if(minsls>1) Dialog.addString("Copy over slices: ","1-"+minsls); if(minfrms>1) Dialog.addString("Copy over frames: ","1-"+minfrms); Dialog.show(); dosls=Dialog.getCheckbox(); if(minsls>1) { slstr=Dialog.getString(); slstr=split(slstr,"-"); if(dosls){stsl=parseInt(slstr[0])-1; endsl=parseInt(slstr[1]);} } if(minfrms>1) { frmstr=Dialog.getString(); frmstr=split(frmstr,"-"); if(dosls){stfr=parseInt(frmstr[0])-1; endfr=parseInt(frmstr[1]);} } }else dosls=false; for(fr=stfr;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"); } 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"); } 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(); whichbright=indexOfArray(brightchoice,Dialog.getChoice()); if(frms==1 && sls>1) {dosls=true;} else dosls=false; Stack.getPosition(ch,sl,frm); if(whichbright==0){ 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(whichbright==1) { 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;} 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(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(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(selectionType()>-1) {selec=true; run("Select None");} else selec=false; if(dosls) endfrms=sls; else endfrms=frms; alldim=1;if(aballzproj){if(dosls){alldim=frms;}else{alldim=sls;}} means=newArray(endfrms); maxmean=0; if(!dosls && aballzproj){ run("Z Project...", "projection=["+zchoice+"] all"); if(chs>0)Stack.setChannel(stc+1); if(selec) run("Restore Selection"); for(j=0;j1) { 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]"{ if(!prefsloaded) loadPrefs(); 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",ztitle); selectImage(ztitle); } } macro "RGB putter together [l]"{ //requires function getTextLUT() if(!prefsloaded) loadPrefs(); 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,1)); 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 showMessage("Color Switch reqiures Composite"); stillrunning=false; } macro "-"{} //oif functions function getData(str){ if(indexOf(str,"=")==-1) return ""; a=split(str,"="); data=a[1]; if(data=="")data="\"NA\""; isquote=(indexOf(data,"\'")>-1 || indexOf(data,"\"")>-1); if(isquote) return substring(data,1,lengthOf(data)-1); else return parseFloat(data); } function findData(xmlfile,findtext,starti,limit){ if(limit==0 || limit>(xmlfile.length))limit=(xmlfile.length); for(i=starti;i -1) {return i;} //print(""+i);} } return limit; } function convtxt(strc){ strn=""; for(in=0; in=32 && c<=127) String.append(fromCharCode(c)); } s2 = String.buffer; return s2; } //print(openoif("")); var zoom="NA";var xysize=0; //returns a string array for each location with the following info, separated by double spaces: //xystring=""+xlocation+ " "+ylocation + " "+ zlocation+ " "+ zstep+ " "+ intervaltime+ " "+ timepoints; //report: // 0-no report // 1-report // 2-populate slice times // 3-populate without asking function ExLoc(xmlfilepath, report, printxyfile, printmap){ timestring=""; ioc=indexOf(report,","); if(ioc>-1) {timestring=substring(report,ioc+1,lengthOf(report); report=parseInt(substring(report,0,ioc));} if(endsWith(xmlfilepath,".oif")) oifdo=true; else oifdo=false; fast=true; if(report==2 || report==3){ if(!hasSliceLabel) {print("ExLoc ptytimes requires Slicelabel_transfer");return newArray(0);}; fast=false; } noask=(report==3); report=(report==1); xylist=newArray(0); xysize=0; n=1; times=newArray(0); alltimes=newArray(0); starttime="I dunno"; startdate=""; version="NA"; lwv="NA"; zm="NA"; lpower="NA"; lpowerend="NA"; gains=newArray(4); gainends=newArray(4); Array.fill(gains,-1); Array.fill(gainends,-1); objective="NA"; pixels=0; averaging=0; averagingtype="None"; if(oifdo){ chs=0; //for olympus oifs xmlfile=split(openoif(xmlfilepath), "\n"); loxf=xmlfile.length; locs=1; //oifs don't have multiple locations as far as I know. i=findData(xmlfile,"ImageCap",0,50); //typo of ImageCaptureDate is currently ImageCaputreDate if(i>50) {if(report) showMessage("Could not get data from oif file"); return xylist;} starttime=getData(xmlfile[i]); version=getData(xmlfile[loxf-1]); //Averaging, called IntegrationCount and IntegrationType, are 2 and 3 after Capture Date averaging=getData(xmlfile[i+2]); averagingtype=getData(xmlfile[i+3]); //Laser Wavelength also we get it later with Laser 0 parameters i=findData(xmlfile,"LaserWavelength",i,0); lwv=""+getData(xmlfile[i]); //Zoom i=findData(xmlfile,"ZoomValue",i,0); zm=getData(xmlfile[i]); zoom=""+zm; //Xsize //oif does not contain xy stage data but rather image xy dimension size data i=findData(xmlfile,"AxisCode=\"X",i,0); i=findData(xmlfile,"EndPosition",i,0); xtotalsize=getData(xmlfile[i]); //Ysize //oif does not contain xy stage data but rather image xy dimension size data i=findData(xmlfile,"AxisCode=\"Y",i,0); i=findData(xmlfile,"EndPosition",i,0); ytotalsize=getData(xmlfile[i]); //Chs //number of chs i=findData(xmlfile,"AxisCode=\"C",i,0); i=findData(xmlfile,"EndPosition",i,0); chs=getData(xmlfile[i]); //ZSize //it is the actual Z position (in nm) i=findData(xmlfile,"AxisCode=\"Z",i,0); i=findData(xmlfile,"EndPosition",i,0); zpartend=getData(xmlfile[i])/1000; //oifs give z in nm not um //Z Step Interval i=findData(xmlfile,"Interval",i,0); zstep=getData(xmlfile[i])/1000; //oifs give z in nm not um //Number of Slices i=findData(xmlfile,"MaxSize",i,0); steps=maxOf(getData(xmlfile[i]),1); //Z position i=findData(xmlfile,"StartPosition",i,0); zpart=getData(xmlfile[i])/1000; //oifs give z in nm not um //Time in total i=findData(xmlfile,"AxisCode=\"T",i,0); i=findData(xmlfile,"EndPosition",i,0); totaltime=getData(xmlfile[i])/1000; //oifs give t in ms //Timepoints number i=findData(xmlfile,"GUI MaxSize",i,0); i=findData(xmlfile,"MaxSize",i+1,0); //+1 because we want the second MaxSize not GUI MaxSize tps=maxOf(getData(xmlfile[i]),1); //Time interval i=findData(xmlfile,"Interval",i-2,0); xmlintervaltime=getData(xmlfile[i])/1000; if(xmlintervaltime==0 || xmlintervaltime==NaN){xmlintervaltime=totaltime/tps;} //i=findData(xmlfile,"StartPosition",i+1,0); //startsecs=getData(xmlfile[i])/1000; //oifs give t in ms //probably startsecs=0 zstepgo=true;pchange=false; starti=i; limit=findData(xmlfile,"Corr Bright",i,0); i=findData(xmlfile,"[Channel 1",starti,limit); if(i<=limit){ i=findData(xmlfile,"AnalogPMTVoltage",i,limit); if(i1) {endptyname=endptyname+"C"+pad(chs,3); startptyname=startptyname+"C001";} if(steps>1){endptyname=endptyname+"Z"+pad(steps,3);startptyname=startptyname+"Z001";} if(tps>1){endptyname=endptyname+"T"+pad(tps,3);startptyname=startptyname+"T001";} endptyname=endptyname+".pty";startptyname=startptyname+".pty"; if(File.exists(startptyname))ptyfilepaths=Array.concat(ptyfilepaths,startptyname); else print("Can't find "+startptyname); if(File.exists(endptyname))ptyfilepaths=Array.concat(ptyfilepaths,endptyname); else print("Can't find "+endptyname); }else{ fl=getFileList(oifdir); //stptytime=getTime(); for(i=0;i-1);hasZ=(ioz>-1);hasC=(ioc>-1);} if(hasT){if(parseInt(substring(fl[i],iot+1,iot+4))>tps)keep=false;} if(hasZ){if(parseInt(substring(fl[i],ioz+1,ioz+4))>steps)keep=false;} if(keep)ptyfilepaths=Array.concat(ptyfilepaths,oifdir+fl[i]); } } //print("PTYTIME took: "+(getTime()-stptytime)); //for(i=0;i-1); ioz=indexOf(ptyname,"Z"); hasZ=(ioz>-1); ioc=indexOf(ptyname,"C"); hasC=(ioc>-1); if(hasT) { tps=0; for(i=0;i0){ //start pty file ptyname=File.getName(ptyfilepaths[0]); iot=indexOf(ptyname,"T"); hasT=(iot>-1); ptyfile=split(openoif(ptyfilepaths[0]),"\n"); i=0; if(ptyfile.length>0){ i=findData(ptyfile,"ObjectiveLens Name",0,0); if(i1){ //end pty file ptyfile=split(openoif(ptyfilepaths[ptyfilepaths.length-1]),"\n"); i=0; if(ptyfile.length>0){ i=findData(ptyfile,"ExcitationOutPutLevel",0,0); if(iendt){j+=(tps-endt+1);} } ch=floor(j/(steps*tps)); sl=floor((j%(steps*tps))/tps); frm=j%tps; //zero index //print(ptyname+" "+ch+" "+sl+" "+frm); ptyname=File.getName(ptyfilepaths[j]); ptyfile=split(openoif(ptyfilepaths[j]),"\n"); i=0; i=findData(ptyfile,"Axis 4 Parameters",0,0); i=findData(ptyfile,"AbsPositionValue",i,0); if(i-1); hasZ=(indexOf(ptyname,"Z")>-1); if((!hasC||indexOf(ptyname,"C001")>-1)&&(!hasZ||indexOf(ptyname,"Z001")>-1)){ times=Array.concat(times,alltimes[alltimes.length-1]); //print(times[times.length-1]); } } showProgress(j/(ptyl-1)); } //showProgress(1); iid=getImageID(); altl=alltimes.length; adder=""; showStatus("Applying pty times..."); for(i=0;i-1) { starttime=substring(xmlfile[1],tindx+6,indexOf(xmlfile[1],"\" notes=")); startdate=substring(starttime,0,indexOf(starttime," ")); vindx=indexOf(xmlfile[1],"version="); if(vindx>-1) {version=substring(xmlfile[1],vindx+9,indexOf(xmlfile[1],"\" date=")); } } // chs=0; i=0; while(indexOf(xmlfile[i], " -1) {chs++; i++;} fc=-1; i=0; while(indexOf(xmlfile[i], "cycle=")== -1) {i++; if(i>50||i==xmlfile.length) {if(report) showMessage("Could not get data from xml file"); return xylist;}} fc=i; firstcyclenum=parseInt(substring(xmlfile[fc],indexOf(xmlfile[i], "cycle=")+7,indexOf(xmlfile[i], "cycle=")+8)); if(firstcyclenum==0) n=0; while(indexOf(xmlfile[i], "positionCurrent_XAxis")== -1) {i++; if(i==xmlfile.length) {if(report) showMessage("Could not get data from xml file"); return xylist;}} fxac=i-fc; //first Xaxis position after each cycle xaxispos=i; while(indexOf(xmlfile[i], "PVStateShard")== -1) i++; restlen=i-xaxispos; //length of the rest of the values after Xaxis //set values to zero used to be here. fz=0; for(i=fc; i<(fxac+fc+restlen);i++){ if(indexOf(xmlfile[i],"opticalZoom")!=-1) zm=getXmlValue(xmlfile[i],-1); else if(indexOf(xmlfile[i],"pmtGain_0")!=-1) gains[0]=parseFloat(getXmlValue(xmlfile[i],0)); else if(indexOf(xmlfile[i],"pmtGain_1")!=-1) gains[1]=parseFloat(getXmlValue(xmlfile[i],0)); else if(indexOf(xmlfile[i],"pmtGain_2")!=-1) gains[2]=parseFloat(getXmlValue(xmlfile[i],0)); else if(indexOf(xmlfile[i],"pmtGain_3")!=-1) gains[3]=parseFloat(getXmlValue(xmlfile[i],0)); else if(indexOf(xmlfile[i],"laserPower_0")!=-1) lpower=getXmlValue(xmlfile[i],0); else if(indexOf(xmlfile[i],"objectiveLens\"")!=-1) objective=getXmlValue(xmlfile[i],0); else if(indexOf(xmlfile[i],"micronsPerPixel_XAxis")!=-1) xysize=parseFloat(getXmlValue(xmlfile[i],-1)); else if(indexOf(xmlfile[i],"pixelsPerLine")!=-1) pixels=parseFloat(getXmlValue(xmlfile[i],-1)); //else if(indexOf(xmlfile[i],"positionCurrent_ZAxis")!=-1) fz=getXmlValue(xmlfile[i],-1); } zoom=zm; badnumstr="0.1689 0.1953 1.0135"; pchange=false; if(indexOf(badnumstr,d2s(xysize*zm*pixels/512,4))!=-1) {xysize=propxy*512/pixels/zm; pchange=true;} if(version=="4.3.1.17") xysize/=parseFloat(zm); ni=i; while((indexOf(xmlfile[ni], "cycle=\"")== -1 && indexOf(xmlfile[ni], "PVScan")== -1) && (ni<(xmlfile.length-1))) ni++; steps="1"; endofcyc=ni-1; //lz=0; goback=true; while(goback){ if(indexOf(xmlfile[ni],"pmtGain_0")!=-1) gainends[0]=parseFloat(getXmlValue(xmlfile[ni],0)); else if(indexOf(xmlfile[ni],"pmtGain_1")!=-1) gainends[1]=parseFloat(getXmlValue(xmlfile[ni],0)); else if(indexOf(xmlfile[ni],"pmtGain_2")!=-1) gainends[2]=parseFloat(getXmlValue(xmlfile[ni],0)); else if(indexOf(xmlfile[ni],"pmtGain_3")!=-1) gainends[3]=parseFloat(getXmlValue(xmlfile[ni],0)); else if(indexOf(xmlfile[ni],"laserPower_0")!=-1) lpowerend=getXmlValue(xmlfile[ni],0); //else if(indexOf(xmlfile[i],"positionCurrent_ZAxis")!=-1) lz=getXmlValue(xmlfile[i],-1); else if(indexOf(xmlfile[ni],"index=")!=-1) { ioindex=indexOf(xmlfile[ni],"index="); iolabel=indexOf(xmlfile[ni],"\" label="); steps=substring(xmlfile[ni],ioindex+7,iolabel); goback=false; } ni--; } while((indexOf(xmlfile[i],"positionCurrent_ZAxis")==-1) && ((i+2)-1){ if((indexOf(xmlfile[i],"cycle=\"")>-1)&&(i+fxac+maxOf(2,nzp)0) if(xylist[0]==xystring) {timecounter=true; tps++;} if(!timecounter) { xylist=addArray(xylist, xystring); } } else if(xylist[0]==xystring) tps++; timestemp=newArray(times.length+1); for(j=0;j0){ gtxt=gtxt+"Gain"+(i+1)+": "+gains[i]; if(gainends[i]>0)gtxt=gtxt+"-"+gainends[i]; gtxt=gtxt+" "; } } lwvtxt=""; if(lwv!="NA")lwvtxt=" Wv: "+lwv; avetext=""; if(averaging!=0){avetext=" Ave:"+averaging+" "+averagingtype;} print(longname+":"); print("Started at: "+starttime+" Locs: "+locs+" Zoom: "+zm+" Obj: "+objective); print("XY: "+pixels+" x "+xysize+"um Z: "+steps+" x "+zstep+"um T: "+tps+" x "+intervaltime+"s"+avetext); print(gtxt+"Laser: "+lpower+"-"+lpowerend+lwvtxt); step2=" Single Image"; for(i=0;i2) {print("1st tf / ave not last / Ave time frame / XML time: " +firsttimeframe+" / "+ onelessavetimeframe +" / "+ avetimeframe +" / "+ xmlintervaltime);} else if(times.length>1) {print("Time btn 1+2 / Ave time frame / XML time: " +firsttimeframe+" / "+ avetimeframe +" / "+ xmlintervaltime);} //newline=""; //if(tps>1) newline=""+startdate+"\t"+tps+"\t"+(onelesstp/(tps-2))+"\t"+steps+"\t"+zstep[0]+"\t"+zm+"\t\t\t\t\t"+ // substring(longname,lastIndexOf(longname,osdiv)+1,lengthOf(longname)); //if(newset) String.copy(newline); //else String.copy(String.paste+"\n"+newline); if(pchange) print("Detected Old 2p bad size, changed based on propxy: "+propxy); addloc=false; if(printxyfile){ title1 = "Exlocs.xy"; title2 = "["+title1+"]"; f = title2; loffset=0; startstr="\n\n"; addloc=false; if (isOpen(title1)) { selectWindow(title1); addloc=true; //=getBoolean("OK to add to Exlocs window (no means clear it)?"); if(addloc) { oldwindow=getInfo("window.contents"); if(startsWith(oldwindow,startstr)) startstr=substring(oldwindow,0,indexOf(oldwindow,"")); oldsplit=split(oldwindow,"\n"); loffset=oldsplit.length-3; } } else { if (getVersion>="1.41g") run("Text Window...", "name="+title2+" width=80 height=20 menu"); else run("New... ", "name="+title2+" type=[Text File] width=80 height=20 menu"); } print(f, "\\Update:"); // clears the window print(f,startstr); for(i=0;i\n"); } print(f,""); } if(printmap){ if(isOpen("LocMap")){ selectWindow("LocMap"); currmapno=parseInt(getMetadata("Info")); if(!(currmapno>0)) currmapno=0; } else { newImage("LocMap", "8-bit White", 500, 500, 1); currmapno=0; } setForegroundColor(0,0,0); setJustification("center"); drawString("Origin",250,250); for(i=0;i0) res=""+hours+":"+pad(minutes,2)+":"+pad(secs,2); return ""+res } macro "Quick Import [i]" { if(!prefsloaded) loadPrefs(); sb=getDirectory(""); openQuick(sb,true); } var dogamma=false; var dotimes=false; function openQuick(s,askit){ path = getDirectory("temp")+"AJlist.txt"; title="Time Series Clock"; title2="["+title+"]"; //iposx=650; iposy=300; mposx=25; mposy=120; winw=26; winh=124; winzm=1; //ibxd=200; ibyd=-50; //mbxd=-50; mbyd=-50; embig=false; IID = "null"; scale=100; boo=true; fl=getFileList(s); RGBname=File.getName(s); ss=substring(s,0,lengthOf(s)-1)+osdiv; //OIF compatibility + tests for empty folders + recurse folders---------- oifdo=false; //oifnotime=false; oifnoz=false; zchar="Z"; prairie=false; hastifs=false; go=true; fcount=0; recurse=false; if(fl.length>0){ for(i=0;i0){ dofs=true; if(fcount==1) ask=false; } if(ask && askit) { Dialog.create("Open all"); if(dofs) checktext="Open all folders?"; else checktext="Open all tifs in folder?"; Dialog.addCheckbox(checktext,true); if(dofs)Dialog.addCheckbox("Recurse?",false); Dialog.addCheckbox("Skip if already open?",true); Dialog.addString("Filter: ",""); Dialog.addMessage("Wildcard [*] at start or end of filter means"); Dialog.addMessage("that it ends with or starts with the string."); Dialog.show() if(dofs) dofs=Dialog.getCheckbox(); else dotifs=Dialog.getCheckbox(); if(dofs) recurse=Dialog.getCheckbox(); skipopen=Dialog.getCheckbox(); filterstring=Dialog.getString(); } if(dofs || dotifs){ gottime=getTime; for(i=0;i0); hasZ=(slind>0); hasC=(chind>2); } else{ //Prairie tif folder cycind=lastIndexOf(fl[i],"Cycle")+5; slind=lengthOf(fl[i])-7; chind=indexOf(fl[i],"_Ch")+3; while(substring(fl[i],cycind+3,cycind+4)!="_") cycind++; ifindex=0; if(!endsWith(fl[ifindex],"xml")) ifindex=1; infofile=s+fl[ifindex]; zoom="NA"; //if(cycind<5) oifnotime=true; hasT=cycind>5; hasZ=true; hasC=true; if(chind<3) exit("Error with tif file name, no Ch found in:\n"+fl[i]); } filesize=File.length(s+fl[i]); if(endsWith(infofile,"xml") || endsWith(infofile,"oif")) xylist=ExLoc(infofile, 1, false, false); else xylist=newArray(0); cont=false; autodc=false; chchoice="GBR"; stackluts=newArray(6);n=0; stackluts[0]="Red"; stackluts[1]="Green"; stackluts[2]="Blue"; stackluts[3]="Magenta"; stackluts[4]="Cyan"; stackluts[5]="Yellow"; if(oifdo){ for(i=0;i-1) {chchoice="RGB"; chchoicedefault=chchoice; autodc=true;} if(indexOfArray(pgreens,chnums[0])>-1) {chchoice="GBR"; chchoicedefault=chchoice; autodc=true;} if(chnums[0]==-16766721) {chchoice="BRG"; chchoicedefault=chchoice; autodc=true;} } //res=call("AJ_FileTest.tryOpen",infofile); //res="true"; //if(res=="false") cont=true; virtual=false; dlm=File.lastModified(s+fl[0]); dlm2=File.lastModified(s+fl[fl.length-2]); tolf=(getTime-dlm2)/1000; if(tolf<30) cont=true; //print("totaltime: "+((parseInt(dlm2)-dlm)/1000)); //exit(); totaltps=0; intervaltime=0; if(xylist.length>0) { xys=split(xylist[0]," "); if(xys.length>4) {intervaltime=xys[4]; totaltps=xys[5];} } startloop=true; contloop=true; cycle=-1; lastslice=-1; sfltime=0; sflsls=1; totalstarttime=0; while(contloop){ if(cont) fl=getFileList(s); fltif=newArray(0); dlm2=-1; for(i=0;i1)){ Dialog.create(RGBname); if(!onecyc) { Dialog.addString("Timepoints",tpstr); Dialog.addCheckbox("Include slice times?",dotimes); } if(locs>1) {Dialog.addNumber("Location:",1,0,3,"out of "+locs);} Dialog.addCheckbox("Virtual?",virtual); Dialog.addCheckbox("Half Gamma?", dogamma); if(!autodc) Dialog.addMessage("Ch1 number: "+chnums[0]); if(chm>1 && !oifdo) Dialog.addChoice("Ch:", chchoicearray, chchoicedefault); if(cont) Dialog.addCheckbox("Continue Update?",false); if(tolf<60*60) Dialog.addMessage("Time since last file: "+round(tolf)); if(cont) Dialog.addCheckbox("Web",false); if(cont) Dialog.addCheckbox("Set an event to mark",false); Dialog.show(); if(!onecyc) { tpstr=Dialog.getString(); dotimes=Dialog.getCheckbox(); } if(locs>1) loc=Dialog.getNumber(); else loc=1; loc--; virtual=Dialog.getCheckbox(); dogamma=Dialog.getCheckbox(); if(chm>1) {if(oifdo){chchoice="RGB";} else {chchoice=Dialog.getChoice();} chchoicedefault=chchoice;} else if(chm==1) chchoice="1chOnly"; // old way-> otherwise chm is >1 and autodc is true, meaning that chchoice is already defined if(cont) cont=Dialog.getCheckbox(); if(cont) web=Dialog.getCheckbox(); if(cont) setevent=Dialog.getCheckbox(); if(setevent){ Dialog.create("set event"); Dialog.addString("Time or time point of event","12:20:23"); Dialog.addString("Event name:","CGRP"); Dialog.show(); eventtime=Dialog.getString(); eventname=Dialog.getString(); } } dozee=defdozee; if(onecyc)dozee=false; printprefs(); if(locs>1) RGBname=RGBname+"-loc"+(loc+1); hyph=indexOf(tpstr,"-"); if(hyph==-1){tpstart=parseInt(tpstr)-1; tpend=parseInt(tpstr); dozee=false;} else { tpstart=parseInt(substring(tpstr,0,hyph))-1; tpend=parseInt(substring(tpstr,hyph+1,lengthOf(tpstr)));} if(chchoice=="1chOnly"){chm=1;} chst=0; chend=chm; if(chchoice=="1"){chend=1;} if(chchoice=="2") {chst=1;} if(cont) {tpstart=0; tpend=cycle;} if(isKeyDown("shift")){dozee=!dozee; shiftheld=true;} } else { cont=true; dozee=true; selectWindow(RGBname); getDimensions(wid,hei,chm,slices,tpstart); virtual=is("Virtual Stack"); IID=getImageID(); if(chm>1) { for(chi=0;chi(1*cycle)) { tpstr0=tpstr0+"/"+totaltps; tpstr1=tpstr1+" / "+textTime(totaltps*intervaltime*1000); } tpstr2="Idle for "+textTime(deadtime); if(isOpen("Time Series Clock")){ print(title2, "\\Update0:"+tpstr0); print(title2, "\\Update1:"+tpstr1); print(title2, "\\Update2:"+tpstr2); if(web){ f=File.open("C:\\Inetpub\\wwwroot\\goingon.txt"); print(f, tpstr0); print(f,tpstr1); print(f,tpstr2); File.close(f); } } else contloop=false; } else {contloop=false;} totalstarttime=getTime; slices=0; for(i=0;itpstart; //if I want to update the first image with every updated new slice.. //if(prevlastslice>-1){ // if(prevcycle==cycle && cycle==1 && prevlastslice1) for(chi=0;chi1)*WINYPERDIM+(slicearray[loc]>1)*WINYPERDIM+((tpend-tp2start)>1)*WINYPERDIM; if(autoplace || cont) setLocation(iposx,iposy,wid*winzm+winw,hei*winzm+winh); //setZoom(winzm); Stack.setPosition(ch,sl,frm); zsize=propz; if(xylist.length>0) { xys=split(xylist[loc]," "); if(xys.length>3) zsize=xys[3]; mlocdata="Loc: "; lbls=newArray("x:","y:","z:","zsize:","tsize:","TPS:"); for(xyi=0;xyi1){ selectImage(maxID); getDimensions(mxwid,mxhei,mxchs,mxsls,mxfrms); run("Z Project...","start="+mxfrms+" stop="+mxfrms+" projection=[Max Intensity]"); zID=getImageID; run("Stack to RGB"); rename("temp"); selectImage(zID); close; selectWindow("temp"); run("Size...", "width=230 height=230 constrain interpolation=Bilinear"); saveAs("Jpeg", "C:\\Inetpub\\wwwroot\\goingon.jpg"); selectWindow("goingon.jpg"); close(); f=File.open("C:\\Inetpub\\wwwroot\\goingon.txt"); print(f, tpstr0); print(f,tpstr1); print(f,tpstr2); File.close(f); if( (mxfrms>3) && mxfrms%5==0 ){ selectImage(maxID); //run("AVI... ", "compression=JPEG jpeg=10 frame=5 save=C:\\Inetpub\\wwwroot\\goingon.avi"); run("Duplicate...", "title=giffer duplicate"); wait(200); run("Size...", "width=230 height=230 constrain interpolate"); wait(200); selectWindow("giffer"); if(setevent){ run("Print Time", "set="+eventtime+" levels=1 prefix=["+eventname+"] background label do"); } getDimensions(gfw,gfh,gfchs,gfsls,gffrms); gfslfr="slices"; if(gffrms>gfsls) gfslfr="frames"; run("Stack to RGB", gfslfr); selectWindow("giffer"); if(!isFiji) run("Animated Gif... ", "save=C:\\inetpub\\wwwroot\\goingon.gif"); else run("Animated Gif ... ", "name=giffer set_global_lookup_table_options=[Do not use] optional=[] image=[No Disposal] set=500 number=0 transparency=[No Transparency] red=0 green=0 blue=0 index=0 filename=C:\\inetpub\\wwwroot\\goingon.gif"); selectWindow("giffer"); close(); } } } if(startloop) startloop=false; }//tpend>tpstart if(cont) { if(!isOpen(RGBname)) contloop=false; if(!isOpen("MAX_"+RGBname)) contloop=false; if(!isOpen(title)) contloop=false; if(!contloop) beep; wait(3000); } } //contloop if(isOpen(IID) && !cont){ selectImage(IID); //if(!isOpen("B&C")) run("Brightness/Contrast..."); //else selectWindow("B&C"); Stack.setSlice(slicearray[loc]/2); for(ch=chm2;ch>0;ch--){ selectImage(IID); Stack.setChannel(ch); resetMinAndMax(); //selectWindow("B&C"); } Stack.setSlice(1); selectImage(IID); } //print("Openquick took "+(getTime-totalstarttime)/1000+"s"+" SFL: "+sfltime+"s, "+(sfltime/sflsls)+"s/frame"); print("Openquick took "+(getTime-totalstarttime)/1000+"s"+" SFL: "+sfltime+"s, "+(d2s(mbps,2))+"MB/s"); return true; } function setZoom(ajz){ run("Set... ", "zoom="+ajz*100); } function copyTo(IID){ run("Select All"); run("Copy"); close(); selectImage(IID); setSlice(nSlices); run("Add Slice"); run("Paste"); } function getCfgCch(fl){ //requires indexOfArray() as well function cfgLine(line,ind){ line=split(line," "); part=split(line[ind],"\""); if(part[1]=="True") result=1; else if(part[1]=="False") result=0; else result=parseInt(part[1]); return result; } li=0; while(!endsWith(fl[li],"Config.cfg") && li=digits) result = num; else result= substring(toString(num+digits),1,digs+1); return result; } function enoughMem(needmem){ //enoughMem(w,h,chs,sls,frms, bits) //bits/=8; if(bits==3)bits=4; //needmem=(bits+bits*0.0364)*w*h*chs*sls*frms/1073741824; //parseInt(IJ.currentMemory())/1024/1024/1024; //parseInt(IJ.maxMemory())/1024/1024/1024; run("Collect Garbage"); memleft=(parseFloat(IJ.maxMemory())-parseFloat(IJ.currentMemory())); //print(""+needmem+" "+memleft); if(needmem