|
Hi guys,
I'm trying to calculate the mean and the standard deviation of the green pixels within a ROI. Anyway there is something wrong with my code, can you help me?
waitForUser("Advice", "keep open only the images you want to analyze, then click ok");
setBackgroundColor (16777215);
waitForUser("Selection required", "put a rectangular ROI in a background area with artefacts"); // CORREGGO PER IL BACKGROUND
for (i=1; i<=nImages; i++)
{
selectImage (i);
run("ROI Manager..."); // Gestisco il ROI manager e correggo per il box
conta = roiManager("count");
if (conta != 0)
{
roiManager("Delete"); // svuoto il ROI manager se è pieno
}
if (selectionType() != 0)
{
titolone = getTitle ();
print ("L'immagine"+titolone+"non è stata processata poichè priva di ROI");
}
else
{
roiManager("Add");
roiManager("Select", 0); //seleziono la nuova roi
getSelectionBounds(x, y, width, height);
x2 = x;
y2 = y;
greentot = 0;
greenpixel = 0;
larghezza = x + width;
lunghezza = y + height;
larghezza2 = x2 + width;
lunghezza2 = y2 + height;
for (y = y; y <= lunghezza ; y++)
{
for (x = x; x <= larghezza; x++)
{
v = getPixel(x,y);
g = (v>>8)&0xff; // estraggo green byte (bits 15-8)
greentot = greentot + g;
greenpixel++;
}
}
greenmean = greentot / greenpixel;
totale2 = 0;
differenziale =0;
sommatoria = 0;
deviazione = 0;
for (y = y2; y <= lunghezza2 ; y++)
{
for (x = x2; x <= larghezza2; x++)
{
v = getPixel(x,y);
g = (v>>8)&0xff; // estraggo green byte (bits 15-8)
differenziale = (greenmean - g)*(greenmean-g);
sommatoria = sommatoria + differenziale;
totale2++;
}
}
libertà = totale2 - 1;
varianza = sommatoria/ libertà;
deviazione = sqrt (varianza);
print (greenmean);
print (deviazione);
print (totale2);
print (greenpixel);
|