Hey guys,
I have a series of image processing codes that I have written, some in ImageJ Macro form and some in python for various reasons, and I am trying pass the results from one to the other (flatfielding, stitching, aligning, etc until I have about 5 ijm and 5 py codes. What I am looking to do is pass the results of the python code into the macro and have it automatically run and then the python script realize when the macro completed. The only way that I can see this working is to have the python script create a .txt file with the parameters that need to be passed to the macro and then to run the macro by calling it from the command line through python. The only step in this process that I cannot figure out is reading in the variables from a text file. I would like to be able to have it in the format of "variable_name=###\n" but I cannot find any reference as to how to read that in. Any advice would be greatly appreciated. Mike |
Hi Mike,
Here is some macro code that I use to write and load analysis parameters in a text file, so that I can reuse them next time I use the macro. Perhaps you can use the code to read your .txt files created by your python script. My parameter text files are simple lists with one parameter per line. The loadParameters function reads the whole file into a single string using File.openAsString and then splits the string into an array using the split macro function and the new line character (\n) as deliminator. The individual elements of the array can then be assigned to the required variables. Hope this helps, Volko function loadParameters(){ macroDir=getDirectory("macros"); if(File.exists(macroDir+"Analysis Tool Parameters.txt")){ parameters = File.openAsString(macroDir+"Analysis Tool Parameters.txt"); parLines=split(parameters,"\n"); scale=parseFloat(parLines[0]); rollingBallRadius=parseInt(parLines[1]); labelBlue=parLines[2]; labelGreen=parLines[3]; labelRed=parLines[4]; minSize=parseFloat(parLines[5]); maxSize=parseFloat(parLines[6]); hoechstThreshold=parseInt(parLines[7]); zoomPercentage=parseInt(parLines[8]); cellSize=parseInt(parLines[9]); connectDistance=parseInt(parLines[10]); drawTrace=parseInt(parLines[11]); punctaThreshold=parseInt(parLines[12]); sizeLimitLower=parseFloat(parLines[13]); sizeLimitUpper=parseFloat(parLines[14]); }; }; function saveParameters(){ macroDir=getDirectory("macros"); parFile = File.open(macroDir+"Analysis Tool Parameters.txt"); // display file open dialog print(parFile, scale); print(parFile, rollingBallRadius); print(parFile, labelBlue); print(parFile, labelGreen); print(parFile, labelRed); print(parFile, minSize); print(parFile, maxSize); print(parFile, hoechstThreshold); print(parFile, zoomPercentage); print(parFile, cellSize); print(parFile, connectDistance); print(parFile, drawTrace); print(parFile, punctaThreshold); print(parFile, sizeLimitLower); print(parFile, sizeLimitUpper); File.close(parFile); }; -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of MChapman Sent: 08 December 2016 15:30 To: [hidden email] Subject: importing parameters from text file Hey guys, I have a series of image processing codes that I have written, some in ImageJ Macro form and some in python for various reasons, and I am trying pass the results from one to the other (flatfielding, stitching, aligning, etc until I have about 5 ijm and 5 py codes. What I am looking to do is pass the results of the python code into the macro and have it automatically run and then the python script realize when the macro completed. The only way that I can see this working is to have the python script create a .txt file with the parameters that need to be passed to the macro and then to run the macro by calling it from the command line through python. The only step in this process that I cannot figure out is reading in the variables from a text file. I would like to be able to have it in the format of "variable_name=###\n" but I cannot find any reference as to how to read that in. Any advice would be greatly appreciated. Mike -- View this message in context: http://imagej.1557.x6.nabble.com/importing-parameters-from-text-file-tp5017721.html Sent from the ImageJ mailing list archive at Nabble.com. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |