/* ROI_Color_Coder.ijm This macro colorizes ROIs listed in the Manager by matching ROI measurements to an index of a lookup table (LUT). It can be used, e.g., to obtain a particle-size 'heat-map' of segmented objects. More info at http://imagejdocu.tudor.lu/doku.php?id=macro:roi_color_coder N.B.: 1) Save this file in the plugins directory and it will be available in the Plugins Menu; 2) Rename your preferred LUT in the ImageJ/luts directory with a 'rmanager' prefix (e.g. 'rmanager-Fire.lut') and it will loaded by default; 3) Check "Edit Mode" in the ROI Manager to toggle particle labeling; 4) Several 'heat-map' LUTs can be download at ; 5) The'glasbey' lookup table can be used to label ROIs randomly Tiago Ferreira, Dec 2010 2010.12.06 v.4 Added: Accepts all LUT files recognized by ImageJ. Faster Fixed: Does not abort when files w/o extension exist in the luts directory 2009.12.14 v.3 Added: Options: transparency, contours width, ROI filling Added: Results table is clearead and ROIs (re)measured when needed 2009.12.01 v.2 Fixed: Labels misalignment in legend */ // For a demo run the following line: // run("Blobs (25K)"); setAutoThreshold; run("Analyze Particles...", "display clear add"); macro "ROI Color Coder" { requires("1.44e"); mCount= roiManager("count"); rCount= nResults; resetRes= true; if (nImages==0 || mCount==0) verboseExit("Macro aborted: No images open and/or the ROI Manager is empty."); msg= ""+ mCount +" ROI(s) in Manager and "+ rCount + " Row(s) in the Results Table"; if (mCount>rCount) msg= msg+":\nPrevious measurements will be cleared and ROIs (re)measured..."; else if (mCount0) roiManager("Set Color", alpha+roiColors[lutIndex]); else roiManager("Set Fill Color", alpha+roiColors[lutIndex]); } Overlay.show; // roiManager("Show All"); // finish setBatchMode("exit & display"); call("java.lang.System.gc"); showStatus("ROI Color Coder... Finished: "+ d2s((getTime-start)/1000,3) +" seconds"); if (countNaN!=0) showMessage("Some "+ parameter +" values could not be retrieved.\n"+ countNaN+" ROI(s) labeled with default color."); } function getLutList() { lutdir = getDirectory("luts"); if (!File.exists(lutdir)) verboseExit("Macro aborted: The \"ImageJ/luts/\" directory does not exist."); rawlist= getFileList(lutdir); count= 0; for (i=0; i< rawlist.length; i++) if (endsWith(rawlist[i], ".lut")) count++; if (count==0) verboseExit("Macro aborted: The \"ImageJ/luts/\" directory contains no LUTs."); list= newArray(count); index= 0; def= -1; for (i=0; i< rawlist.length; i++) { if (endsWith(rawlist[i], ".lut")) { lutnm= substring(rawlist[i], 0, lengthOf(rawlist[i])-4); if (startsWith(lutnm, "rmanager")) def= index; list[index++]= lutnm; } } if(def!=-1) { // a "rmanager lut" was found. Make it the 1st item in list old1st= list[0]; new1st= list[def]; list[def]= old1st; Array.sort(list); list[0]= new1st; } showStatus("ROI Color Coder: "+ count +" LUT files available"); return list; } function getMeasurements() { // image will be measured. Parameters could just be defined manually List.setMeasurements; list= split(List.getList, "\n"); nList= list.length; Array.sort(list); parameters= newArray(nList+1); for (i=0; i