From aa955210c169f62ca6d47707c7fb8dbc9b2e9ae1 Mon Sep 17 00:00:00 2001 From: Michael Doube Date: Wed, 18 Nov 2020 19:47:02 +0800 Subject: [PATCH] Expand the allowable label space to use all positive int values (#278) Addresses issue #276 --- .../src/main/java/org/bonej/plugins/ConnectedComponents.java | 4 +++- .../src/main/java/org/bonej/plugins/ParticleCounter.java | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Legacy/bonej/src/main/java/org/bonej/plugins/ConnectedComponents.java b/Legacy/bonej/src/main/java/org/bonej/plugins/ConnectedComponents.java index af92b853e..d58e0053e 100644 --- a/Legacy/bonej/src/main/java/org/bonej/plugins/ConnectedComponents.java +++ b/Legacy/bonej/src/main/java/org/bonej/plugins/ConnectedComponents.java @@ -84,7 +84,9 @@ public class ConnectedComponents { /** Background value */ public static final int BACK = 0; /** 2^23 - greatest integer that can be represented precisely by a float */ - static final int MAX_LABEL = 8388608; + public static final int MAX_FINAL_LABEL = 8388608; + /** maximum label value to use during intermediate processing */ + static final int MAX_LABEL = Integer.MAX_VALUE; /** number of particle labels */ private static int nParticles; diff --git a/Legacy/bonej/src/main/java/org/bonej/plugins/ParticleCounter.java b/Legacy/bonej/src/main/java/org/bonej/plugins/ParticleCounter.java index 92925c86a..1afb4d852 100644 --- a/Legacy/bonej/src/main/java/org/bonej/plugins/ParticleCounter.java +++ b/Legacy/bonej/src/main/java/org/bonej/plugins/ParticleCounter.java @@ -236,6 +236,9 @@ public void run(final String arg) { final int[][] particleLabels = (int[][]) result[1]; final long[] particleSizes = (long[]) result[2]; final int nParticles = particleSizes.length; + + if (nParticles > ConnectedComponents.MAX_FINAL_LABEL) + IJ.log("Number of particles ("+nParticles+") exceeds the accurate display range (2^23) of the 32-bit float particle image"); final double[] volumes = ParticleAnalysis.getVolumes(imp, particleSizes);