// ------------------------------------------------------------------------------------------------------------------------------------------- // Sarah Bailey 17 Dec 2013 - option to invert images if background is dark added by Matt Bolt 29 Aug 2014 // ------------------------------------------------------------------------------------------------------------------------------------------- // Results X,Y display rather than North South // At Coll 90, North (G) = X2, South (T) = X1, East (B) = Y1, West (A) = Y2 // ********************* global variables *********************** // can be seen (edited) by all functions in this macro var maxPixValue; var pWidth; var pHeight; var arrayImageID; var arrayImageName; var myFolder; var myLinac; var intEnergy; var intSSD; var strDateImage; var meanImage; var pLow; // used in mini profile of overlap region var pHigh; var xArr; var yArr; var myLen; // ------------------------------------------------------------------------------------------------------------------------------------------- // MAIN MACRO // ------------------------------------------------------------------------------------------------------------------------------------------- macro "AssymAnalysis" { version = "1.1"; update_date = "23 December 2016 by MB"; requires("1.47p"); myLinac = getArgument() ; if(myLinac == "") { myLinac = "Select"; } // Show a dialog to user so that they know the macro is running if (nImages != 0) { exit("Oops, please close all images before running this macro! "); } lstLinac = newArray("LA1","LA2","LA3","LA4","LA5", "LA6", "Red-A", "Red-B", "Select"); Dialog.create("Macro Opened"); Dialog.addMessage("EPID QC Asymmetric Image Analysis"); Dialog.addMessage("Version: " + version); Dialog.addMessage("Last Updated: " + update_date); Dialog.addMessage(""); Dialog.addMessage("This is an automated process as folows:"); Dialog.addMessage("You will be promted to select the folder containg the 4 asymmetric images."); Dialog.addMessage("Results appear in the Log window"); Dialog.addMessage(""); //Dialog.addMessage("Linac: "+myLinac); Dialog.addChoice(" Linac:", lstLinac,myLinac); Dialog.addMessage(" ***** Click OK to start ******"); Dialog.show(); myLinac = Dialog.getChoice(); myDirectory = "G:\\Shared\\Oncology\\Physics\\Linac Field Analysis\\"+myLinac+"\\ "; call("ij.io.OpenDialog.setDefaultDirectory", myDirectory); call("ij.plugin.frame.Editor.setDefaultDirectory", myDirectory); print(myDirectory); myFolder = getDirectory("Choose Image File Directory "); list = getFileList(myFolder); setBatchMode(true); if (list.length != 4) { exit("Oops, only 4 images can be analysed! "); } // removes any previous calibration - affects the X-ray field results myCF = 0.039; for (k=0; k 1) { meanMin = (myProfile[pMin -1]+myProfile[pMin]+myProfile[pMin +1])/3; } if (pMax >1) { meanMax = (myProfile[pMax -1]+myProfile[pMax]+myProfile[pMax +1])/3; } pHigh = (maxPixValue - meanMin)/pAvg; pLow = (maxPixValue - meanMax)/pAvg; // store results in an array so we can read them later if (isX=="X") { xArr[arrayPos]= 100*pLow; xArr[arrayPos+1]= 100*pHigh; } if (isX=="Y") { yArr[arrayPos] = 100*pLow; yArr[arrayPos+1] = 100*pHigh; } } // End of Function // **************************** FUNCTION FIND MEAN ****************************************** function findMean(myImageID){ selectImage(myImageID); // ROI normally drawn on combined image pxROI = 50; // determines the size and location of ROI - i.e. 50 pixels from edge, 100 pixels square for 1024 image makeRectangle(xV1-pxROI, yH1-pxROI, 2*pxROI, 2*pxROI); getRawStatistics(area,mean); ROIMean = mean; makeRectangle(xV2-pxROI, yH1-pxROI, 2*pxROI, 2*pxROI); getRawStatistics(area,mean); ROIMean = ROIMean +mean; makeRectangle(xV1-pxROI, yH2-pxROI, 2*pxROI, 2*pxROI); getRawStatistics(area,mean); ROIMean = ROIMean +mean; makeRectangle(xV2-pxROI, yH2-pxROI, 2*pxROI, 2*pxROI); getRawStatistics(area,mean); ROIMean = (ROIMean +mean)/4; return ROIMean; } // End of Function Find Mean // ***************************** FUNCTION PRINT HEADER ************************************ function printHeader(){ strDate = getMyDate(); print ("\\Clear"); print("-------------------------------------------------------------"); print(" Assymmetric Image Analysis using EPID"); print("-------------------------------------------------------------"); print("Images Analysed:"); print(myFolder); print("Image Date: "+strDateImage); print("Analysis Date: "+strDate); print("Macro Version:"+version); print("Linac: "+myLinac); print("Energy: "+intEnergy+"MV"); print("SSD: "+intSSD+"cm"); print("-------------------------------------------------------------"); print("Ratios of intersection to image mean: "); print("\n"); } // End Function // ************************ FUNCTION SAVE RESULTS ******************************************* function saveResults(){ // Add Comments & Save Results Dialog.create("Comments"); // Allows user to insert comments if required. Default is "Results OK" These are then added to Log Dialog.addMessage("Add any Comments in the Box Below"); Dialog.addString("Comments:", "None",40); Dialog.addMessage(""); Dialog.addString("Analysis Performed by:", "",10); Dialog.addMessage("Click OK to Continue"); Dialog.show(); print("\n"); print("Comments:"+Dialog.getString()); print("Analysis Performed by:" + Dialog.getString()); print("\n"); print("-------------------------------------------------------------"); Dialog.create("~~ Save Results ~~"); // Asks user if they want to save results (as a text file). If they select cancel, the macro wil exit, therefore the save will not occur. Dialog.addMessage(" Save the Results? "); Dialog.show(); selectWindow("Log"); // Get data from log window for transfer to Text window to save contents = getInfo(); FileExt = ".txt"; title1 = strDateImage+"-"+myLinac+"-"+intEnergy+"-AsymResults" + FileExt+ FileExt; // Title of log window is filename without extension as defined at start. title2 = "["+title1+"]"; // Repeat f = title2; if (isOpen(title1)) { print(f, "\\Update:"); selectWindow(title1); // clears the window if already one opened with same name } else { run("Text Window...", "name="+title2+" width=72 height=60"); } setLocation(screenWidth()-50,screenHeight()-50); // Puts window out of sight print(f,contents); saveAs("Text"); run("Close"); } // End of Function // **************************** FUNCTION GET DATE ****************************************** function getMyDate() { arrMonth = newArray("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec); strDate = ""+dayOfMonth+"-"+arrMonth[month]+"-"+year; return strDate; } // End Function