Commit 4e3cc252 authored by Andrey Filippov's avatar Andrey Filippov

Added testing for local max

parent a656136c
......@@ -3,6 +3,7 @@ package epfl;
| Version: April 6, 2014
\=====================================================================*/
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
/*=====================================================================
......@@ -79,9 +80,10 @@ public final static int GRADIENT_X = 6;
public final static int GRADIENT_Y = 7;
public final static int GRADIENT_XY = 8;
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_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;
......@@ -114,7 +116,8 @@ private static String[] operations = {
"Normalize by local maximum",
"Local min",
"Local max",
"Local diff"
"Local diff",
"Local ismax"
};
/*....................................................................
......@@ -369,8 +372,56 @@ private void doIt (
if (!(ip.getPixels() instanceof float[])) {
throw new IllegalArgumentException("Float image required");
}
switch (operation) {
case LOCAL_DIFF:
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);
final double r2 = max_norm_rad * max_norm_rad;
......@@ -422,8 +473,6 @@ private void doIt (
}
break;
case LOCAL_MIN:
{
final int ir = (int) Math.ceil(max_norm_rad);
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment