/* ROI_Color_Coder.ijm http://imagejdocu.tudor.lu/doku.php?id=macro:roi_color_coder Colorizes ROIs by matching LUT indexes to measurements in the Results table. It is complementary to the ParticleAnalyzer (Analyze>Analyze Particles...), generating particle-size heat maps. Requires IJ 1.46h. Tiago Ferreira, v.5 2012.03.01 */ // For a demo run the following line: // run("Blobs (25K)"); setThreshold(126, 255); run("Analyze Particles...", "display clear add"); resetThreshold; setBatchMode(true); nROIs= roiManager("count"); nRES= nResults; // assess conditions to proceed requires("1.46h"); if (nImages==0 || nROIs==0) exit("No images open or the ROI Manager is empty..."); if (nRES==0) { roiManager('Deselect'); roiManager('Measure'); nRES= nResults; } // create the dialog prompt Dialog.create("ROI Color Coder: "+ getTitle); headings= split(String.getResultsHeadings); Dialog.addChoice("Measurement:", headings, "Area"); luts= getLutList(); Dialog.addChoice("LUT:", luts, luts[1]); Dialog.setInsets(12, 0, 0); Dialog.addMessage("Contours:"); Dialog.addNumber("Width:", 0, 0, 4, "pixels (0 to fill ROIs)"); Dialog.addSlider("Opacity (%):", 0, 100, 80); Dialog.setInsets(12, 0, 0); Dialog.addMessage("Legend:"); getPixelSize(unit, null, null); Dialog.addString("Label:", unit+"^2", 10); Dialog.addString("Range:", "Min-Max", 10); Dialog.setInsets(-35, 213, 0); Dialog.addMessage("(e.g., 10-100)"); Dialog.addNumber("N. of labels:", 5, 0, 3, "(Defines major ticks interval)"); Dialog.addNumber("Decimal places:", 0, 0, 3, "(Scientific notation if negative)"); Dialog.addChoice("Ramp size:", newArray("128 pixels", "256 pixels", "512 pixels"), "256 pixels"); Dialog.addChoice("Font:", newArray("Monospaced", "SansSerif", "Serif"), "SansSerif"); Dialog.addNumber("Font_size:", 14, 0, 3, "pt"); Dialog.setInsets(-25, 200, 0); Dialog.addCheckbox("Draw tick marks", true); if (nROIs!=nRES) Dialog.addMessage(nROIs +" ROI(s) in Manager, "+ nRES +" rows in Results table:\n"+ abs(nROIs-nRES) +" item(s) will be ignored..."); Dialog.addHelp("http://imagejdocu.tudor.lu/doku.php?id=macro:roi_color_coder"); Dialog.show; parameter= Dialog.getChoice; lut= Dialog.getChoice; stroke= Dialog.getNumber; alpha= pad(toHex(255*Dialog.getNumber/100)); label= Dialog.getString; range= split(Dialog.getString, "-"); if (range.length==1) { min= NaN; max= parseFloat(range[0]); } else { min= parseFloat(range[0]); max= parseFloat(range[1]); } numLabels= Dialog.getNumber; decPlaces= Dialog.getNumber; rampH= parseFloat(Dialog.getChoice); font= Dialog.getChoice; fontS= Dialog.getNumber; ticks= Dialog.getCheckbox; // get id of image and number of ROIs to colorize id= getImageID; items= minOf(nROIs, nRES); // get values for chosen parameter values= newArray(items); for (i=0; i2) step /= (numLabels-1); for (i= 0; imax) lutIndex= 255; else lutIndex= round(values[i]*255/max); roiManager("select", i); if (stroke>0) { roiManager("Set Line Width", stroke); roiManager("Set Color", alpha+roiColors[lutIndex]); } else roiManager("Set Fill Color", alpha+roiColors[lutIndex]); } // finish roiManager("Show all"); if (countNaN!=0) print(" ---\nSome "+ parameter +" values could not be retrieved.\n" + countNaN +" ROI(s) labeled with default color.\n ---"); setBatchMode("exit & display"); call("java.lang.System.gc"); function getLutList() { luts= getFileList(getDirectory("luts")); for (i=0, count=0; i