Skip to content

Commit

Permalink
Fix issue #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Domander committed Dec 16, 2015
1 parent 406d182 commit aea4d5a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/org/doube/bonej/Thickness.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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()) {
Expand Down Expand Up @@ -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;
}
}
}
}
}

0 comments on commit aea4d5a

Please sign in to comment.