Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StRigaud committed Oct 17, 2024
1 parent a3d651d commit 804ac7d
Show file tree
Hide file tree
Showing 7 changed files with 843 additions and 830 deletions.
15 changes: 9 additions & 6 deletions src/test/java/TestAbsolute.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public class TestAbsolute {

@Test
public void testAbsolute() {
DeviceJ device = DeviceJ.getDefaultDevice();
DeviceJ device = DeviceJ.getDefaultDevice();
device.setWaitForKernelFinish(true);

ArrayJ in = device.createArray(DataType.INT32, MemoryType.BUFFER, 2, 2);
in.fillMemory(-1);
ArrayJ out = device.createArray(DataType.INT32, MemoryType.BUFFER, 2, 2);
Expand All @@ -64,18 +66,19 @@ public void testAbsolute() {

@Test
public void testAbsolute1() {
DeviceJ device = DeviceJ.getDefaultDevice();
DeviceJ device = DeviceJ.getDefaultDevice();
device.setWaitForKernelFinish(true);
ArrayJ in = device.createArray(DataType.INT32, MemoryType.BUFFER, 2, 2);
in.fillMemory(-1);
in.fillMemory(-1);
ArrayJ out = Tier1.absolute(device, in, null);

int[] result = new int[4];
IntBuffer resultBuff = IntBuffer.wrap(result);
out.readToBuffer(resultBuff);

for (int val : result)
assertEquals(1, val);
in = null;
out = null;
assertEquals(1, val);
in = null;
out = null;
}
}
141 changes: 70 additions & 71 deletions src/test/java/TestAbsoluteImagePlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,81 +44,80 @@

public class TestAbsoluteImagePlus {

@Test
public void testAbsoluteImagePlus() {
ImagePlus inputImp = IJ.createImage("input", 2, 2, 1, 32);
ImagePlus outputImp = IJ.createImage("input", 2, 2, 1, 32);
ImageProcessor inpIp = inputImp.getProcessor();
ImageProcessor outIp = outputImp.getProcessor();

int[] vals = {-1, -1, 1, 1};
int c = 0;
for (int x = 0; x < 2; x ++) {
for (int y = 0; y < 2; y ++) {
inpIp.putPixelValue(x, y, vals[c]);
outIp.putPixelValue(x, y, vals[c ++]);
}
}


DeviceJ device = DeviceJ.getDefaultDevice();
ArrayJ in = ImageJConverters.copyImagePlus2ToArrayJ(inputImp, device, MemoryType.BUFFER);
ArrayJ out = ImageJConverters.copyImagePlus2ToArrayJ(outputImp, device, MemoryType.BUFFER);

Tier1.absolute(device, in, out);

outputImp = ImageJConverters.copyArrayJToImagePlus(out);
outIp = outputImp.getProcessor();


double min = Double.MAX_VALUE;
@Test
public void testAbsoluteImagePlus() {
ImagePlus inputImp = IJ.createImage("input", 2, 2, 1, 32);
ImagePlus outputImp = IJ.createImage("input", 2, 2, 1, 32);
ImageProcessor inpIp = inputImp.getProcessor();
ImageProcessor outIp = outputImp.getProcessor();

int[] vals = { -1, -1, 1, 1 };
int c = 0;
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
inpIp.putPixelValue(x, y, vals[c]);
outIp.putPixelValue(x, y, vals[c++]);
}
}

DeviceJ device = DeviceJ.getDefaultDevice();
device.setWaitForKernelFinish(true);
ArrayJ in = ImageJConverters.copyImagePlus2ToArrayJ(inputImp, device, MemoryType.BUFFER);
ArrayJ out = ImageJConverters.copyImagePlus2ToArrayJ(outputImp, device, MemoryType.BUFFER);

Tier1.absolute(device, in, out);

outputImp = ImageJConverters.copyArrayJToImagePlus(out);
outIp = outputImp.getProcessor();

double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
double mean = 0;
for (int x = 0; x < 2; x ++) {
for (int y = 0; y < 2; y ++) {
double val = outIp.getPixelValue(x, y);
mean += val / 4;
min = Math.min(min,val);
max = Math.max(max,val);
}
}

assertEquals(1, min);
assertEquals(1, max);
assertEquals(1, mean);
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
double val = outIp.getPixelValue(x, y);
mean += val / 4;
min = Math.min(min, val);
max = Math.max(max, val);
}
}

assertEquals(1, min);
assertEquals(1, max);
assertEquals(1, mean);
in = null;
out = null;
}

@Test
public void testAbsolute1ImagePlus() {
ImagePlus inputImp = IJ.createImage("input", 2, 2, 1, 32);
ImageProcessor inpIp = inputImp.getProcessor();

int[] vals = {-1, -1, 1, 1};
int c = 0;
for (int x = 0; x < 2; x ++) {
for (int y = 0; y < 2; y ++) {
inpIp.putPixelValue(x, y, vals[c ++]);
}
}


DeviceJ device = DeviceJ.getDefaultDevice();
ArrayJ in = ImageJConverters.copyImagePlus2ToArrayJ(inputImp, device, MemoryType.BUFFER);

ArrayJ out = Tier1.absolute(device, in, null);

ImagePlus outputImp = ImageJConverters.copyArrayJToImagePlus(out);
ImageProcessor outIp = outputImp.getProcessor();

for (int x = 0; x < 2; x ++) {
for (int y = 0; y < 2; y ++) {
double val = outIp.getPixelValue(x, y);
assertEquals(1, val);
}
}
}

@Test
public void testAbsolute1ImagePlus() {
ImagePlus inputImp = IJ.createImage("input", 2, 2, 1, 32);
ImageProcessor inpIp = inputImp.getProcessor();

int[] vals = { -1, -1, 1, 1 };
int c = 0;
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
inpIp.putPixelValue(x, y, vals[c++]);
}
}

DeviceJ device = DeviceJ.getDefaultDevice();
device.setWaitForKernelFinish(true);
ArrayJ in = ImageJConverters.copyImagePlus2ToArrayJ(inputImp, device, MemoryType.BUFFER);

ArrayJ out = Tier1.absolute(device, in, null);

ImagePlus outputImp = ImageJConverters.copyArrayJToImagePlus(out);
ImageProcessor outIp = outputImp.getProcessor();

for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
double val = outIp.getPixelValue(x, y);
assertEquals(1, val);
}
}
in = null;
out = null;
}
}
}
60 changes: 29 additions & 31 deletions src/test/java/TestAbsoluteImgLib2.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,59 +44,57 @@

public class TestAbsoluteImgLib2 {

@Test
public void testAbsoluteImgLib2() {
int[] flatVals = {1, 1, -1, -1};
RandomAccessibleInterval<IntType> inputImg = ArrayImgs.ints(flatVals, new long[] {2, 2});
RandomAccessibleInterval<IntType> outputImg = ArrayImgs.ints(flatVals, new long[] {2, 2});
@Test
public void testAbsoluteImgLib2() {
int[] flatVals = { 1, 1, -1, -1 };
RandomAccessibleInterval<IntType> inputImg = ArrayImgs.ints(flatVals, new long[] { 2, 2 });
RandomAccessibleInterval<IntType> outputImg = ArrayImgs.ints(flatVals, new long[] { 2, 2 });

DeviceJ device = DeviceJ.getDefaultDevice();
device.setWaitForKernelFinish(true);
ArrayJ in = ImgLib2Converters.copyImgLib2ToArrayJ(inputImg, device, MemoryType.BUFFER);
ArrayJ out = ImgLib2Converters.copyImgLib2ToArrayJ(outputImg, device, MemoryType.BUFFER);

DeviceJ device = DeviceJ.getDefaultDevice();
ArrayJ in = ImgLib2Converters.copyImgLib2ToArrayJ(inputImg, device, MemoryType.BUFFER);
ArrayJ out = ImgLib2Converters.copyImgLib2ToArrayJ(outputImg, device, MemoryType.BUFFER);
Tier1.absolute(device, in, out);

Tier1.absolute(device, in, out);
outputImg = ImgLib2Converters.copyArrayJToImgLib2(out);

outputImg = ImgLib2Converters.copyArrayJToImgLib2(out);


double min = outputImg.firstElement().getRealDouble();
double min = outputImg.firstElement().getRealDouble();
double max = min;
double mean = 0;

for (IntType px : outputImg) {
double val = px.getRealDouble();
mean += val / 4;
min = Math.min(min,val);
max = Math.max(max,val);
min = Math.min(min, val);
max = Math.max(max, val);
}

assertEquals(1, min);
assertEquals(1, max);
assertEquals(1, mean);
assertEquals(1, min);
assertEquals(1, max);
assertEquals(1, mean);
in = null;
out = null;
}

@Test
public void testAbsolute1ImgLib2() {
int[] flatVals = {1, 1, -1, -1};
RandomAccessibleInterval<IntType> inputImg = ArrayImgs.ints(flatVals, new long[] {2, 2});

}

DeviceJ device = DeviceJ.getDefaultDevice();
ArrayJ in = ImgLib2Converters.copyImgLib2ToArrayJ(inputImg, device, MemoryType.BUFFER);
@Test
public void testAbsolute1ImgLib2() {
int[] flatVals = { 1, 1, -1, -1 };
RandomAccessibleInterval<IntType> inputImg = ArrayImgs.ints(flatVals, new long[] { 2, 2 });

ArrayJ out = Tier1.absolute(device, in, null);
DeviceJ device = DeviceJ.getDefaultDevice();
device.setWaitForKernelFinish(true);
ArrayJ in = ImgLib2Converters.copyImgLib2ToArrayJ(inputImg, device, MemoryType.BUFFER);

RandomAccessibleInterval<IntType> outputImg = ImgLib2Converters.copyArrayJToImgLib2(out);
ArrayJ out = Tier1.absolute(device, in, null);

RandomAccessibleInterval<IntType> outputImg = ImgLib2Converters.copyArrayJToImgLib2(out);

for (IntType px : outputImg) {
double val = px.getRealDouble();
assertEquals(1, val);
assertEquals(1, val);
}
in = null;
out = null;
}
}
}
Loading

0 comments on commit 804ac7d

Please sign in to comment.