private static double CalculateMean ( RectangleF roiBoundingBox, GrayscalePixelData pixelData, IModalityLut modalityLut, IsPointInRoiDelegate isPointInRoi ) { double sum = 0; int pixelCount = 0; var boundingBox = RectangleUtilities.RoundInflate(RectangleUtilities.ConvertToPositiveRectangle(roiBoundingBox)); pixelData.ForEachPixel( boundingBox.Left, boundingBox.Top, boundingBox.Right, boundingBox.Bottom, delegate(int i, int x, int y, int pixelIndex) { if (isPointInRoi(x, y)) { ++pixelCount; // Make sure we run the raw pixel through the modality LUT // when doing the calculation. Note that the modality LUT // can be something other than a rescale intercept, so we can't // just run the mean through the LUT. int storedValue = pixelData.GetPixel(pixelIndex); double realValue = modalityLut != null ? modalityLut[storedValue] : storedValue; sum += realValue; } }); if (pixelCount == 0) { return(0); } return(sum / pixelCount); }
private static double CalculateStandardDeviation ( double mean, RectangleF roiBoundingBox, GrayscalePixelData pixelData, IModalityLut modalityLut, IsPointInRoiDelegate isPointInRoi ) { double sum = 0; int pixelCount = 0; var boundingBox = RectangleUtilities.RoundInflate(RectangleUtilities.ConvertToPositiveRectangle(roiBoundingBox)); pixelData.ForEachPixel( boundingBox.Left, boundingBox.Top, boundingBox.Right, boundingBox.Bottom, delegate(int i, int x, int y, int pixelIndex) { if (isPointInRoi(x, y)) { ++pixelCount; int storedValue = pixelData.GetPixel(pixelIndex); double realValue = modalityLut != null ? modalityLut[storedValue] : storedValue; double deviation = realValue - mean; sum += deviation * deviation; } }); if (pixelCount == 0) { return(0); } return(Math.Sqrt(sum / pixelCount)); }
private static double CalculateMean ( RectangleF roiBoundingBox, GrayscalePixelData pixelData, IModalityLut modalityLut, IsPointInRoiDelegate isPointInRoi ) { double sum = 0; int pixelCount = 0; var boundingBox = RectangleUtilities.RoundInflate(RectangleUtilities.ConvertToPositiveRectangle(roiBoundingBox)); pixelData.ForEachPixel( boundingBox.Left, boundingBox.Top, boundingBox.Right, boundingBox.Bottom, delegate(int i, int x, int y, int pixelIndex) { if (isPointInRoi(x, y)) { ++pixelCount; // Make sure we run the raw pixel through the modality LUT // when doing the calculation. Note that the modality LUT // can be something other than a rescale intercept, so we can't // just run the mean through the LUT. int storedValue = pixelData.GetPixel(pixelIndex); double realValue = modalityLut != null ? modalityLut[storedValue] : storedValue; sum += realValue; } }); if (pixelCount == 0) return 0; return sum/pixelCount; }
private static double CalculateStandardDeviation ( double mean, RectangleF roiBoundingBox, GrayscalePixelData pixelData, IModalityLut modalityLut, IsPointInRoiDelegate isPointInRoi ) { double sum = 0; int pixelCount = 0; var boundingBox = RectangleUtilities.RoundInflate(RectangleUtilities.ConvertToPositiveRectangle(roiBoundingBox)); pixelData.ForEachPixel( boundingBox.Left, boundingBox.Top, boundingBox.Right, boundingBox.Bottom, delegate(int i, int x, int y, int pixelIndex) { if (isPointInRoi(x, y)) { ++pixelCount; int storedValue = pixelData.GetPixel(pixelIndex); double realValue = modalityLut != null ? modalityLut[storedValue] : storedValue; double deviation = realValue - mean; sum += deviation*deviation; } }); if (pixelCount == 0) return 0; return Math.Sqrt(sum/pixelCount); }