Project

General

Profile

Files » MRI_Artemia_Tools.txt

Volker Baecker, 07/04/2013 03:09 PM

 
/**
* MRI Artemia Tools
*
* The Artemia Tools help to calculate the normalized redness of Artemia in images
*
* written 2011-2013 by Volker Baecker (INSERM) at Montpellier RIO Imaging (www.mri.cnrs.fr)
* in collaboration with Nicolas Rode and Eva Lievens
*
*/

var helpURL = "http://dev.mri.cnrs.fr/projects/imagej-macros/wiki/Artemia_Tools"
macro "Unused Tool - C037" { }

macro "MRI Artemia Tools Action Tool - C762D3eD5bD68D69D6aD6eCcc9D29D3aD3bD56D8aD8bD95Dc3Dd2Cbb7D4aD4bD79D7aD87D88CcdaD1aD65D6fD9bDa3Db2Db4Cba4D59D5aD5cD67D6bD78CccaD74D96Cbc8D57D7cD84D89D97Dc2CcdbD7eD83D8dD93D9cDa6Caa5D4dD4eD5dD75D76D77D85Ccc9D2aD2bD38D8cD9aDa7Da8Da9Cbb8D3dD49D66D6dD86D98D99CcdbD19D1bD28D2cD37Da5Dd0De0De1Cbb7D4cD58D5eD6cD7bD94Db3CcdaD46D47D7dDaaDc1Ccc9D39D3cD48Da4Dd1" {
run('URL...', 'url='+helpURL);
}

macro "01 artemia prepare Action Tool - C037T4d14p" {
prepare();
}

macro "02 artemia measure Action Tool - C037T4d14m" {
measure();
}

macro "03 artemia next image Action Tool - C037T4d14n" {
nextImage();
}

macro "04 artemia calculate redness Action Tool - C037T4d14c"{
calculateRedness();
}

function prepare() {
run("Conversions...", "scale");
run("Set Measurements...", "mean display redirect=None decimal=3");
run("RGB Stack");
setSlice(3);
setAutoThreshold("Default dark");
setAutoThreshold("Default");
run("Threshold...");
}

function measure() {
// measure red composant in individuals
resetThreshold();
roiManager("Deselect");
roiManager("XOR");
setSelectionName("xor")
roiManager("Add");
roiManager("Select", 0);
roiManager("Delete");
roiManager("Select", 0);
roiManager("Delete");
run("Select None");
setSlice(1);
roiManager("Measure");
setSlice(2);
roiManager("Measure");
setSlice(3);
roiManager("Measure");
roiManager("Delete");
}

function nextImage() {
// step 3 - next image
setOption("Changes", false);
run("Open Next");
}

function calculateRedness() {
// STEP 4 - calculate redness
// ask for normalization area
// calculate R/(R+G+B)

waitForUser("Please select the normalization area");
setSelectionName("control");
roiManager("Add");

rednessValues = newArray(nResults / 3);
labels = newArray(nResults / 3);
for (i=0; i<nResults; i=i+3) {
red = getResult("Mean", i);
green = getResult("Mean", i+1);
blue = getResult("Mean", i+2);
rednessValues[i/3] = red / (red + green + blue);
aLabel = getResultLabel(i);
parts = split(aLabel, ":");
labels[i/3] = parts[0];
}

setSlice(1);
roiManager("Measure");
setSlice(2);
roiManager("Measure");
setSlice(3);
roiManager("Measure");
roiManager("Delete");
redControl = getResult("Mean", nResults-3);
greenControl = getResult("Mean", nResults-2);
blueControl = getResult("Mean", nResults-1);
rednessMax = redControl / (redControl + greenControl + blueControl);
IJ.deleteRows(nResults-3, nResults-1);

windowTitles = getList("window.titles");
isRednessTableOpen = false;
for (i=0; i < windowTitles.length; i++) {
if (windowTitles[i]=="redness-measurements") isRednessTableOpen = true;
}


if (!isRednessTableOpen) {
run("Table...", "name=redness-measurements width=550 height=250");
print("[redness-measurements]", "\\Headings:n\tLabel\tredness raw\tredness norm\tredness max");
index = 1;
} else {
selectWindow("redness-measurements");
info = split(getInfo("window.contents"), "\n");
index = lengthOf(info);
}

numberOfLabels = lengthOf(labels);
for(i=0; i<lengthOf(rednessValues); i++) {
if (labels[i]==labels[numberOfLabels-1]) {
line = "" + index + "\t" + labels[i] + "\t" + d2s(rednessValues[i], 4) + "\t" + d2s((rednessValues[i] / rednessMax),4) + "\t" + d2s(rednessMax,4);
print("[redness-measurements]", line);
index++;
}
}
}
(1-1/2)