//Now requires correct pixel size to be set // Map metadata "Info" is n (up to which image number), origxysize function getTextLUT(imageID,ch){ selectImage(imageID); getDimensions(w,h,chs,sls,frms); if(ch>chs) exit("ch too great"); if(bitDepth ==24) exit("Does not work on RGB image"); if(Stack.isHyperstack)Stack.setChannel(ch); getLut(reds,greens,blues); max=maxOf(reds[128],maxOf(greens[128],blues[128])); if(max==reds[128]) { result="Red"; if(max==greens[128]) result="Yellow"; if(max==blues[128]) result="Magenta"; if(max==greens[128] && max==blues[128]) result="Grays"; } else if(max==greens[128]) { result="Green"; if(max==blues[128]) result="Cyan"; } else if(max==blues[128]) result="Blue"; return ""+result; } //macro "Mapify"{ getDimensions(wid, hei, channels, slices, frames); oid=getImageID(); getPixelSize(unit,px,py); pxfac=px; origxysize=px; if(unit!="microns") { showMessageWithCancel("Ok to use pixelsize: "+px+"?"); if(px==1) showMessageWithCancel("Really? Pixel size of 1 is probably wrong."); } title=getTitle; name="Map"; if(slices==1 && frames>1) { luts=newArray(channels); for(i=0;i1) Stack.setChannel(1); askauto9=false; auto9=false; if((slices==9) && !startsWith(getMetadata("Label"),"Loc")) askauto9=true; lwidth=4; fontsize=32; mapisopen=false; useopenmap=true; if(isOpen(name)) mapisopen=true; else if(isOpen("Map.tif")) {mapisopen=true; name="Map.tif";} Dialog.create("Settings"); Dialog.addNumber("Line Width:",lwidth); Dialog.addNumber("Font Size:", fontsize); Dialog.addNumber("Px Size:", pxfac); Dialog.addCheckbox("Should I even draw them?",false); Dialog.addCheckbox("Copy instead of Max Mode",true); Dialog.addCheckbox("Auto fix positions from previous",false); if(askauto9) Dialog.addCheckbox("Assume 9-Montage?",true); if(mapisopen) Dialog.addCheckbox("Use open Map?",true); Dialog.show(); lwidth=Dialog.getNumber(); fontsize=Dialog.getNumber(); pxfac=Dialog.getNumber(); drawstuff=Dialog.getCheckbox(); copymode=Dialog.getCheckbox(); autofix=Dialog.getCheckbox(); if(askauto9) auto9=Dialog.getCheckbox(); if(mapisopen) useopenmap=Dialog.getCheckbox(); setPasteMode("Max"); if(copymode) setPasteMode("Copy"); setFont("SansSerif", fontsize); setColor(255,0,0); setLineWidth(lwidth); setJustification("center"); mwid=1600; mhei=1600; //pxfac=pxfac/(wid/512); bits=bitDepth(); closergb=false; if(channels>1) { closergb=true; Stack.setChannel(1); mld=newArray(slices); for(i=0;i1) Stack.setSlice(i+1); mld[i]=getMetadata("Label");} run("Stack to RGB", "slices keep"); RGBID=getImageID(); for(i=0;i1) Stack.setSlice(i+1); setMetadata("Label",mld[i]);} } else if(bits != 24){ run("Duplicate...", "duplicate"); run("RGB Color"); RGBID=getImageID(); closergb=true;} IID=getImageID; if(!useopenmap) { shortname=name; extra=0; do{ extra++; name=shortname+"-"+extra;} while(isOpen(name)); } if(isOpen(name)) { selectWindow(name); getDimensions(mwid, mhei, mchannels, mslices, mframes); mdata=getMetadata("Info"); mdata=split(mdata," "); n=parseInt(mdata[0]); origxysize=parseFloat(mdata[1]); } else { newImage(name, "RGB Black", mwid, mhei, 1); n=1; } endim=getImageID; selectImage(IID); dxtemp=dytemp=0; minxpos=-1; minypos=-1; maxxpos=-1; maxypos=-1; for(i=0;i6 || auto9){ if(auto9){ x=0; y=0; zm=1; if(i==0 || i==5 || i==6) x+=250; if(i<3) y+=250; if(i==2 || i==3 || i==8) x-=250; if(i>5) y-=250; x/=pxfac; y/=pxfac; }else{ x=parseFloat(spa[1])/pxfac; y=parseFloat(spa[2])/pxfac; z=parseFloat(spa[3])/pxfac; zm=parseFloat(spa[6]); if(spa.length==10) x=-x; //Oif fix for up being negative } if(i==0) {if(abs(x)>1200 || abs(y) >1200){xadj=x; yadj=y;} else {xadj=0; yadj=0;}} x-=xadj; y-=yadj; run("Select All"); run("Duplicate...", "title=temp"); //if(!(pxfac==px/(wid/512))) cwid=wid/(origxysize/px); chei=hei/(origxysize/px); if(origxysize!=px) { run("Size...", "width="+cwid+" height="+chei+" interpolation=Bilinear"); } getDimensions(cwid, chei, nochannels, noslices, noframes); if(autofix){ //outdated selectImage(IID); right=true; down=false; if(i>0){ xch=x-xprev; ych=y-yprev; if((abs(xch)<475) && (abs(ych)<475)){ if(xch>-50) right=false; setSlice(i); if(i<3 || i>6) {rect=newArray(416,0,512,512); recs=newArray(0,0,96,512);} else if(i==3 || i==6) {rect=newArray(0,416,512,512); recs=newArray(0,0,512,96);} else {recs=newArray(416,0,512,512); rect=newArray(0,0,96,512);} makeRectangle(rect[0],rect[1],rect[2],rect[3]); run("Duplicate...", "title=targ"); run("8-bit"); getDimensions(widt,heit,ch,slr,frm); selectImage(IID); setSlice(i+1); makeRectangle(recs[0],recs[1],recs[2],recs[3]); run("Duplicate...", "title=sour"); run("8-bit"); getDimensions(wid,hei,ch,sls,frm); run("TurboReg ","-align -window sour 0 0 "+(wid-1)+" "+(hei-1)+" -window targ 0 0 "+(widt-1)+" "+(heit-1) +" -translation " +((wid-1)/2)+" "+((hei-1)/2)+" "+((widt-1)/2)+" "+((heit-1)/2) +" -showOutput"); dxtemp = round(parseFloat(getResult("sourceX", 0)) - parseFloat(getResult("targetX", 0))); dytemp = round(parseFloat(getResult("sourceY", 0)) - parseFloat(getResult("targetY", 0))); dx+=dxtemp; dy+=dytemp; x+=dx; y+=dy; selectWindow("sour"); close; selectWindow("targ"); close; selectWindow("Output"); close; print("\\Update:Changed "+(i+1)+" by "+dx+" and "+dy); print("[Refined Landmarks]","\\Clear"); print("[Refined Landmarks]","\\Close"); } } xprev=x; yprev=y; } selectWindow("temp"); run("Select All"); run("Copy"); close; selectImage(endim); xor=mwid/2; yor=mhei/2; xpos=xor-(cwid/2)-x; ypos=yor-(chei/2)-y; change=false; if(xpos<0) {mwid=mwid+2*(abs(xpos)+10); change=true;} if((xpos+cwid) > mwid) {mwid=mwid+2*((xpos+cwid+10)-mwid); change=true;} if(ypos-30<0) {mhei=mhei+2*(abs(ypos)+60); change=true;} if((ypos+chei) > mhei) {mhei=mhei+2*((ypos+chei+10)-mhei); change=true;} if(change) { run("Canvas Size...", "width="+mwid+" height="+mhei+" position=Center zero"); xor=mwid/2; yor=mhei/2; xpos=xor-(cwid/2)-x; ypos=yor-(chei/2)-y; } makeRectangle(xpos, ypos, cwid, chei); run("Paste"); if(drawstuff){ drawRect(xpos, ypos, cwid, chei); drawString(toString(n),xpos,ypos); } n++; if(minxpos==-1) minxpos=xpos; if(minypos==-1) minypos=ypos; minxpos=minOf(xpos,minxpos); minypos=minOf(ypos,minypos); maxxpos=maxOf(xpos+cwid,maxxpos); maxypos=maxOf(ypos+chei,maxypos); } else print("Slice "+(i+1)+" skipped, cannot read label"); } run("Select None"); setMetadata("Info", ""+n+" "+origxysize); //if(slices==9){ // makeRectangle(127,127,1346,1346); //} makeRectangle(minxpos,minypos,maxxpos-minxpos,maxypos-minypos); if(closergb) { selectImage(RGBID); close;} //} end macro