Skip to content

Instantly share code, notes, and snippets.

@Mikayex
Created December 12, 2014 11:00
Show Gist options
  • Save Mikayex/1c27751f397bec6c98ea to your computer and use it in GitHub Desktop.
Save Mikayex/1c27751f397bec6c98ea to your computer and use it in GitHub Desktop.
Macro ImageJ
function listOfImages() {
images=newArray(nImages+1);
for (i=1; i<=nImages; i++) {
selectImage(i);
images[i-1]=getTitle;
}
images[nImages]="Aucune";
return images;
}
function traitementImage(median, gamma, subBack, nomImg) {
run("Duplicate...", "title=Mask_"+nomImg);
run("Grays");
if (median>0) run("Median...", "radius="+median);
if (gamma>0) run("Gamma...", "value="+gamma);
if (subBack>0) run("Subtract Background...", "rolling="+subBack);
}
function creationMask(choixManuel) {
setAutoThreshold("Li dark");
if(choixManuel) {
run("Threshold...");
waitForUser("Régler le seuil\npuis cliquer sur OK");
}
run("Convert to Mask");
run("Fill Holes");
}
function segmentation() {
if(nImages<1) exit("Aucune image");
images=listOfImages();
Dialog.create("Segmentation");
Dialog.addChoice("Noyau", images, "Aucune");
Dialog.addChoice("Cyto", images, "Aucune");
Dialog.addChoice("Spots", images, "Aucune");
Dialog.addCheckbox("Seuillage manuel", false);
Dialog.show();
imNoyaux=Dialog.getChoice();
imCyto=Dialog.getChoice();
imSpots=Dialog.getChoice();
seuilManuel=Dialog.getCheckbox();
if (imNoyaux == "Aucune" && imCyto == "Aucune" && imSpots == "Aucune") exit("Aucune image sélectionnée !");
if (imNoyaux != "Aucune") {
selectWindow(imNoyaux);
traitementImage(5, 0, 0, "Noyaux");
creationMask(seuilManuel);
run("Watershed");
}
if (imCyto != "Aucune") {
selectWindow(imCyto);
traitementImage(8, 0, 0, "Cyto");
creationMask(seuilManuel);
}
if (imSpots != "Aucune") {
selectWindow(imSpots);
traitementImage(0, 0.5, 0.1, "Spot");
creationMask(seuilManuel);
}
}
//Avant 12/12
//fabrice.cordelieres@u-bordeaux.fr
//Pour chaque cellule, get intensité et aire et nb spots dans cellule et moyenne aire intensité spots
function analyseSpots() { //Compte spots dans cellules
//Interface
images=listOfImages();
Dialog.create("Segmentation");
Dialog.addChoice("Cellules", images);
Dialog.addChoice("Masque cellules", images);
Dialog.addChoice("Spots", images);
Dialog.addChoice("Masque spots", images);
Dialog.show();
cytoImage = Dialog.getChoice();
cytoMask = Dialog.getChoice();
spotsImage = Dialog.getChoice();
spotsMask = Dialog.getChoice();
if (cytoImage == "Aucune" || cytoMask == "Aucune" || spotsImage == "Aucune" || spotsMask == "Aucune")
exit("Il manque une ou plusieurs images !");
run("Set Measurements...", "area mean min limit decimal=3 redirect=["+cytoImage+"]");
selectWindow(cytoMask);
run("Select None"); //Reset d'une éventuelle sélection précedente
run("Analyze Particles...", "size=150-Infinity pixel show=Nothing display clear add");
nbCellules=nResults;
areasCell = newArray(nbCellules);
intensCell = newArray(nbCellules);
areasSpots = newArray(nbCellules);
intensSpots = newArray(nbCellules);
nSpots = newArray(nbCellules);
//On enregistre l'aire et l'intensité
for(i=0; i<nbCellules; i++) {
areasCell[i] = getResult("Area", i);
intensCell[i] = getResult("Mean", i);
}
//Selection de la fenêtre des spots
selectWindow(spotsMask);
run("Set Measurements...", "area mean min limit decimal=3 redirect=["+spotsImage+"]");
//On boucle sur les ROI pour obtenir les infos des spots
for(i=0; i<nbCellules; i++) {
roiManager("Select", i);
run("Analyze Particles...", "size=4-15 pixel show=Nothing display clear");
nSpots[i] = nResults;
totalArea = 0;
meanIntens = 0;
for(j=0; j<nSpots[i]; j++) {
totalArea += getResult("Area", j);
meanIntens += getResult("Mean", j);
}
areasSpots[i] = totalArea;
intensSpots[i] = meanIntens/totalArea;
}
//Affichage des résultats
run("Clear Results");
for(i=0; i<nbCellules; i++) {
setResult("AireCellule", i, areasCell[i]);
setResult("IntensiteCellule", i, intensCell[i]);
setResult("NbSpots", i, nSpots[i]);
setResult("AireSpots", i, areasSpots[i]);
setResult("IntensiteSpots", i, intensSpots[i]);
}
}
//segmentation();
analyseSpots();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment