// ROI_Color_Coder.ijm // // This macro colorizes ROIs listed in the Manager by matching ROI measurements to an index // of a LUT file. It can be used, e.g., to obtain a particle-size 'heat-map' of segmented // objects. It will terminate if the LUT file cannot be read. // // 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) Edit your preferred LUT and save it as 'rmanager[...].lut' in the ImageJ/luts directory // to have it loaded by default; // 3) Use the 'glasbey' lookup table to label ROIs randomly or ramp LUTs ('001-fire','002-spectrum', // 'hue', etc.) to obtain heat-map codes; // glasbey LUT: http://rsb.info.nih.gov/ij/download/luts/glasbey.lut // heat-map LUTs (and several others): http://rsb.info.nih.gov/ij/download/luts/luts.zip // 4) If the Results table has more rows then the number of items in the ROI Manager list, the macro // will ignore the extra rows // // tf, 2009.11.26 //revised: 2009.12.01: Fixed labels misalignment in legend // For a demo, make sure you have at least one tab-delimited text LUT file in your ImageJ/luts folder // and run the three lines below // run("Blobs (25K)"); // setAutoThreshold; // run("Analyze Particles...", "display clear add") macro "ROI Color Coder" { requires("1.43j"); if(nImages==0 || nResults==0 || nResults257) verboseExit("Error reading "+path, "Reason: Found unexpected number of columns"); hexColor = newArray(256); firstStrg = substring(rgbColor[0], 0, 1); if (isNaN(firstStrg)) k = 1; // the lut file has a header (Index Red Green Blue) else k = 0; // there is no header. First row is index 0 for(i=k; i<256; i++) { hex = rgbToHex(rgbColor[i]); hexColor[i] = hex; } return hexColor; } function rgbToHex(color) { color1 = split(color,"\t"); if(color1.length==1) color1 = split(color," "); if(color1.length==1) verboseExit("Chosen LUT does not seem to be either a tab-delimited", "or a space-delimited text file"); if(color1.length==4) i = 1; // first column of the lut file is the index number else i = 0; // first column of the lut file is the red value r = color1[0+i]; g = color1[1+i]; b = color1[2+i]; return ""+toHex(r)+""+toHex(g)+""+toHex(b); } function toHex(n) { n = parseInt(n); if(n==0 || isNaN(n)) return "00"; n = maxOf(0,n); n = minOf(n,255); n = round(n); hex = ""+substring("0123456789ABCDEF",((n-n%16)/16),((n-n%16)/16)+1)+ substring("0123456789ABCDEF",(n%16),(n%16)+1); return hex; } function verboseExit(line1, line2) { msg = line1+"\n"+ line2+"\n \n"+ "ROI Color Coder screens all the LUT files in the '/ImageJ/luts/' folder selecting\n"+ "those saved as tab-delimited text files. A chosen LUT is then used to colorize\n"+ "ROIs in the Manager, by matching LUT indexes to measurements in the Results\n"+ "table. It is a complement to the 'Analyze>Analyze Particles...' command.\n \n"+ " - Several tab-delimited lookup tables can be obtained from the IJ web site:\n"+ " - http://rsb.info.nih.gov/ij/download/luts/luts.zip\n \n"+ " - Customize your own tab-delimited LUT file using several plugins, e.g.:\n"+ " - LUT Lister (http://rsbweb.nih.gov/ij/plugins/lut-lister.html)\n"+ " - LUT Panel (http://rsbweb.nih.gov/ij/plugins/lut-panel.html)"; exit(msg); }