diff --git a/src/org/doube/bonej/Thickness.java b/src/org/doube/bonej/Thickness.java index 2f63e1ce..eed4c226 100644 --- a/src/org/doube/bonej/Thickness.java +++ b/src/org/doube/bonej/Thickness.java @@ -131,6 +131,7 @@ public void run(final String arg) { impLTC = getLocalThickness(imp, inverse, doMask); impLTC.setTitle(title + "_Tb.Th"); impLTC.setCalibration(imp.getCalibration()); + backgroundToNaN(impLTC, 0x00); final double[] stats = StackStats.meanStdDev(impLTC); insertResults(imp, stats, inverse); if (doGraphic && !Interpreter.isBatchMode()) { @@ -153,6 +154,7 @@ public void run(final String arg) { // check marrow cavity size (i.e. trabcular separation, Tb.Sp) impLTCi.setTitle(title + "_Tb.Sp"); impLTCi.setCalibration(imp.getCalibration()); + backgroundToNaN(impLTCi, 0x00); final double[] stats = StackStats.meanStdDev(impLTCi); insertResults(imp, stats, inverse); if (doGraphic && !Interpreter.isBatchMode()) { @@ -1379,4 +1381,28 @@ private ImagePlus trimOverhang(final ImagePlus imp, final ImagePlus impLTC, fina } return impLTC; } + + + /** + * Sets the value of the background pixels in the given image to Float.NaN. + * + * @param image + * A 32-bit floating point image + * @param backgroundColor + * The color used to identify background pixel (usually 0x00) + */ + private static void backgroundToNaN(final ImagePlus image, final int backgroundColor) { + final int depth = image.getNSlices(); + final int pixelsPerSlice = image.getWidth() * image.getHeight(); + final ImageStack stack = image.getStack(); + + for (int z = 1; z <= depth; z++) { + final float pixels[] = (float[]) stack.getPixels(z); + for (int i = 0; i < pixelsPerSlice; i++) { + if (Float.compare(pixels[i], backgroundColor) == 0) { + pixels[i] = Float.NaN; + } + } + } + } } \ No newline at end of file