Skip to content

Commit

Permalink
Adding ImageJ print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
haiderriazkhan committed Jul 21, 2015
1 parent 4c1cabc commit 1c7d8b5
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 57 deletions.
11 changes: 5 additions & 6 deletions CANDLE.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@




# function that opens up a dialog box where the user inputs filter parameters
def getOptions():
gd = GenericDialog("Options")
Expand Down Expand Up @@ -158,11 +157,11 @@ def getOptions():


# Noise Estimation and Non-Local Means Filter
start_time = time.time()
print "Denoising: NoiseEstimation + 3D Optimized Non-local Means Filter"
fimg = NativeCodeJNA.NativeCall(InputImgArray, medfiltArray, int(searchradius), int(patchradius), beta , int(x), int(y), int(z))
elapsed_time = time.time() - start_time
print "Elapsed time:", elapsed_time

print "Going Native ..."
fimg = NativeCodeJNA.NativeCall(InputImgArray, medfiltArray, int(searchradius), int(patchradius), beta , int(x), int(y), int(z))





Expand Down
40 changes: 22 additions & 18 deletions InverseAnscombe.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import ij.IJ;


public class InverseAnscombe {
Expand All @@ -42,7 +43,7 @@ public static Object[] loadOVSTable(){
}
catch (IOException e)
{
e.printStackTrace();
IJ.log("Error: Could not load pre-computed correspondence table.");
}

return new Object[]{firstColumn, secondColumn};
Expand Down Expand Up @@ -102,35 +103,35 @@ public static float[] interp1(double[] x, double[] y, float[]xq){

if(pt < x[0]){
x1 = x[0];
x2 = x[1];
y1 = y[0];
y2 = y[1];
x2 = x[1];
y1 = y[0];
y2 = y[1];
}else if(pt > x[x.length-1]){
x1 = x[x.length-2];
x2 = x[x.length-1];
y1 = y[x.length-2];
y2 = y[x.length-1];
x2 = x[x.length-1];
y1 = y[x.length-2];
y2 = y[x.length-1];

}else{

index = binary_search(x, pt);

x1 = x[index];
x2 = x[index+1];
y1 = y[index];
y2 = y[index+1];
x2 = x[index+1];
y1 = y[index];
y2 = y[index+1];

}

m = (y2 - y1) / (x2 - x1);
interp = y1 + m*(pt - x1);
if(interp < 0){
vq[counter++] = 0;
continue;
}
vq[counter++] = (float)interp;
interp = y1 + m*(pt - x1);
if(interp < 0){
vq[counter++] = 0;
continue;
}

vq[counter++] = (float)interp;

}

Expand Down Expand Up @@ -173,7 +174,10 @@ public static float[] OVST(float[] fimg){
}

return optimalinvfimg;


}

}


82 changes: 49 additions & 33 deletions NativeCodeJNA.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,91 @@
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.PointerByReference;
import ij.IJ;


public class NativeCodeJNA {

// Interface that declares native methods of the ONLM C program
public interface ONLMInterface extends Library {
public void ONLM(Pointer p1, int x1, int x2, Pointer p2, float x3, Pointer p3, int x4, int x5, int x6, PointerByReference valsRef);
public void cleanup(Pointer s);
public void ONLM(Pointer p1, int x1, int x2, Pointer p2, float x3, Pointer p3, int x4, int x5, int x6, PointerByReference valsRef);
public void cleanup(Pointer s);
}

// Interface that declares native methods of the NoiseEstimation C program
public interface NoiseEstimationInterface extends Library {
public void estimate(Pointer p1, int x1, int x2, int x3, int x4, PointerByReference valsRef);
public void estimate(Pointer p1, int x1, int x2, int x3, int x4, PointerByReference valsRef);
}

// Method that calls the two (NoiseEstimation and ONLM) native programs.
static public float[] NativeCall(float[] img , float[] medfiltimg, int searchrad , int patchrad, float beta, int x, int y, int z ){

// Set the JNA path
System.setProperty("jna.library.path", "/Users/haiderriaz/Desktop/JNA-C/NativeCode");

// Load Native Library: libNoiseEstimation.dylib
NoiseEstimationInterface noisest = (NoiseEstimationInterface) Native.loadLibrary("NoiseEstimation", NoiseEstimationInterface.class);
NoiseEstimationInterface noisest = (NoiseEstimationInterface) Native.loadLibrary("NoiseEstimation", NoiseEstimationInterface.class);

int size = x*y*z;
int size = x*y*z;

// Allocate memory for native pointers
Pointer ima = new Memory(size * Native.getNativeSize(Float.TYPE));
Pointer ref = new Memory(size * Native.getNativeSize(Float.TYPE));
Pointer ima = new Memory(size * Native.getNativeSize(Float.TYPE));
Pointer ref = new Memory(size * Native.getNativeSize(Float.TYPE));


for (int dloop=0; dloop<(size); dloop++) {
for (int dloop=0; dloop<(size); dloop++) {

ima.setFloat(dloop * Native.getNativeSize(Float.TYPE), img[dloop] );
ref.setFloat(dloop * Native.getNativeSize(Float.TYPE), medfiltimg[dloop] );
ima.setFloat(dloop * Native.getNativeSize(Float.TYPE), img[dloop] );
ref.setFloat(dloop * Native.getNativeSize(Float.TYPE), medfiltimg[dloop] );

}
}

// Pointer to a pointer : This lets us read the output array from the first native method
PointerByReference PMAP = new PointerByReference();
// Pointer to a pointer : This lets us read the output array from the first native method
PointerByReference PMAP = new PointerByReference();

IJ.log("Wavelet-based local noise estimation");

// Call to the first native method
noisest.estimate(ima, x, y, z, 2*searchrad, PMAP);
long startTime = System.currentTimeMillis();

// Call to the first native method
noisest.estimate(ima, x, y, z, 2*searchrad, PMAP);

Pointer MAP = PMAP.getValue();
long endTime = System.currentTimeMillis();

IJ.log("Elapsed time: " + ((endTime - startTime)/1000) );

Pointer MAP = PMAP.getValue();


// Load Native Library: libONLM_Mod.dylib
ONLMInterface onlm = (ONLMInterface) Native.loadLibrary("ONLM_Mod", ONLMInterface.class);


// Load Native Library: libONLM_Mod.dylib
ONLMInterface onlm = (ONLMInterface) Native.loadLibrary("ONLM_Mod", ONLMInterface.class);

// Pointer to a pointer : This lets us read the output array from the second native method
PointerByReference Pfima = new PointerByReference();
// Pointer to a pointer : This lets us read the output array from the second native method
PointerByReference Pfima = new PointerByReference();

IJ.log("Denoising: 3D Optimized Non-local Means Filter");

startTime = System.currentTimeMillis();

// Call to the second native method
onlm.ONLM(ima, searchrad, patchrad, MAP, beta, ref, x, y, z, Pfima);
// Call to the second native method
onlm.ONLM(ima, searchrad, patchrad, MAP, beta, ref, x, y, z, Pfima);

endTime = System.currentTimeMillis();

IJ.log("Elapsed time: " + ((endTime - startTime)/1000) );

Pointer fima = Pfima.getValue();
Pointer fima = Pfima.getValue();

// Get final result
for (int dloop=0; dloop<size; dloop++) {
// Get final result
for (int dloop=0; dloop<size; dloop++) {

medfiltimg[dloop] = fima.getFloat(dloop * Native.getNativeSize(Float.TYPE));
medfiltimg[dloop] = fima.getFloat(dloop * Native.getNativeSize(Float.TYPE));

}
}

// free memory
onlm.cleanup(fima);
// free memory
onlm.cleanup(fima);

return medfiltimg;
return medfiltimg;


}
Expand Down

0 comments on commit 1c7d8b5

Please sign in to comment.