/* This file is part of FLEYE a package of ImageJ macros developed to classify fly eyes attending to their degeneration level Copyright (C) 2014 Cristina Rueda Sabater, Sergio Díez Hermano, Diego Sánchez Romero, María Dolores Ganfornina Álvarez and Jorge Valero Gómez-Lobo. FLEYE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. FLEYE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ //This macro has been developed by Dr Jorge Valero (jorge.valero@cnc.uc.pt). //If you have any doubt about how to use it, please contact me. //License Dialog.create("GNU GPL License"); Dialog.addMessage("FLEYE Copyright (C) 2014 Cristina Rueda Sabater, Sergio Diez Hermano, Diego Sanchez Romero, Maria Dolores Ganfornina Alvarez and Jorge Valero Gomez-Lobo."); Dialog.setInsets(10, 20, 0); Dialog.addMessage("FLEYE comes with ABSOLUTELY NO WARRANTY; click on help button for details."); Dialog.setInsets(0, 20, 0); Dialog.addMessage("This is free software, and you are welcome to redistribute it under certain conditions; click on help button for details."); Dialog.addHelp("http://www.gnu.org/licenses/gpl.html"); Dialog.show(); //scale normalization scaleUser=getNumber("What's the size (in microns) of a pixel in your images?", 1.85); scalecorr=1.85/scaleUser; // parameters of the model var indep=newArray(84.3666, 60.0043, 29.0704, 1.2994); var DISTMED=newArray(-13.6811, -11.0979, -4.4487, 0.2421); var DISTSKEW=newArray(20.3917, 15.0051, 7.6631, -17.7463); var LOGNNVAR=newArray(-17.3201, -6.9768, -3.3085, -0.1040); var NOPOINTS=0; //table handling variable var infovar=0; //Initial dialog Dialog.create("OPTIONS"); Dialog.addCheckbox("\tPRE-OPTIMIZED PARAMETERS", true); Dialog.setInsets(-6, 40, 0); Dialog.addMessage("(Remember!!! Predefined parameters are assumed to be CALIBRATED)"); Dialog.setInsets(0, 50, 0); Dialog.addCheckbox("All parameter files", true); Dialog.setInsets(5, 120, 0); Dialog.addMessage("NUMBER OF GROUPS TO ANALYSE"); Dialog.setInsets(0, -100, 0); Dialog.addNumber("", 1); Dialog.setInsets(-6, 100, 0); Dialog.addMessage("(Images from groups should be separated in different folders)"); Dialog.setInsets(20, 0, 0); Dialog.addNumber ("Define number of intervals for Frequency histograms", 200); Dialog.show(); prepar=Dialog.getCheckbox; optionprepar=Dialog.getCheckbox; groups=Dialog.getNumber(); intervals=Dialog.getNumber(); //Groups definition dialog Dialog.create("Groups definition"); for (i=1; i<=groups; i++) Dialog.addString("Group "+i+":", "group"+i, 25); Dialog.show(); groupname=newArray(groups); dirgroup=newArray(groups); dirRoi=newArray(groups); for (i=0; i0){ selectWindow(name+" Maxima"); run("Specify...", "width="+GridWith+" height="+GridWith+" x="+xn+" y="+yn+" slice=1"); roiManager("Add"); roiManager("Show All without labels"); roiManager("Show None"); } run("Select None"); } } //This function creates images for grid generation function TestGrids(){ run("Select None"); run("Duplicate...", "title=[TestGrid Line]"); run("Duplicate...", "title=[TestGrid Filled]"); selectWindow("TestGrid Line"); roiManager("Select",0); setBackgroundColor(0, 0, 0); run("Clear"); setForegroundColor(255, 255, 255); run("Line Width...", "line=1"); run("Draw"); run("Select None"); selectWindow("TestGrid Filled"); roiManager("Select",0); run("Enlarge...", "enlarge=-1"); setBackgroundColor(255, 255, 255); run("Clear"); run("Select None"); } //This function obtains data from the grid function GridResults(){ run("Set Measurements...", "area centroid center skewness kurtosis area_fraction redirect=None decimal=4"); setThreshold(1,255); roiselect(); roiManager("Measure"); } //function to select single grid cells function roiselect(){ roiManager("Deselect"); rois=roiManager("count"); rois=rois-1; roiselection=newArray(rois); for (i=0; i0) { dist=sqrt((pow(getResult("X", i)-getResult("XM", i), 2))+((pow(getResult("Y", i)-getResult("YM", i), 2)))); sumDist=sumDist+dist; ndist++; } //skew=getResult("Skew", i); //if (isNaN(skew)==false){ //sumSkew=sumSkew+skew; //nSkew++; //} //kurt=getResult("Kurt", i); //if (isNaN(kurt)==false){ //sumKurt=sumKurt+kurt; //nKurt++; //} } //PorCelMinor2=(PorCelMinor2/nResults)*100; //PorCelMinor4=(PorCelMinor4/nResults)*100; //PorCelMinor6=(PorCelMinor6/nResults)*100; //PorCelMinor8=(PorCelMinor8/nResults)*100; meanPoints=sumPoints/nResults; meanDist=sumDist/ndist; //meanSkew=sumSkew/nSkew; //meanKurt=sumKurt/nKurt; squsumDist=0; cubsumDist=0; for (i=0; i0) { dist=sqrt((pow(getResult("X", i)-getResult("XM", i), 2))+((pow(getResult("Y", i)-getResult("YM", i), 2)))); squsumDist=pow((dist-meanDist),2)+squsumDist; cubsumDist=pow((dist-meanDist),3)+cubsumDist; } //skew=getResult("Skew", i); //if (isNaN(skew)==false){ //squsumSkew=pow((skew-meanSkew),2)+squsumSkew; //cubsumSkew=pow((skew-meanSkew),3)+cubsumSkew; //} //kurt=getResult("Kurt", i); //if (isNaN(kurt)==false){ //squsumKurt=pow((kurt-meanKurt),2)+squsumKurt; //cubsumKurt=pow((kurt-meanKurt),3)+cubsumKurt; //} } //variancePoints=squsumPoints/nResults; //StdDvPoints=sqrt(variancePoints); //SkewPoints=(cubsumPoints/nResults)/pow(StdDvPoints,3); varianceDist=squsumDist/ndist; StdDvDist=sqrt(varianceDist); SkewDist=(cubsumDist/ndist)/pow(StdDvDist,3); //varianceSkew=squsumSkew/nSkew; //StdDvSkew=sqrt(varianceSkew); //SkewSkew=(cubsumSkew/nSkew)/pow(StdDvSkew,3); //varianceKurt=squsumKurt/nKurt; //StdDvKurt=sqrt(varianceKurt); //SkewKurt=(cubsumKurt/nKurt)/pow(StdDvKurt,3); //tablearray=newArray(date, time, name, nResults, meanPoints, StdDvPoints, variancePoints, SkewPoints); //tableprinter("Points per Cell", tablearray); tablearray=newArray(date, time, name, ndist, meanDist, StdDvDist, varianceDist, SkewDist); tableprinter(""+groupname[arr]+"_Distance to the center of mass", tablearray); //tablearray=newArray(date, time, name, nSkew, meanSkew, StdDvSkew, varianceSkew, SkewSkew); //tableprinter("Skewness", tablearray); //tablearray=newArray(date, time, name, nKurt, meanKurt, StdDvKurt, varianceKurt, SkewKurt); //tableprinter("Kurtosis", tablearray); //tablearray=newArray(date, time, name, nResults, PorCelMinor2, PorCelMinor4, PorCelMinor6, PorCelMinor8); //tableprinter("Cells percentages", tablearray); model(); } //this function all close windows, except table ones function resetall(){ selectWindow(name); close(); selectWindow(name+" Maxima"); close(); list = getList("window.titles"); for (i=0; i=minI && value0.9375) Plot.setColor("#00FF00"); if (xmax<=0.9375 && xmax>0.7188) Plot.setColor("#008000"); if (xmax<=0.7188 && xmax>0.5) Plot.setColor("#ADFF2F"); if (xmax<=0.5 && xmax>0.2812) Plot.setColor("#FFFF00"); if (xmax<=0.2812 && xmax>0.0625) Plot.setColor("#FFA500"); if (xmax<=0.0625) Plot.setColor("#FF0000"); for (i=index; i>=0; i=i-0.001) Plot.add("line", newArray(xmin,xmax), newArray(i,i)); } Plot.show; } //Old Graphs generation (for degeneration probability, not used) function bargraph(indexname, col, mincol, minmed, maxmed, maxcol){ Plot.create(indexname, "EYE", indexname+" index"); Plot.setFrameSize(500+limit, 300); Plot.setLimits(0, limit, -0.1, 1.1); //Plot.setLineWidth(2); for (n=1; n0.75) Plot.setColor(maxcol); if (index<=0.75 && index>0.5) Plot.setColor(maxmed); if (index<=0.5 && index>0.25) Plot.setColor(minmed); if (index<=0.25) Plot.setColor(mincol); xmin=n-0.25; xmax=n+0.25; for (i=index; i>0; i=i-0.001) Plot.add("line", newArray(xmin,xmax), newArray(i,i)); } Plot.show; } //Accumulated probability graphs generation function bargraph2(prefijo, group){ Plot.create(prefijo+"_Accumulated probability", group, "PP index"); Plot.setFrameSize(400+limit, 300); Plot.setLimits(0, limit+1, -0.1, 1.1 ); for (n=1; n0; i=i-0.001) Plot.add("line", newArray(xmin,xmax), newArray(i,i)); infoTab(""+prefijo+"_Classification", n, 6); index1=index+parseFloat(infovar); Plot.setColor("blue"); setJustification("left"); Plot.addText("PP1",0.9, 0.40); for (i=index1; i>index; i=i-0.001) Plot.add("line", newArray(xmin,xmax), newArray(i,i)); infoTab(""+prefijo+"_Classification", n, 7); index2=index1+parseFloat(infovar); Plot.setColor("yellow"); setJustification("left"); Plot.addText("PP2",0.9, 0.50); for (i=index2; i>index1; i=i-0.001) Plot.add("line", newArray(xmin,xmax), newArray(i,i)); infoTab(""+prefijo+"_Classification", n, 8); index3=index2+parseFloat(infovar); Plot.setColor("orange"); setJustification("left"); Plot.addText("PP3",0.9, 0.60); for (i=index3; i>index2; i=i-0.001) Plot.add("line", newArray(xmin,xmax), newArray(i,i)); infoTab(""+prefijo+"_Classification", n, 9); index4=index3+parseFloat(infovar); Plot.setColor("red"); setJustification("left"); Plot.addText("PP4",0.9, 0.70); for (i=index4; i>index3; i=i-0.001) Plot.add("line", newArray(xmin,xmax), newArray(i,i)); } Plot.show; } //create and save mean tables function meantables(){ tablesmean("Mean"); for(i=0; i1){ coltable=split(linetable[1], "\t"); means=newArray(coltable.length); infoTab(""+groupname[i]+""+tabname, 1, 0); means[0]=infovar; infoTab(""+groupname[i]+""+tabname, 1, 1); means[1]=infovar; means[2]=groupname[i]; for(c=3; c