// Realign OCT // // This is a set of tools to relign an OCT image //GLOBAL VARIABLES var slicewidth = 1, topslice = 50, bottomslice = 49, offset = 0, pixelsperslice = 10, noslices = 100, noslicesout = 100, sequencetype = 1, skanlabel, skanlabeltype; var imageid = 0, stackid = 0, resliceid = 0, skanlabel = "skan", imagechoice; var imagedir = "", newfolder = "", templatedir; var stackwidth = 0, stackheight = 0, imagewidth = 0, imageheight = 0; var scrheight, scrwidth; var protocolin = newArray("7mm x 7mm", "10mm x 10mm", "5mm x 5mm", "5mm x 10mm", "8mm x 12mm"); var protocolout = newArray("7mm x 7mm", "10mm x 10mm", "5mm x 5mm", "12mm x 12mm"); var protocolinchoice = "5mm x 10mm", protocoloutchoice = "10mm x 10mm", Ascanspacing = 1.1, Bscanspacing = 1.1; var template = 1, recentre = 0, reverse = 1, fovea = 1, eye = 1, eyestring = "right"; var firstname = "X", lastname = "X", gender = "1", day = "1", month = "1", year = "2000"; var testday = "1", testmonth = "1", testyear = "2010", testtime = "12:00:00"; var superlative = newArray("FINE", "FINE", "FINE", "FINE", "FINE", "FINE", "FINE", "FINE","FINE","FINE","FINE"); var edgerpe = newArray("Non-oblique","Internally oblique", "Internally oblique with Bruch's membrane overhang", "Externally oblique","Other"); var rpedeflection = newArray("Straight", "Downwards", "Upwards","Other"); var typevessel = newArray("None", "Hyaloid", "Vessel", "Other"); var locationvessel = newArray("None","Upper half of cup", "Lower half of cup", "Cup bottom", "Along whole edge","Other"); var picname = "CHANGE NAME"; var rpe=newArray(2000); var ilm=newArray(2000); var rnfl=newArray(2000); var bruchs=newArray(2000); var optionstrings = newArray ("Go to select area to analyse", "Go to adjust brightness / contrast", "Go to anisometropic filter", "Go to flatten disk", "Go to ABSnake", "CONTINUE"); var option = 0; var optionstringsfirst = newArray ("Go to select area to analyse", "Go to adjust brightness / contrast", "Go to anisometropic filter", "CONTINUE"); call("java.lang.System.gc"); /////COPY THIS SECTION var imageJdir = getDirectory("imagej"); //IMAGEJ FOLDER var mainOCTdir = imageJdir+"\\OCT_Analysis\\"; //FOLDER WITH CONFIG FILES ETC var layerimagesdir = imageJdir+"\\images\\layers\\ONH\\"; //FOLDER WITH CONFIG FILES ETC var onhfolder = imageJdir+"\\ONH_ANALYSIS\\"; //TEXT FILES RESULTS ARE SAVED HERE /////////////////////////////////////////////////////////////// var xx = setup(); // runs when macros are installed function setup() { setOption("QueueMacros", true); return true; } macro "START Action Tool - Cff0Cf0fCf00C0ffC0f0C00fC000C135D00D01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eD0fD10D1fD20D2fD30D3fD40D4fD50D5fD60D6fD70D7fD80D8fD90D9fDa0DafDb0DbfDc0DcfDd0DdfDe0DefDf0Df1Df2Df3Df4Df5Df6Df7Df8Df9DfaDfbDfcDfdDfeDffCc00D4cD53D54D55D56D5cD5dD62D63D64D65D66D67D6cD6dD72D76D77D7dD82D87D88D8cD8dD92D97D98D99D9cD9dDa2Da3Da8Da9DaaDabDacDb9DbaDbbCc11D45D78Cc22D44D52D57D9bCc33Db8Cd44D4bD4dD73D7cD81D86Da7DadDbcCd55D71D93D9aCd66D43D46D91Ce88D68D7eD83D89Db2Db3Ce88D61D6eD8eCe99D5bD75Da1CeaaD96CebbDcaCfccD5eD9eDc9DcbCfddD42D8bDa4Db4CfeeD47D51D58D74D79Db7Dbd"{ //SET UP VARIABLES AND IMPORT DATA scrheight = screenHeight(); scrwidth = screenWidth(); stackid = nImages; //IF BUTTONS ARE PRESSED BEFORE LAST SET OF FILES ARE CLOSED if (stackid>0) { waitForUser("Realign Tool", "THERE ARE FILES ALREADY OPEN! PLEASE CLOSE THEM FIRST!"); } else { imagechoice = getBoolean("DO YOU WANT TO ANALYSE A SINGLE PREVIOUSLY SAVED IMAGE (NO FOR STACK)?"); if (imagechoice==1){ open(); picname=getInfo("image.filename"); picname=substring(picname, 0, lengthOf(picname)-4); } else { run("OCT Reader", "select=[]"); run("Flip Vertically", "stack"); run("Reverse"); } protocolinchoice = "8mm x 12mm"; protocoloutchoice = "12mm x 12mm"; sequencetype=0; //GET IMPORTANT PARAMETERS stackwidth = getWidth(); stackheight = getHeight(); noslices = nSlices(); stackid = getImageID(); imagedir = getDirectory("image"); setLocation(0, 0, (scrwidth*0.5), (scrheight*0.95)); run("Point Tool...", "mark=0 label selection=yellow"); //shortenchoice = getBoolean("DO YOU WANT TO SHORTEN HEIGHT TO 1010?"); //if(shortenchoice==1){ //Fill out canvas to required size stackheight = 1010; //} //eye = getBoolean("IS THIS RIGHT EYE DATA (NO FOR LEFT)?"); //if (eye==0){ eyestring="left"; //} //else //{ //eyestring="right"; //} } if (noslices>300){ waitForUser("Realign Tool", "THERE ARE TOO MANY SLICES FOR THIS PROGRAM (MAX = 300)!"); } else { if (imagechoice!=1){ //CREAT DIALOG BOX Dialog.create("PLEASE SET INPUT SETTINGS FOR THE FILE ANALYSIS"); Dialog.addMessage("FILE SETTINGS"); Dialog.addMessage("Stack width is "+stackwidth+" pixels"); Dialog.addMessage("Stack height is "+stackheight+" pixels"); Dialog.addMessage("No of slices is "+noslices); Dialog.addMessage(""); Dialog.addMessage("PROTOCOL SETTINGS"); Dialog.addChoice("Choose original protocol used", protocolin, protocolinchoice); Dialog.addChoice("Choose final protocol to save", protocolout, protocoloutchoice); Dialog.show(); //GET VALUES OUT OF DIALOG BOX protocolinchoice = Dialog.getChoice(); protocoloutchoice = Dialog.getChoice(); //SET UP PARAMETERS BASED ON CHOICES if (protocolinchoice=="7mm x 7mm") { Ascanspacing = 7000/stackwidth; Bscanspacing = 7000/noslices; } if (protocolinchoice=="10mm x 10mm") { Ascanspacing = 10000/stackwidth; Bscanspacing = 10000/noslices; } if (protocolinchoice=="5mm x 5mm") { Ascanspacing = 5000/stackwidth; Bscanspacing = 5000/noslices; } if (protocolinchoice=="5mm x 10mm") { Ascanspacing = 10000/stackwidth; Bscanspacing = 5000/noslices; } if (protocolinchoice=="8mm x 12mm") { Ascanspacing = 12000/stackwidth; Bscanspacing = 8000/noslices; } if (protocoloutchoice=="7mm x 7mm") { imagewidth = round(7000/Ascanspacing); noslicesout = round(7000/Bscanspacing); templatedir = mainOCTdir+"Copernicus_Templates\\7mmx7mm"; } if (protocoloutchoice=="10mm x 10mm") { imagewidth = round(10000/Ascanspacing); noslicesout = round(10000/Bscanspacing); templatedir = mainOCTdir+"Copernicus_Templates\\10mmx10mm"; } if (protocoloutchoice=="5mm x 5mm") { imagewidth = round(5000/Ascanspacing); noslicesout = round(5000/Bscanspacing); templatedir = mainOCTdir+"Copernicus_Templates\\10mmx10mm"; } if (protocoloutchoice=="12mm x 12mm") { imagewidth = round(12000/Ascanspacing); noslicesout = round(12000/Bscanspacing); templatedir = mainOCTdir+"Copernicus_Templates\\12mmx12mm"; } templatedir =templatedir+"_"+stackwidth+"Ascans"; templatedir = templatedir+"_"+noslicesout+"Bscans"; //templatedir = templatedir+"_200Bscans"; if (fovea==1){ templatedir = templatedir+"_fovea"; } else { templatedir = templatedir+"_ONH"; } pixelsperslice = round(Bscanspacing/Ascanspacing); imageheight = pixelsperslice * noslicesout; if (sequencetype==0) { // CHANGE CANVAS WIDTH BASED ON PARAMETERS run("Canvas Size...", "width="+imagewidth+" height="+stackheight+" position=Center zero"); run("Out"); //put default in centre slice and middle if(recentre==1) { Stack.setSlice(noslices/2); run("Colors...", "foreground=blue background=white selection=yellow"); makePoint(imagewidth/2, stackheight/2); setTool(7); setLocation(0, 0, (scrwidth*0.5), (scrheight*0.95)); waitForUser("SET POINT AND SLICE AT MIDPOINT OF FOVEA TO RECENTRE"); n=getSliceNumber(); getSelectionCoordinates(a, b); //will move run("Translate...", "x="+((imagewidth/2)-a[0])+" y=0 interpolation=None stack"); } else { n=round(noslices/2); } if (noslicesout>noslices) { i=round((noslicesout/2)-(noslices-n)); j=noslicesout-noslices-i; Stack.setSlice(noslices); if (i>0){ for (l=0; l0){ Stack.setSlice(0); run("Add Slice"); Stack.swap(1, 2); } if(j>1){ Stack.setSlice(0); for (l=1;lnoslicesout-1){ topslice=noslicesout-1; } if (bottomslice>noslicesout){ bottomslice=noslicesout; } slicewidth = bottomslice - topslice; selectImage(stackid); setSlice(topslice+1); selectImage(imageid); makeRectangle(0, topslice*pixelsperslice, imagewidth, slicewidth*pixelsperslice); } macro "LEFT Action Tool - Cff0Cf0fCf00C0ffC0f0C00fC000C135D00D01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eD0fD10D1fD20D2fD30D3fD40D48D4fD50D57D58D5fD60D67D68D69D6fD70D76D77D78D79D7fD80D85D86D87D88D89D8aD8fD90D95D96D97D98D99D9aD9fDa0Da4Da5Da6Da7Da8Da9DaaDabDafDb0Db4Db5Db6Db7Db8Db9DbaDbbDbcDbfDc0Dc3Dc4Dc5Dc6Dc7Dc8Dc9DcaDcbDccDcfDd0DdfDe0DefDf0Df1Df2Df3Df4Df5Df6Df7Df8Df9DfaDfbDfcDfdDfeDffC246D66D7aD9bC247D47D59Db3C468D38D94DcdC579D75DacC68aD56D8bDd3Dd4Dd5Dd6Dd7Dd8Dd9DdaDdbDdcDddC79bDc2Dd2C89bD37D6aC9bcD49Da3CabdD84DbdCbcdD9cCbceD28D46D65D7bDdeCcdfD11D12D13D14D15D16D17D18D19D1aD1bD1cD1dD1eD21D22D23D24D25D26D27D29D2aD2bD2cD2dD2eD31D32D33D34D35D36D39D3aD3bD3cD3dD3eD41D42D43D44D45D4aD4bD4cD4dD4eD51D52D53D54D55D5aD5bD5cD5dD5eD61D62D63D64D6bD6cD6dD6eD71D72D73D74D7cD7dD7eD81D82D83D8cD8dD8eD91D92D93D9dD9eDa1Da2DadDaeDb1Db2DbeDc1DceDd1De1De2De3De4De5De6De7De8De9DeaDebDecDedDee"{ offset = offset-1; selectImage(imageid); makeRectangle(0, topslice*pixelsperslice, imagewidth, slicewidth*pixelsperslice); run("Translate...", "x=-1 y=0 interpolation=None"); selectImage(stackid); for (loop=topslice+1; loopnoslicesout-1){ topslice=noslicesout-1; } if (bottomslice>noslicesout){ bottomslice=noslicesout; } slicewidth = bottomslice - topslice; selectImage(stackid); setSlice(topslice+1); selectImage(imageid); makeRectangle(0, topslice*pixelsperslice, imagewidth, slicewidth*pixelsperslice); } macro "LEFTKey [n]"{ offset = offset-1; selectImage(imageid); makeRectangle(0, topslice*pixelsperslice, imagewidth, slicewidth*pixelsperslice); run("Translate...", "x=-1 y=0 interpolation=None"); selectImage(stackid); for (loop=topslice+1; loopnoslicesout-1){ topslice=noslicesout-1; } if (topslice==bottomslice){ topslice=topslice-1; } slicewidth = bottomslice - topslice; selectImage(stackid); setSlice(topslice+1); selectImage(imageid); makeRectangle(0, topslice*pixelsperslice, imagewidth, slicewidth*pixelsperslice); } macro "MOVEBOTTOMUPKey [e]"{ bottomslice = bottomslice - 1; if (bottomslice==topslice){ bottomslice = bottomslice + 1; } if (bottomslice>noslicesout){ bottomslice=noslicesout; } slicewidth = bottomslice - topslice; selectImage(stackid); setSlice(topslice+1); selectImage(imageid); makeRectangle(0, topslice*pixelsperslice, imagewidth, slicewidth*pixelsperslice); } macro "MOVEBOTTOMDOWNKey [d]"{ bottomslice = bottomslice + 1; if (bottomslice>noslicesout){ bottomslice=noslicesout; } slicewidth = bottomslice - topslice; selectImage(stackid); setSlice(topslice+1); selectImage(imageid); makeRectangle(0, topslice*pixelsperslice, imagewidth, slicewidth*pixelsperslice); } macro "UP Action Tool - Cff0Cf0fCf00C0ffC0f0C00fC000C135D00D01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eD0fD10D1fD20D2fD30D3cD3fD40D4aD4bD4cD4fD50D58D59D5aD5bD5cD5fD60D67D68D69D6aD6bD6cD6fD70D75D76D77D78D79D7aD7bD7cD7fD80D84D85D86D87D88D89D8aD8bD8cD8fD90D96D97D98D99D9aD9bD9cD9fDa0Da8Da9DaaDabDacDafDb0DbaDbbDbcDbfDc0DcbDccDcfDd0DdfDe0DefDf0Df1Df2Df3Df4Df5Df6Df7Df8Df9DfaDfbDfcDfdDfeDffC246D66Da7Db9C247D3bD74D95C468D49D83DdcC579D57DcaC68aD3dD4dD5dD65D6dD7dD8dD9dDadDb8DbdDcdDddC79bD2cD2dC89bD73Da6C9bcD3aD94CabdD48DdbCbcdDc9CbceD56D64D82Db7DedCcdfD11D12D13D14D15D16D17D18D19D1aD1bD1cD1dD1eD21D22D23D24D25D26D27D28D29D2aD2bD2eD31D32D33D34D35D36D37D38D39D3eD41D42D43D44D45D46D47D4eD51D52D53D54D55D5eD61D62D63D6eD71D72D7eD81D8eD91D92D93D9eDa1Da2Da3Da4Da5DaeDb1Db2Db3Db4Db5Db6DbeDc1Dc2Dc3Dc4Dc5Dc6Dc7Dc8DceDd1Dd2Dd3Dd4Dd5Dd6Dd7Dd8Dd9DdaDdeDe1De2De3De4De5De6De7De8De9DeaDebDecDee"{ selectImage(stackid); run("Translate...", "x=0 y=-1 interpolation=None slice"); } macro "DOWN Action Tool - Cff0Cf0fCf00C0ffC0f0C00fC000C135D00D01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eD0fD10D1fD20D2fD30D33D3fD40D43D44D45D4fD50D53D54D55D56D57D5fD60D63D64D65D66D67D68D69D6fD70D73D74D75D76D77D78D79D7aD7bD7fD80D83D84D85D86D87D88D89D8aD8bD8fD90D93D94D95D96D97D98D99D9fDa0Da3Da4Da5Da6Da7Da8DafDb0Db3Db4Db5Db6DbfDc0Dc3Dc4DcfDd0DdfDe0DefDf0Df1Df2Df3Df4Df5Df6Df7Df8Df9DfaDfbDfcDfdDfeDffC246D34D9aC247D46D8cDd3C357D58C468D6aDc5C468Db7C579D23C679D7cC68aD35Da9C79bD9bC89bD47Dd4C9bcD22D32D42D52D59D62D72D82D92Da2Db2Dc2Dc6Dd2CabdD8dCbcdD6bDb8CbceD24D36D7dDaaDe2De3CcdfD11D12D13D14D15D16D17D18D19D1aD1bD1cD1dD1eD21D25D26D27D28D29D2aD2bD2cD2dD2eD31D37D38D39D3aD3bD3cD3dD3eD41D48D49D4aD4bD4cD4dD4eD51D5aD5bD5cD5dD5eD61D6cD6dD6eD71D7eD81D8eD91D9cD9dD9eDa1DabDacDadDaeDb1Db9DbaDbbDbcDbdDbeDc1Dc7Dc8Dc9DcaDcbDccDcdDceDd1Dd5Dd6Dd7Dd8Dd9DdaDdbDdcDddDdeDe1De4De5De6De7De8De9DeaDebDecDedDee"{ selectImage(stackid); run("Translate...", "x=0 y=1 interpolation=None slice"); } macro "ONH Action Tool - C500D22C100D64C900DfbC000D4bD4cD4dD5dD5eD5fD63Dc4C700D97C300D31D87Cc00D1bD25D32D34D99Dd5C600D45C200Dd4Ca00DcfC800D2bC311D17D7fCd00D09C511D1fD39D7dD8cD8dD8fDaaC200D40D51DfaC911D7bDc7C611D05D9eDeeC411D28D3aD46D47Cd00De5C611D38D6cD9cDb9Dd8DdfC311D06D3bD56D67DcbDd9Cb11D04D89C811D2eD7aC411D2aD53D55D6dCe00D03D0cD13D98DcdC411D0fD8eDe7C100D65C911D1eD69D79D9bDb7DedDefC711D37C311D29D48D6eDbaDf7Cc00D0aD1cD1dD88DccDdcC611D19D3dDffC211D3eD58De9DeaCb00D1aD9aDaeDceDebDf5DfcC811D6aD8aC311D6fDabDacDc9De8Cd00D0dD14D23DbeDbfC111D07D49DcaCa11D0bD2dD9fDd6C711D16D8bDb8Dd7Cd00D24D33DbdC211Df8C911D0eD2cD35Da9Ce00DafDecC511DadC100D4aD5cDdaCa00Db6C611D36D68C300D52C600D08Dc5DdbC211D18D57D59DbbCb11Da8Dc6DddC811D42D6bDe6Df6DfeC711D7cDc8C511D2fD7eD9dDdeC100D3fD5aD5bD66Db5C711D27D41DfdC400Da6C511D43D44D54C000Df9C700D3cDbcC300De4Ca11D15D26C700D02C400D12Df4C500D78Cb00Da7"{ thisslice=topslice+1; selectImage(stackid); scrheight = screenHeight(); scrwidth = screenWidth(); xindex=0; k=1; option=0; stackwidth = getWidth(); stackheight = getHeight(); noslices = nSlices(); imagewidthmm=10; pixheightmm=2.4; //picname = "CHANGE NAME"; noascans = stackwidth; //CREAT DIALOG BOX Dialog.create("PLEASE SET INPUT SETTINGS FOR B SCAN FLATTENING"); Dialog.addMessage("FILE SETTINGS"); Dialog.addMessage("Stack width is "+stackwidth+" pixels"); Dialog.addMessage("Stack height is "+stackheight+" pixels"); Dialog.addMessage("No of slices is "+noslices); Dialog.addString("Image filename ",picname, 50); Dialog.addString("Save results to folder ",onhfolder, 50); Dialog.addMessage(""); Dialog.addMessage("PROTOCOL SETTINGS"); Dialog.addNumber("IMAGE WIDTH (mm)", imagewidthmm); Dialog.addNumber("NO OF A SCANS",noascans); Dialog.addNumber("PIXEL HEIGHT (mm)",pixheightmm); Dialog.addNumber("Rectangle Width", 40); Dialog.addNumber("Step Size", 20); Dialog.addNumber("Threshold", 25); Dialog.addNumber("Line Width", 6); Dialog.addNumber("Line Height", 60); Dialog.addMessage(""); Dialog.addCheckbox("Use Anisometropic Filter?", true); Dialog.addCheckbox("Use ABSnake for ILM Detection?", true); Dialog.addCheckbox("Flatten using spline (uncheck for linear)?",false); Dialog.show(); //GET VALUES OUT OF DIALOG BOX pname = Dialog.getString(); onhfolder = Dialog.getString(); imagewidthmm = Dialog.getNumber(); noascans = Dialog.getNumber(); pixheightmm = Dialog.getNumber(); recwidth = Dialog.getNumber(); step = Dialog.getNumber(); threshold = Dialog.getNumber(); linewidth = Dialog.getNumber(); lineheight = Dialog.getNumber(); anisofilter = Dialog.getCheckbox(); absnakeplugin = Dialog.getCheckbox(); splineflatten = Dialog.getCheckbox(); //MAIN LOOP STARTS HERE //GET AXIAL LENGTH ROUTINE years = 0.0; months = 0.0; weeks = 0.0; prem=false; addgp=0; almethod="MEASURED"; axiallength=0; change=0; do{ if (years==NaN) years=0; if (months==NaN) months=0; if (weeks==NaN) weeks=0; prevgestage=(years*52.17857143)+(months*4.348214286)+weeks+(addgp*39.14); ageans=false; Dialog.create("GET AXIAL LENGTH"); Dialog.addMessage("PLEASE INPUT GESTATIONAL AGE"); Dialog.addNumber("Years", years); Dialog.addNumber("Months", months); Dialog.addNumber("Weeks", weeks); Dialog.addCheckbox("Premature infant", prem); Dialog.addCheckbox("For normals add 39 weeks?", addgp); Dialog.addMessage(""); Dialog.addMessage(""); Dialog.addMessage("ALTERNATIVELY INPUT AXIAL LENGTH"); Dialog.addNumber("AXIAL LENGTH - "+almethod, axiallength); Dialog.show(); years = Dialog.getNumber(); months = Dialog.getNumber(); weeks = Dialog.getNumber(); prem = Dialog.getCheckbox(); addgp = Dialog.getCheckbox(); axiallength = Dialog.getNumber(); gestage=(years*52.17857143)+(months*4.348214286)+weeks+(addgp*39.14); if(gestage>0){ axiallength=getcorrectionfactor(gestage, prem); almethod="ESTIMATED"; } else { almethod="MEASURED"; } if(axiallength<=0) ageans=getBoolean("AGE IS OUT OF RANGE. INPUT AGE AGAIN? (PRESS 'NO' TO CONTINUE)?"); }while ((ageans==true)||(prevgestage!=gestage)); if(axiallength<=0){ axiallength=23.98; almethod="DEFAULT"; } /////////////////////////////////////////////////////////////////////////// anssaveimage = 3; do{ do{ if (option==0){ selectImage(stackid); run("Duplicate...", "title=[SINGLESLICE] duplicate range="+thisslice+"-"+thisslice); picid = getImageID(); setLocation(0, 0, (scrwidth*0.5), (scrheight*0.95)); tempnas=getBoolean("IS THE IMAGE FROM THE LEFT EYE ('NO' FOR RIGHT)?"); if (tempnas==0){ picname=pname+"_R"; } else { picname=pname+"_L"; } flipans=getBoolean("IS NASAL ON THE LEFT ('NO' WILL FLIP THE IMAGE)?"); if(flipans==0){ run("Select All"); run("Flip Horizontally"); } if (anssaveimage==3){ anssaveimage = getBoolean("WOULD YOU LIKE TO SAVE A COPY OF THE IMAGE?"); if (anssaveimage==1){ saveAs("tiff", onhfolder+pname+".tif"); } } // SET ANALYSIS AREA AND ADD BORDER run("Point Tool...", "mark=0 label selection=yellow"); makeRectangle(100, 100, 300, 500); waitForUser("SET RECTANGLE FOR ANALYSIS AREA"); run("Crop"); stackwidth = getWidth(); stackheight = getHeight(); noslices = nSlices(); run("Canvas Size...", "width="+(stackwidth+100)+" height="+(stackheight+100)+" position=Center"); stackwidth = stackwidth+100; stackheight = stackheight+100; norecs = round(stackwidth/step); } if (option<2){ //ADJUST BRIGHTNESS CONTRAST selectImage(picid); setLocation(0, 0, (scrwidth*0.4), (scrheight*0.95)); run("Brightness/Contrast..."); waitForUser("ADJUST BRIGHTNESS / CONTRAST"); run("Close"); } if(option<3){ //ANISOTROPIC FILTER //anisofilter = getBoolean("DO YOU WANT TO APPLY THE ANISOTROPIC FILTER?"); if (anisofilter==true){ selectImage(picid); setLocation(0, 0, (scrwidth*0.4), (scrheight*0.95)); makeRectangle(0, 0, stackwidth, stackheight); run("Anisotropic Diffusion 2D",""); anpicid = getImageID(); selectImage(picid); setLocation((scrwidth*0.8), (scrheight*0.8) ,(scrwidth*0.2), (scrheight*0.2)); selectImage(anpicid); setLocation(0, 0, (scrwidth*0.4), (scrheight*0.95)); } rnd=round(random()*10); optionstringsfirst[3]="Image looks "+superlative[rnd]+"!"; Dialog.create("MAKE SELECTION AND PRESS OK"); Dialog.addChoice("Please choose place to return to: ", optionstringsfirst, optionstringsfirst[3]) Dialog.show(); menuchoice = Dialog.getChoice(); for (v=0; v<4; v++) { if (menuchoice == optionstringsfirst[v]) option=v; } if (option==0) { selectImage(picid); run("Close"); } if (option<3) { selectImage(anpicid); run("Close"); } } }while (option<3); if (option==3){ option=5; } if (option<4 || option==5){ //FLATTEN DISC selectImage(anpicid); if (splineflatten==1) { layerimagelocation=layerimagesdir+"rpe_choroid.tif"; meanrpe=polylinetoarray(50, stackwidth-50, stackwidth, "LOWER RPE BORDER",1, layerimagelocation, anpicid, rpe); //FLATTEN USING RPE for (s=50; s>16)&0xff; // extract red byte (bits 23-17) green = (v>>8)&0xff; // extract green byte (bits 15-8) blue = v&0xff; // extract blue byte (bits 7-0) if (red>250 && green<5 && blue<5){ findred=1; } i=i+1; } //setKeyDown("alt"); // profile = getProfile(); //i=0; //threshold=240; //Array.getStatistics(profile, min, max, mean, stdDev); //while (profile[i]threshold) { profile2[j] = i; j=j+1; } } profile2 = Array.trim(profile2, j-1); Array.getStatistics(profile2, min, max, mean, stdDev); ilmfitx[k] = xindex+(recwidth/2); ilmfity[k] = min; if (ilmfity[k]<((lineheight/2)+1)) ilmfity[k]=stackheight/2; if (ilmfity[k]>stackheight-((lineheight/2)+1)) ilmfity[k]=stackheight/2; ///CORRECT ILMFIT TO SHARPEST CONTRAST makeLine(ilmfitx[k], ilmfity[k]-(lineheight/2), ilmfitx[k], ilmfity[k]+(lineheight/2), linewidth); //waitForUser("MAKE LINE"); lineprofile = getProfile(); maxdiff=0; diff=0; maxdiffindex=0; for (l=0; l<(lineheight-2); l++) { diff=abs(lineprofile[l]-lineprofile[l+1]); if (diff>maxdiff) { maxdiff=diff; maxdiffindex=l; } } ilmfity[k]=ilmfity[k]-(lineheight/2)+maxdiffindex; /////// k=k+1; } ilmfitx = Array.trim(ilmfitx, k); ilmfity = Array.trim(ilmfity, k); ilmfitx[k-1]=stackwidth; ilmfity[k-1]=(2*ilmfity[k-2])-ilmfity[k-3]; ilmfity[0]=(2*ilmfity[1])-ilmfity[2]; } //END OF LOOPS selectImage(anpicid); makeSelection("polyline", ilmfitx, ilmfity); layerimagelocation=layerimagesdir+"ilm.tif"; polylinetoarray(50, stackwidth-50, stackwidth, "INTERNAL LIMITING MEMBRANE",0, layerimagelocation, anpicid, ilm); rnd=round(random()*10); optionstrings[5] ="Results look "+superlative[rnd]+"!"; Dialog.create("MAKE SELECTION AND PRESS OK"); Dialog.addChoice("Please choose place to return to: ", optionstrings, optionstrings[5]) Dialog.show(); menuchoice = Dialog.getChoice(); for (v=0; v<6; v++) { if (menuchoice == optionstrings[v]) option=v; } if (option==0) { selectImage(picid); run("Close"); } if (option<3) { selectImage(anpicid); run("Close"); } }while (option<5); getSelectionCoordinates(ilmx, ilmy); //EXTRA LAYERS GO HERE analysernflrt=getBoolean("DO YOU WANT ANALYSE RNFL ANDBRUCH'S ON BOTH SIDES?"); if (analysernflrt==true){ addrnfl=true; addbruchs=true; } //RNFL Array.fill(rnfl, -7777); if (analysernflrt==false) addrnfl=getBoolean("DO YOU WANT ADD LEFT RNFL TO THE TEXT FILE?"); if(addrnfl ==true) { layerimagelocation=layerimagesdir+"rnfl_nasal.tif"; polylinetoarray(50, disclx, stackwidth, "LEFT RNFL",1, layerimagelocation, anpicid, rnfl); } if (analysernflrt==false) addrnfl=getBoolean("DO YOU WANT ADD RIGHT RNFL TO THE TEXT FILE?"); if(addrnfl ==true) { layerimagelocation=layerimagesdir+"rnfl_temp.tif"; polylinetoarray(discrx, stackwidth-50, stackwidth, "RIGHT RNFL",1, layerimagelocation, anpicid, rnfl); } //BRUCH'S Array.fill(bruchs, meanrpe); if(splineflatten ==false) { Array.fill(bruchs, -7777); if (analysernflrt==false) addbruchs=getBoolean("DO YOU WANT ADD LEFT BRUCH'S TO THE TEXT FILE?"); if (addbruchs==true){ layerimagelocation=layerimagesdir+"bruchs_nasal.tif"; polylinetoarray(50, disclx, stackwidth, "NASAL BRUCH'S",1, layerimagelocation, anpicid, bruchs); } if (analysernflrt==false) addbruchs=getBoolean("DO YOU WANT ADD RIGHT BRUCH'S TO THE TEXT FILE?"); if (addbruchs==true){ layerimagelocation=layerimagesdir+"bruchs_temp.tif"; polylinetoarray(discrx, stackwidth-50, stackwidth, "TEMPORAL BRUCH'S",1, layerimagelocation, anpicid, bruchs); } } //PRINT OUTPUT //OPEN FILE AND HEADER INFORMATION f = File.open(onhfolder+picname+".txt"); print(f, "PATIENT PARAMETERS\n"); print(f, picname+"\n"); print(f, "gestational age (weeks)\t" + d2s(gestage,2) + "\n"); print(f, "axial length (mm)\t" + d2s(axiallength,2) +"\t" + almethod+"\n"); print(f, "correction factor\t" + d2s(axiallength/23.98,2) + "\n"); print(f, "SCAN PARAMETERS\n"); print(f, "no Ascans\t" + d2s(noascans,0) + "\n"); print(f, "image width\t" + d2s(imagewidthmm,4) + "\n"); print(f, "analysed image width\t" + d2s(stackwidth-100,0) + "\n"); print(f, "pixel height\t" + d2s(pixheightmm,4) + "\n"); pixwidthmm=(axiallength/23.98)*((imagewidthmm*1000)/noascans); print(f, "pixel width\t" + d2s(pixwidthmm,4) + "\n"); print(f, "DISC PARAMETERS\n"); print(f, "disc width\t" + d2s((discwidth),2) + "\n"); print(f, "y disc offset\t" + d2s((meanrpe-discref),2) + "\n"); print(f, "nasal disc edge\t" + lrpeedge + "\n"); print(f, "nasal disc deflection\t" + lrpedeflection + "\n"); print(f, "temporal disc edge\t" + rrpeedge + "\n"); print(f, "temporal disc deflection\t" + rrpedeflection + "\n"); print(f, "CUP PARAMETERS\n"); print(f, "cup depth\t" + d2s((cupy[0]-discref),0) + "\n"); print(f, "nasal vessel type\t" + ncupvessel + "\n"); print(f, "nasal vessel location\t" + ncuplocation + "\n"); print(f, "nasal vessel cutoff\t" + d2s(ncupcutoff,0) + "\n"); print(f, "temporal vessel type\t" + tcupvessel + "\n"); print(f, "temporal vessel location\t" + tcuplocation + "\n"); print(f, "temporal vessel cutoff\t" + d2s(tcupcutoff,0) + "\n"); print(f, "cup description\t" + cupdescription + "\n"); print(f, "LAYERS\n"); print(f, "x_pixel\tdisc centre\tindex\tcup bottom\tILM\tRNFL\tBruch's\n"); //LOOP THROUGH PIXELS FROM LEFT TO RIGHT INTERPOLATING BETWEEN POINTS IN ARRAY phase=1; tnsym=1; tncup=1; xval=(disccentre-50)*-1; for (p=50; p<(stackwidth-50); p++) // I.E. WHOLE SELECTION { phase=1; if (p>disclx) // SORT OUT 4 PHASES phase=2; if (p>=cupx[0]) phase=3; if (p>=discrx) phase=4; if (rnfl[p]>0) //SUBTRACT FROM MEAN RPE rnfl[p]=meanrpe-rnfl[p]; ilm[p]=meanrpe-ilm[p]; if (bruchs[p]>0) //SUBTRACT FROM MEAN RPE bruchs[p]=meanrpe-bruchs[p]; if (p>disccentre) //SORT OUT DISC AND CUP CENTRE tnsym=2; if (p>cupx[0]) tncup=2; print(f, d2s(xval,2) + "\t"+ d2s(tnsym,0) + "\t" + d2s(phase,0) + "\t" +d2s(tncup,0) + "\t"+ d2s(ilm[p],2) + "\t" + d2s(rnfl[p],2) + "\t" + d2s(bruchs[p],2) + "\n"); xval=xval+1; } File.close(f); finalquestion = getBoolean("GO TO "+onhfolder+" FOR RESULTS. DO YOU WANT TO USE THE SAME STACK AGAIN?"); anssaveimage = 3; selectImage(anpicid); run("Close"); if (finalquestion==0) { if (imagechoice==0){ selectImage(imageid); run("Close"); } selectImage(stackid); run("Close"); } selectImage(picid); run("Close"); } } function polylinetoarray(xmin, xmax, width, layername, lineoption, linesimage, analysisimageid, testarray){ polyx=newArray(0); polyy=newArray(0); splinex=newArray(0); spliney=newArray(0); //LINEOPTION: 0:LINE PRESENT - CHECKED FOR WIDTH, 1: ADD LINE - CHECKED FOR WIDTH, 2: ADD LINE - CHECKED ON LEFT, 3: ADDLINE - CHECKED ON RIGHT, 4: ADD LINE NO CHECKING if (lineoption<=1) addanalysistype="ALONG THE WHOLE PROFILE"; if (lineoption==2) addanalysistype="ALONG THE NASAL SEGMENT"; if (lineoption==3) addanalysistype="ALONG THE TEMPORAL SEGMENT"; open(linesimage); linesimageid = getImageID(); setLocation((scrwidth*0.5), (scrheight*0.3), (scrwidth*0.4), (scrheight*0.5)); selectImage(analysisimageid); if (lineoption==0){ //JUST SORT OUT SPLINE AS LINE IS PRESENT polyx = Array.trim(polyx, 1); polyy = Array.trim(polyy, 1); getSelectionCoordinates(polyx, polyy); do{ nopoints=0; run("Select None"); makeSelection("polyline", polyx, polyy); run("Fit Spline"); waitForUser("MAKE FINE ADJUSTMENTS TO SPLINE FOR LAYER '"+layername+"'"); wait(200); if(selectionType()!=-1){ getSelectionCoordinates(splinex, spliney); nopoints=splinex.length; } } while ((selectionType()==-1)||(nopoints<20)); //I.E. IF NO SELECTION OR POLYLINE RATHER THAN SPLINE } //ADD A LINE SINCE NOT ONE PRESENT if (lineoption>=1){ do{ run("Select None"); rightButton=4; ctrl=2; setTool("polyline"); getCursorLoc(x, y, z, flags); while ((flags&rightButton==0)&&(flags&ctrl==0)) { getCursorLoc(x, y, z, flags); } } while (selectionType()==-1); polyx = Array.trim(polyx, 1); polyy = Array.trim(polyy, 1); getSelectionCoordinates(polyx, polyy); do{ nopoints=0; run("Select None"); makeSelection("polyline", polyx, polyy); run("Fit Spline"); waitForUser("MAKE FINE ADJUSTMENTS TO SPLINE FOR LAYER '"+layername+"'"); wait(200); if(selectionType()!=-1){ getSelectionCoordinates(splinex, spliney); nopoints=splinex.length; } } while ((selectionType()==-1)||(nopoints<20)); //I.E. IF NO SELECTION OR POLYLINE RATHER THAN SPLINE } splinex = Array.trim(splinex, 1); spliney = Array.trim(spliney, 1); selectImage(analysisimageid); getSelectionCoordinates(splinex, spliney); if (splinex[0]>splinex[1]){ //REVERSE IF WRONG WAY AROUND Array.reverse(splinex); Array.reverse(spliney); } //LINEOPTION: 0:LINE PRESENT - CHECKED FOR WIDTH, 1: ADD LINE - CHECKED FOR WIDTH, 2: ADD LINE - CHECKED ON LEFT, 3: ADDLINE - CHECKED ON RIGHT, 4: ADD LINE NO CHECKING if (lineoption<=1){ while ((splinex[0]>=xmin)||(splinex[splinex.length-1]<=xmax)){ //MAKE LINE LONGER IF NOT LONG ENOUGH do{ nopoints=0; run("Select None"); makeSelection("polyline", polyx, polyy); run("Fit Spline"); waitForUser("YOU NEED TO MAKE THE LINE LONGER!!"); wait(200); if(selectionType()!=-1){ getSelectionCoordinates(splinex, spliney); nopoints=splinex.length; } } while ((selectionType()==-1)||(nopoints<20)); //I.E. IF NO SELECTION OR POLYLINE RATHER THAN SPLINE splinex = Array.trim(splinex, 1); spliney = Array.trim(spliney, 1); getSelectionCoordinates(splinex, spliney); if (splinex[0]>splinex[1]){ //REVERSE IF WRONG WAY AROUND Array.reverse(splinex); Array.reverse(spliney); } } } if (lineoption==2){ while (splinex[0]>=xmin){ //MAKE LINE LONGER IF NOT LONG ENOUGH do{ nopoints=0; run("Select None"); makeSelection("polyline", polyx, polyy); run("Fit Spline"); waitForUser("YOU NEED TO MAKE THE LINE LONGER ON THE LEFT!!"); wait(200); if(selectionType()!=-1){ getSelectionCoordinates(splinex, spliney); nopoints=splinex.length; } } while ((selectionType()==-1)||(nopoints<20)); //I.E. IF NO SELECTION OR POLYLINE RATHER THAN SPLINE splinex = Array.trim(splinex, 1); spliney = Array.trim(spliney, 1); getSelectionCoordinates(splinex, spliney); if (splinex[0]>splinex[1]){ //REVERSE IF WRONG WAY AROUND Array.reverse(splinex); Array.reverse(spliney); } } xmax=splinex[splinex.length-1]; //MAKE MAX = SPLINE END testarray[xmax]=spliney[spliney.length-1]; } if (lineoption==3){ while (splinex[splinex.length-1]<=xmax){ //MAKE LINE LONGER IF NOT LONG ENOUGH do{ nopoints=0; run("Select None"); makeSelection("polyline", polyx, polyy); run("Fit Spline"); waitForUser("YOU NEED TO MAKE THE LINE LONGER ON THE RIGHT!!"); wait(200); if(selectionType()!=-1){ getSelectionCoordinates(splinex, spliney); nopoints=splinex.length; } } while ((selectionType()==-1)||(nopoints<20)); //I.E. IF NO SELECTION OR POLYLINE RATHER THAN SPLINE splinex = Array.trim(splinex, 1); spliney = Array.trim(spliney, 1); getSelectionCoordinates(splinex, spliney); if (splinex[0]>splinex[1]){ //REVERSE IF WRONG WAY AROUND Array.reverse(splinex); Array.reverse(spliney); } } xmin=splinex[0]; //MAKE MAX = SPLINE END testarray[0]=spliney[0]; //SORT OUT FIRST AND LAST POINTS } if (lineoption==4){ xmin=splinex[0]; //MAKE MIN AND MAX = SPLINE ENDS xmax=splinex[splinex.length-1]; testarray[0]=spliney[0]; //SORT OUT FIRST AND LAST POINTS testarray[xmax]=spliney[spliney.length-1]; } selectImage(linesimageid); close(); selectImage(analysisimageid); novals=0; sumvals=0; //LOOP THROUGH PIXELS FROM LEFT TO RIGHT INTERPOLATING BETWEEN POINTS IN ARRAY for (s=xmin; s<=xmax; s++){ for (q=0; q<(splinex.length-1);q++){ if ((s>=splinex[q])&(s0){ return (sumvals/novals); } } function getcorrectionfactor(age, prem){ premsweeks = newArray(27.99, 32.01, 36.01, 40.01, 44.01, 52.01, 56.01); normsweeks = newArray(31.99, 39.14, 66.08, 114.99, 167.45, 222.03, 270.95, 325.53, 380.11, 457.38, 692.02, 951.47, 1500.14, 3169.86, 3691.64, 4213.43, 5257.00); premsaxial = newArray(14.86, 15.44, 16.09, 16.84, 17.43, 18.58, 19.27); normsaxial = newArray(16.61, 16.80, 17.40, 18.60, 18.87, 19.20, 20.07, 21.27, 21.75, 22.14, 22.26, 22.66, 23.98, 23.60, 23.44, 23.39, 23.20); axiallength=-1; if (prem==1){ for (q=0; q<(premsweeks.length-1);q++){ if ((age>=premsweeks[q])&(age=normsweeks[q])&(age