Loading src/main/java/epfl/Differentials_.java +58 −8 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ package epfl; | Version: April 6, 2014 \=====================================================================*/ import java.util.Arrays; import java.util.concurrent.atomic.AtomicInteger; /*===================================================================== Loading Loading @@ -82,6 +83,7 @@ public final static int NORMALIZE_LMAX = 9; public final static int LOCAL_MIN = 10; // local minimum within radius public final static int LOCAL_MAX = 11; // local maximum within radius public final static int LOCAL_DIFF = 12; // local maximum - local minimum within radius public final static int LOCAL_ISMAX = 13; // 1.0 if it is a local max, 0 - otherwise private final static int THREADS_MAX = 100; Loading Loading @@ -114,7 +116,8 @@ private static String[] operations = { "Normalize by local maximum", "Local min", "Local max", "Local diff" "Local diff", "Local ismax" }; /*.................................................................... Loading Loading @@ -369,7 +372,55 @@ private void doIt ( if (!(ip.getPixels() instanceof float[])) { throw new IllegalArgumentException("Float image required"); } switch (operation) { switch (operation) { // for positive values only case LOCAL_ISMAX: { final float[] floatPixels = (float[])ip.getPixels(); final double [] pixels = new double[floatPixels.length]; for (int i = 0; i < pixels.length; i++) { pixels[i] = floatPixels[i]; } Arrays.fill(floatPixels, 0.0f); final Thread[] threads = newThreadArray(THREADS_MAX); final AtomicInteger ai = new AtomicInteger(0); for (int y00 = 0; (y00 < height); y00++) { final int y0 = y00; int ymin = Math.max(y0-1, 0); int ymax = Math.min(y0+1, height-1); ai.set(0); for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { public void run() { for (int x0 = ai.getAndIncrement(); x0 < width; x0 = ai.getAndIncrement()) { int k = y0*width + x0; int xmin = Math.max(x0-1, 0); int xmax = Math.min(x0+1, width-1); double d = pixels[k]; if (d > 0) { maxtest: { for (int y = ymin; y <= ymax; y++) { for (int x = xmin; x <= xmax; x++) { int dx = x-x0; int dy = y-y0; if (pixels[y*width+x] > d) { break maxtest; } } } floatPixels[k] = 1.0f; } } } } }; } startAndJoin(threads); stepProgressBar(); } } break; case LOCAL_DIFF: { final int ir = (int) Math.ceil(max_norm_rad); Loading Loading @@ -422,8 +473,6 @@ private void doIt ( } break; case LOCAL_MIN: { final int ir = (int) Math.ceil(max_norm_rad); Loading Loading @@ -934,6 +983,7 @@ private void setupProgressBar ( completed = 0; lastTime = System.currentTimeMillis(); switch (operation) { case LOCAL_ISMAX: case LOCAL_MIN: case LOCAL_MAX: case LOCAL_DIFF: Loading Loading
src/main/java/epfl/Differentials_.java +58 −8 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ package epfl; | Version: April 6, 2014 \=====================================================================*/ import java.util.Arrays; import java.util.concurrent.atomic.AtomicInteger; /*===================================================================== Loading Loading @@ -82,6 +83,7 @@ public final static int NORMALIZE_LMAX = 9; public final static int LOCAL_MIN = 10; // local minimum within radius public final static int LOCAL_MAX = 11; // local maximum within radius public final static int LOCAL_DIFF = 12; // local maximum - local minimum within radius public final static int LOCAL_ISMAX = 13; // 1.0 if it is a local max, 0 - otherwise private final static int THREADS_MAX = 100; Loading Loading @@ -114,7 +116,8 @@ private static String[] operations = { "Normalize by local maximum", "Local min", "Local max", "Local diff" "Local diff", "Local ismax" }; /*.................................................................... Loading Loading @@ -369,7 +372,55 @@ private void doIt ( if (!(ip.getPixels() instanceof float[])) { throw new IllegalArgumentException("Float image required"); } switch (operation) { switch (operation) { // for positive values only case LOCAL_ISMAX: { final float[] floatPixels = (float[])ip.getPixels(); final double [] pixels = new double[floatPixels.length]; for (int i = 0; i < pixels.length; i++) { pixels[i] = floatPixels[i]; } Arrays.fill(floatPixels, 0.0f); final Thread[] threads = newThreadArray(THREADS_MAX); final AtomicInteger ai = new AtomicInteger(0); for (int y00 = 0; (y00 < height); y00++) { final int y0 = y00; int ymin = Math.max(y0-1, 0); int ymax = Math.min(y0+1, height-1); ai.set(0); for (int ithread = 0; ithread < threads.length; ithread++) { threads[ithread] = new Thread() { public void run() { for (int x0 = ai.getAndIncrement(); x0 < width; x0 = ai.getAndIncrement()) { int k = y0*width + x0; int xmin = Math.max(x0-1, 0); int xmax = Math.min(x0+1, width-1); double d = pixels[k]; if (d > 0) { maxtest: { for (int y = ymin; y <= ymax; y++) { for (int x = xmin; x <= xmax; x++) { int dx = x-x0; int dy = y-y0; if (pixels[y*width+x] > d) { break maxtest; } } } floatPixels[k] = 1.0f; } } } } }; } startAndJoin(threads); stepProgressBar(); } } break; case LOCAL_DIFF: { final int ir = (int) Math.ceil(max_norm_rad); Loading Loading @@ -422,8 +473,6 @@ private void doIt ( } break; case LOCAL_MIN: { final int ir = (int) Math.ceil(max_norm_rad); Loading Loading @@ -934,6 +983,7 @@ private void setupProgressBar ( completed = 0; lastTime = System.currentTimeMillis(); switch (operation) { case LOCAL_ISMAX: case LOCAL_MIN: case LOCAL_MAX: case LOCAL_DIFF: Loading