Posted by
Sebastian Rhode-3 on
Apr 29, 2011; 8:07am
URL: http://imagej.273.s1.nabble.com/Plot-profiles-of-multiple-ROI-s-on-the-same-graph-with-color-coding-for-tp3684805.html
Hi,
I just saw the discussion about plotting multiple ROIs inside one plot. I
recently wrote a mcro for this. It only works with time lapse files which
have one color channel right now.
1) Open File and make sure it is a time lapse file
2) Open the ROI manger and draw up to 8 ROIs
3) start the macro and select the desired options (--> the Python only works
if you have pythonxy installed)
And here is the code:
Cheers, Sebi
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Author: Sebastian Rhode
// Date: 2011-04-26
version_number = 1.6;
// marco for plotting mutiple lines from up-to 8 ROIs inside one plot
// only works with time-lapse images
// does not work with image 5D format
// get title from active window
title_orig = getTitle();
selectWindow(title_orig);
imagedir = getInfo("image.directory")
imagefilename = getInfo("image.filename")
//print(imagedir);
print(imagedir + imagefilename);
// get dimension from original image
getDimensions(w,h,ch,sl,fr);
print("X :",w,"Y :",h,"CHANNELS :",ch,"SLICES :",sl,"FRAMES :",fr);
setBatchMode(true);
// create maximum & minmum intensity projetion
run("Z Project...", "start=1 stop="+toString(fr)+" projection=[Max
Intensity]");
getStatistics(areaMax, meanMax, minMax, maxMax);
selectWindow(title_orig);
run("Z Project...", "start=1 stop="+toString(fr)+" projection=[Min
Intensity]");
// determine the maximum pixel value to adjust the y-scaling of the plot
getStatistics(areaMin, meanMin, minMin, maxMin);
close();
Dialog.create("Multiple ROI Kinetics");
Dialog.addMessage("Version Number: " + toString(version_number,1));
Dialog.addNumber("Time per frame [ms]",1);
Dialog.addCheckbox("Plot Data Points", false);
Dialog.addNumber("Line Width for Lines",2);
Dialog.addNumber("Line Width for ROIs",2);
//Dialog.addCheckbox("Inculde Min & Max in result table", false);
Dialog.addCheckbox("Save Results as TXT-File", false);
Dialog.addCheckbox("Save Results as XLS-File", false);
Dialog.addCheckbox("Show Results in Python - MatPlotLib", false);
Dialog.show();
timeframe = Dialog.getNumber();
plotpoints = Dialog.getCheckbox();
lw_plot = Dialog.getNumber();
lw_roi = Dialog.getNumber();
//minmax = Dialog.getCheckbox();
savetxt = Dialog.getCheckbox();
savexls = Dialog.getCheckbox();
openmpl = Dialog.getCheckbox();
run("Set Measurements...", " mean display redirect=None decimal=3");
//if (minmax == true){
// run("Set Measurements...", " mean min display redirect=None
decimal=3");
// }
//else if (minmax == false){
// run("Set Measurements...", " mean display redirect=None
decimal=3");
// }
// specify plot dimensions
run("Profile Plot Options...", "width=600 height=400 minimum=0 maximum=0
draw");
numROI = roiManager("Count");
//print("NumROI : ",numROI);
if (numROI >= 9) {
showMessage("Error Message","Too many ROIs - only 8 are possible ...");
exit();
}
frames = newArray(fr);
roi1 = newArray(fr); // ROI number 1
roi2 = newArray(fr);
roi3 = newArray(fr);
roi4 = newArray(fr);
roi5 = newArray(fr);
roi6 = newArray(fr);
roi7 = newArray(fr);
roi8 = newArray(fr);
//lb =
newArray("Mean(ROI001)","Mean(ROI002)","Mean(ROI003)","Mean(ROI004)","Mean(ROI005)","Mean(ROI006)","Mean(ROI007)","Mean(ROI008)");
lb =
newArray("Mean1","Mean2","Mean3","Mean4","Mean5","Mean6","Mean7","Mean8");
// create color list for ROIs
List.set("1","red"); // color for ROI 1
List.set("2","green");
List.set("3","blue");
List.set("4","black");
List.set("5","magenta");
List.set("6","orange");
List.set("7","cyan");
List.set("8","yellow");
// adjust color properties for all ROIs
for (i=1; i<=numROI; i++) {
roiManager("Select", i-1);
colorvalue = List.get(toString(i));
roiManager("Set Color", colorvalue);
roiManager("Set Line Width", lw_roi);
}
roiManager("Deselect");
roiManager("MultiMeasure");
// create array containing the frame numbers
for (i=1; i<=fr; i++) {
frames[i-1] = i * timeframe;
//setResult("Time", i-1, i * timeframe);
setResult("Time", i-1, frames[i-1]);
}
//test = getResultLabel(3);
//print("Testlabel = :",test);
for (i=1; i<=fr; i++) {
if (numROI == 1) {
roi1[i-1] = getResult(lb[0],i-1);
}
if (numROI == 2) {
roi1[i-1] = getResult(lb[0],i-1);
roi2[i-1] = getResult(lb[1],i-1);
}
if (numROI == 3) {
roi1[i-1] = getResult(lb[0],i-1);
roi2[i-1] = getResult(lb[1],i-1);
roi3[i-1] = getResult(lb[2],i-1);
}
if (numROI == 4) {
roi1[i-1] = getResult(lb[0],i-1);
roi2[i-1] = getResult(lb[1],i-1);
roi3[i-1] = getResult(lb[2],i-1);
roi4[i-1] = getResult(lb[3],i-1);
}
if (numROI == 5) {
roi1[i-1] = getResult(lb[0],i-1);
roi2[i-1] = getResult(lb[1],i-1);
roi3[i-1] = getResult(lb[2],i-1);
roi4[i-1] = getResult(lb[3],i-1);
roi5[i-1] = getResult(lb[4],i-1);
}
if (numROI == 6) {
roi1[i-1] = getResult(lb[0],i-1);
roi2[i-1] = getResult(lb[1],i-1);
roi3[i-1] = getResult(lb[2],i-1);
roi4[i-1] = getResult(lb[3],i-1);
roi5[i-1] = getResult(lb[4],i-1);
roi6[i-1] = getResult(lb[5],i-1);
}
if (numROI == 7) {
roi1[i-1] = getResult(lb[0],i-1);
roi2[i-1] = getResult(lb[1],i-1);
roi3[i-1] = getResult(lb[2],i-1);
roi4[i-1] = getResult(lb[3],i-1);
roi5[i-1] = getResult(lb[4],i-1);
roi6[i-1] = getResult(lb[5],i-1);
roi7[i-1] = getResult(lb[6],i-1);
}
if (numROI == 8) {
roi1[i-1] = getResult(lb[0],i-1);
roi2[i-1] = getResult(lb[1],i-1);
roi3[i-1] = getResult(lb[2],i-1);
roi4[i-1] = getResult(lb[3],i-1);
roi5[i-1] = getResult(lb[4],i-1);
roi6[i-1] = getResult(lb[5],i-1);
roi7[i-1] = getResult(lb[6],i-1);
roi8[i-1] = getResult(lb[7],i-1);
}
}
// do the plots
Plot.create("Line Plot Test", "Frame Number / Time [ms]", "Mean Intensity
[cts]", frames, roi1);
Plot.setLimits(1, fr*timeframe*1.02, minMin*1.3, maxMax*0.7);
Plot.setLineWidth(lw_plot);
if (plotpoints == true) {
Plot.add("Circle", frames, roi1);
}
// ROI 2
if (numROI >= 2) {
Plot.setColor(List.get(toString(2)));
Plot.add("Line", frames, roi2);
if (plotpoints == true) {
Plot.add("Circle", frames, roi2);
}
}
// ROI 3
if (numROI >= 3) {
Plot.setColor(List.get(toString(3)));
Plot.add("Line", frames, roi3);
if (plotpoints == true) {
Plot.add("Circle", frames, roi3);
}
}
// ROI 4
if (numROI >= 4) {
Plot.setColor(List.get(toString(4)));
Plot.add("Line", frames, roi4);
if (plotpoints == true) {
Plot.add("Circle", frames, roi4);
}
}
// ROI 5
if (numROI >= 5) {
Plot.setColor(List.get(toString(5)));
Plot.add("Line", frames, roi5);
if (plotpoints == true) {
Plot.add("Circle", frames, roi5);
}
}
// ROI 6
if (numROI >= 6) {
Plot.setColor(List.get(toString(6)));
Plot.add("Line", frames, roi6);
if (plotpoints == true) {
Plot.add("Circle", frames, roi6);
}
}
// ROI 7
if (numROI >= 7) {
Plot.setColor(List.get(toString(7)));
Plot.add("Line", frames, roi7);
if (plotpoints == true) {
Plot.add("Circle", frames, roi7);
}
}
// ROI 8
if (numROI == 8) {
Plot.setColor(List.get(toString(8)));
Plot.add("Line", frames, roi8);
if (plotpoints == true) {
Plot.add("Circle", frames, roi8);
}
}
// ROI 1
Plot.setColor(List.get(toString(1)));
// display the plot
Plot.show();
setBatchMode(false);
if (savetxt == true) {
if (nResults==0) {
exit("Results table is empty");
}
else {
path = imagedir + imagefilename + "_Results.txt";
//print(path);
saveAs("Measurements", path);
}
}
if (savexls == true) {
// save contents of Results table in Excel
if (nResults==0) {
exit("Results table is empty");
}
else {
path = imagedir + imagefilename + "_Results.xls";
//print(path);
saveAs("Measurements", path);
//exec("cmd", "/c", "start", "excel.exe", "c:\\Results.xls");
}
}
if (openmpl == true) {
if (nResults==0) {
exit("Results table is empty");
}
else {
path = imagedir + imagefilename + "_Results.txt";
saveAs("Measurements", path);
exec("cmd", "/c","start", "python.exe", "c:/Dokumente und
Einstellungen/sebastian.rhode/Eigene
Dateien/Sebi/Projects_TILL/LA_Software/Online_Analysis/kinetics_FIJI.py",
"run");
}
}
--
Dr. Sebastian Rhode
Grünwalder Str. 103a
81547 München
Tel: +49 89 4703091
Mobil: +49 15122810945
[hidden email]