// F-ReadIni.js reads N-STORM ini files // 15-07-16 importClass(Packages.java.io.File); importClass(Packages.ij.IJ); /* Function to read Warp database form an N-STORM ini file Example of Warp DB from an ini file: [XY Warps] WarpDB=Obj:[0, "Apo TIRF 100x Oil DIC N2"] Rep:[0, "561.000000"][1, "488.000000"][2, "647.000000"] Warps:[32, "XPWarp=[Order=3, Vars=2, Coeff=[-0.16180073413488572, 1.00190553951753, -0.000024473899625566, 0.000000077197503156, 0.001283779838445298, 0.000031988349733281, -0.000000077240121384, -0.000035279069060756, -0.000000059381910668, 0.000000133561090611]], YPWarp=[Order=3, Vars=2, Coeff=[-0.10320769829377241, 0.00087019093269447, 0.00001111427530387, -0.000000061187987889, 0.9994623985370481, -0.000036096022038912, 0.000000105165065883, 0.000027768162811803, 0.000000049386136027, -0.000000097484211519]]"] [256, "XPWarp=[Order=3, Vars=2, Coeff=[0.044936698366655037, 0.99861001370829428, -0.000003197677888034, 0.000000021567474126, -0.001287855516295622, 0.000010515117401355, -0.000000035440992241, 0.000003180358023158, 0.000000004744538575, -0.000000004820559819]], YPWarp=[Order=3, Vars=2, Coeff=[0.071432406581152463, 0.000392393067009778, -0.0000024440961095, 0.0000000054655798, 0.99951397072925374, -0.000002713106987406, -0.000000001694454978, -0.000001294414644804, 0.000000010113447004, 0.00000000519206721]]"] [288, "XPWarp=[Order=3, Vars=2, Coeff=[-0.088768005089150392, 1.0000469135523709, -0.000005913170118999, 0.000000016210187136, -0.001629541731688278, 0.000005083851283505, -0.000000012193974019, 0.000006205028235673, 0.00000000396347566, -0.000000009388471915]], YPWarp=[Order=3, Vars=2, Coeff=[-0.043155886625754647, 0.001342709180178758, -0.00000706405596973, 0.000000007039697175, 1.0001687650340045, -0.000006428580618723, 0.000000019728559786, -0.000004393759374111, 0.000000006842611257, 0.000000020690555018]]"] [4128, "XPWarp=[Order=3, Vars=2, Coeff=[-0.016165051843927358, 1.0000278195175021, -0.000006949128623868, 0.000000021859502388, -0.001308301165579451, 0.000017405359866024, -0.000000022239322315, 0.00000131201232012, -0.000000029408739951, 0.000000003000780983]], YPWarp=[Order=3, Vars=2, Coeff=[-0.01953889503784012, 0.001892857365177747, -0.000016233622519291, 0.000000035657430211, 0.99896720275148709, -0.000001137116393046, 0.000000017283480794, 0.00000435926562492, -0.00000001561201567, 0.000000000442773752]]"] [4352, "XPWarp=[Order=3, Vars=2, Coeff=[-0.10077294873917708, 1.0008267153009101, -0.000014402517801826, 0.000000037257780396, 0.001868105357687, -0.00001698576413256, 0.000000010483367484, -0.000008131138425682, 0.00000005793694282, 0.000000004605118257]], YPWarp=[Order=3, Vars=2, Coeff=[0.1229695434376481, -0.00119265041634975, 0.00000494295955733, -0.000000004245713324, 1.0003578127293622, 0.000003754970118036, -0.000000013896138467, -0.000013039017829897, 0.000000010381610921, 0.000000025282131701]]"] [4384, "XPWarp=[Order=3, Vars=2, Coeff=[-0.14558318237504864, 1.0032561888619895, -0.000038057673290848, 0.000000089901761074, -0.001125176316008947, -0.000010919533101356, 0.000000046398379228, 0.000016038704762522, 0.000000008873964383, -0.000000054254080156]], YPWarp=[Order=3, Vars=2, Coeff=[0.12640296466997825, 0.000194874924957844, -0.000007523554439226, 0.000000022912716252, 0.99893777575891818, 0.000005118139802553, -0.000000001669738523, -0.000007044516757482, -0.000000010281811364, 0.000000024748796779]]"] ZCalOffsets:[4128, "20.000000"][4352, "-70.000000"][4384, "-50.000000"] Warps are always longer WL to shorter WL ie 647 -› 488 for example "Source WL" is the WL corresponding to the image that will be transformed (647) "Destination WL" is the target WL to which the source WL image will be warped (488) source coordinates (x,y) destination coordinates (u,v) xWarps u = a0*x3 + a1*x2y + a2*xy2 + a3*y3 + a4*x2 + a5*xy + a6*y2 + a7*x + a8*y + a9 yWarps v = b0*x3 + b1*x2y + b2*xy2 + b3*y3 + b4*x2 + b5*xy + b6*y2 + b7*x + b8*y + b9 */ function readIniWarp(path) { // Open ini file var iniString = IJ.openAsString(path); // isolate Warp DB string var startI = iniString.indexOf("WarpDB=Obj:"); var stopI = iniString.indexOf("[General]"); var warpDB = iniString.substring(startI, stopI); // IJ.log(warpDB); // Generate arrays for objectives, source and destination WL, warps, Zshifts var objArray = getObj(warpDB); var repArray = getRep(warpDB); var warpArray = getWarps(warpDB); var zShiftArray = getZShifts(warpDB); return [objArray, repArray, warpArray, zShiftArray]; } // Get objectives (from 'Obj:' string) // returns an array of strings function getObj(ws) { var oaf = new Array; var startI = ws.indexOf("WarpDB=Obj:") + 12; var stopI = ws.indexOf("Rep:[") - 2; var os = ws.substring(startI, stopI); //IJ.log(os); // split each entry of DB (beware of escape characters) var oi = os.split("\\]\\["); for (var i = 0; i < oi.length; i++) { na = oi[i].split(","); naa = na[1].split("\""); oaf[i] = naa[1]; //IJ.log("stored " + oaf[i]); } return oaf; } // Get reporter wavelengths (from 'Rep:' string) // returns an array of ints function getRep(ws) { var raf = new Array; var startI = ws.indexOf("Rep:[") + 5; var stopI = ws.indexOf("Warps:[") - 2; var rs = ws.substring(startI, stopI); //IJ.log(rs); var ri = rs.split("\]\["); for (var i = 0; i < ri.length; i++) { var nr = ri[i].split(","); var wl = nr[1].split("\""); raf[i] = parseInt(wl[1]); //IJ.log("stored " + raf[i]); } return raf; } /* Get Warp coefficients (from 'Warps:' string) returns an array of 'warps' 'warps' contain three components [0] is the warp ID 32 bit int (decimal format ie 4128 etc) [1] is the x coefficients array (10 float coefficients a0-a9) [2] is the y coefficients array (10 float coefficients b0-b9) */ function getWarps(ws) { var ca = new Array; // isolate Warp parts of the Warp DB string var startI = ws.indexOf("Warps:[") + 7; var stopI = ws.indexOf("ZCalOffsets:[") - 2; var cs = ws.substring(startI, stopI); // IJ.log(cs); // split each entry of DB (beware of escape characters) var ci = cs.split("\]\["); //IJ.log(ci.lenght); // loop on all warps for (var i = 0; i < ci.length; i++) { currWarp = ci[i]; // first DB entry is the warp ID (32 bits int) iWarp = parseInt(currWarp.substring(0, currWarp.indexOf(","))); // isolate xWarp coefficients var startI = currWarp.indexOf("XPWarp=[") + 8; var stopI = currWarp.indexOf("YPWarp=[") - 3; var bigxWarp = currWarp.substring(startI, stopI); //IJ.log(bigxWarp); var xWarp = bigxWarp.substring(bigxWarp.indexOf("Coeff=[") + 7, bigxWarp.length()); //IJ.log(xWarp) var xWarps = xWarp.split(","); var xWarpa = new Array; for (var j = 0 ; j < xWarps.length; j++) { xWarpa[j] = parseFloat(xWarps[j]); //IJ.log(xWarpa[j]); } // isolate yWarp coefficients var startI = currWarp.indexOf("YPWarp=[") + 8; var bigyWarp = currWarp.substring(startI, currWarp.length()); var yWarp = bigyWarp.substring(bigyWarp.indexOf("Coeff=[") + 7, bigyWarp.length()); var yWarps = yWarp.split(","); var yWarpa = new Array; for (var j = 0 ; j < yWarps.length; j++) { yWarpa[j] = parseFloat(yWarps[j]); } // make warp and assign it to the return array ca[i] = new Array; ca[i][0] = iWarp; //IJ.log(iWarp); ca[i][1] = xWarpa; ca[i][2] = yWarpa; } return ca; } // Get Z shifts (end of Warps DB) // output an array of Zshifts : [0] is Zshift ID, [1] is shift in nm function getZShifts(ws) { var za = new Array; var startI = ws.indexOf("ZCalOffsets:[") + 13; var stopI = ws.length() - 2; var rs = ws.substring(startI, stopI); // IJ.log(rs); var ri = rs.split("\\]\\["); for (var i = 0; i < ri.length; i++) { var nr = ri[i].split(","); za[i] = new Array; za[i][0] = parseInt(nr[0]); var sh = nr[1].split("\""); za[i][1] = parseFloat(sh[1]); // IJ.log(za[i][0]); // IJ.log(za[i][1]); } return za; }