use of boofcv.core.image.GImageMultiBand in project BoofCV by lessthanoptimal.
the class TestConvolveImage method fillTestImage.
/**
* Fillers the border in the larger image with an extended version of the smaller image. A duplicate
* of the smaller image is contained in the center of the larger image.
*/
protected void fillTestImage(ImageBase smaller, ImageBase larger, KernelBase kernel, String functionName) {
computeBorder(kernel, functionName);
stripBorder(larger, borderX0, borderY0, borderX1, borderY1).setTo(smaller);
GImageMultiBand s = FactoryGImageMultiBand.wrap(smaller);
GImageMultiBand l = FactoryGImageMultiBand.wrap(larger);
float[] pixel = new float[s.getNumberOfBands()];
for (int y = 0; y < larger.height; y++) {
for (int x = 0; x < larger.width; x++) {
int sx = x - borderX0;
int sy = y - borderY0;
if (sx < 0)
sx = 0;
else if (sx >= smaller.width)
sx = smaller.width - 1;
if (sy < 0)
sy = 0;
else if (sy >= smaller.height)
sy = smaller.height - 1;
s.get(sx, sy, pixel);
l.set(x, y, pixel);
}
}
// ShowImages.showWindow((GrayF32)larger,"large",true);
}
use of boofcv.core.image.GImageMultiBand in project BoofCV by lessthanoptimal.
the class TestConvolveImage method compareResults.
@Override
protected void compareResults(Object targetResult, Object[] targetParam, Object validationResult, Object[] validationParam) {
ImageBase targetOut = (ImageBase) targetParam[2];
ImageBase validationOut = (ImageBase) validationParam[2];
// remove the border
computeBorder((KernelBase) targetParam[0], methodTest.getName());
validationOut = stripBorder(validationOut, borderX0, borderY0, borderX1, borderY1);
GImageMultiBand t = FactoryGImageMultiBand.wrap(targetOut);
GImageMultiBand v = FactoryGImageMultiBand.wrap(validationOut);
float[] valueT = new float[t.getNumberOfBands()];
float[] valueV = new float[v.getNumberOfBands()];
for (int y = 0; y < targetOut.height; y++) {
for (int x = 0; x < targetOut.width; x++) {
t.get(x, y, valueT);
v.get(x, y, valueV);
for (int band = 0; band < valueT.length; band++) {
assertEquals("Failed at " + x + " " + y + " band " + band, valueV[band], valueT[band], 1e-4f);
}
}
}
}
use of boofcv.core.image.GImageMultiBand in project BoofCV by lessthanoptimal.
the class BufferedImageChecks method checkEquals.
public static void checkEquals(BufferedImage imgA, ImageMultiBand imgB, boolean boofcvBandOrder, float tol) {
GImageMultiBand genericB = FactoryGImageMultiBand.wrap(imgB);
float[] pixelB = new float[imgB.getNumBands()];
WritableRaster raster = imgA.getRaster();
if (raster.getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE && ConvertBufferedImage.isKnownByteFormat(imgA)) {
if (raster.getNumBands() == 1) {
byte[] dataA = ((DataBufferByte) raster.getDataBuffer()).getData();
int strideA = ConvertRaster.stride(raster);
int offsetA = ConvertRaster.getOffset(raster);
// handle a special case where the RGB conversion is screwed
for (int i = 0; i < imgA.getHeight(); i++) {
for (int j = 0; j < imgA.getWidth(); j++) {
genericB.get(j, i, pixelB);
double valB = pixelB[0];
int valA = dataA[offsetA + i * strideA + j];
valA &= 0xFF;
if (Math.abs(valA - valB) > tol)
throw new RuntimeException("Images are not equal: A = " + valA + " B = " + valB);
}
}
return;
}
}
int[] bandOrder;
if (boofcvBandOrder) {
if (imgB.getNumBands() == 4) {
bandOrder = new int[] { 1, 2, 3, 0 };
} else {
bandOrder = new int[] { 0, 1, 2 };
}
} else {
if (imgA.getType() == BufferedImage.TYPE_INT_RGB) {
bandOrder = new int[] { 0, 1, 2 };
} else if (imgA.getType() == BufferedImage.TYPE_INT_BGR || imgA.getType() == BufferedImage.TYPE_3BYTE_BGR) {
bandOrder = new int[] { 2, 1, 0 };
} else if (imgA.getType() == BufferedImage.TYPE_4BYTE_ABGR) {
bandOrder = new int[] { 0, 3, 2, 1 };
} else if (imgA.getType() == BufferedImage.TYPE_INT_ARGB) {
bandOrder = new int[] { 0, 1, 2, 3 };
} else {
bandOrder = new int[] { 0, 1, 2 };
}
}
int[] expected = new int[4];
for (int y = 0; y < imgA.getHeight(); y++) {
for (int x = 0; x < imgA.getWidth(); x++) {
// getRGB() automatically converts the band order to ARGB
int rgb = imgA.getRGB(x, y);
// alpha
expected[0] = ((rgb >>> 24) & 0xFF);
// red
expected[1] = ((rgb >>> 16) & 0xFF);
// green
expected[2] = ((rgb >>> 8) & 0xFF);
// blue
expected[3] = (rgb & 0xFF);
if (imgB.getNumBands() == 4) {
genericB.get(x, y, pixelB);
for (int i = 0; i < 4; i++) {
double found = pixelB[bandOrder[i]];
if (Math.abs(Math.exp(expected[i] - found)) > tol) {
for (int j = 0; j < 4; j++) {
System.out.println(expected[j] + " " + pixelB[bandOrder[j]]);
}
throw new RuntimeException("Images are not equal: band - " + i + " type " + imgA.getType());
}
}
} else if (imgB.getNumBands() == 3) {
genericB.get(x, y, pixelB);
for (int i = 0; i < 3; i++) {
double found = pixelB[bandOrder[i]];
if (Math.abs(expected[i + 1] - found) > tol) {
for (int j = 0; j < 3; j++) {
System.out.println(expected[j + 1] + " " + pixelB[bandOrder[j]]);
}
throw new RuntimeException("Images are not equal: band - " + i + " type " + imgA.getType());
}
}
} else if (imgB.getNumBands() == 1) {
genericB.get(x, y, pixelB);
double expectedGray = (expected[1] + expected[2] + expected[3]) / 3.0;
if (Math.abs(expectedGray - pixelB[0]) > tol) {
throw new RuntimeException("Images are not equal: " + imgA.getType() + " single band multi banded");
}
} else {
throw new RuntimeException("Unexpected number of bands");
}
}
}
}
use of boofcv.core.image.GImageMultiBand in project BoofCV by lessthanoptimal.
the class TestConvolveJustBorder_General_IL method compareResults.
@Override
protected void compareResults(Object targetResult, Object[] targetParam, Object validationResult, Object[] validationParam) {
ImageInterleaved targetOut = (ImageInterleaved) targetParam[2];
ImageInterleaved validationOut = (ImageInterleaved) validationParam[2];
// remove the border
computeBorder((KernelBase) targetParam[0], methodTest.getName());
validationOut = (ImageInterleaved) stripBorder(validationOut, borderX0, borderY0, borderX1, borderY1);
GImageMultiBand t = FactoryGImageMultiBand.wrap(targetOut);
GImageMultiBand v = FactoryGImageMultiBand.wrap(validationOut);
float[] pixelT = new float[t.getNumberOfBands()];
float[] pixelV = new float[t.getNumberOfBands()];
for (int y = 0; y < targetOut.height; y++) {
if (y >= borderX0 && y < targetOut.height - borderX1)
continue;
for (int x = 0; x < targetOut.width; x++) {
if (x >= borderX0 && x < targetOut.width - borderY1)
continue;
t.get(x, y, pixelT);
v.get(x, y, pixelV);
for (int band = 0; band < t.getNumberOfBands(); band++) {
assertEquals(x + " " + y, pixelV[band], pixelT[band], 1e-4f);
}
}
}
}
use of boofcv.core.image.GImageMultiBand in project BoofCV by lessthanoptimal.
the class BufferedImageChecks method checkEquals.
public static void checkEquals(WritableRaster imgA, ImageMultiBand imgB, float tol) {
GImageMultiBand genericB = FactoryGImageMultiBand.wrap(imgB);
float[] pixelB = new float[imgB.getNumBands()];
if (imgA.getNumBands() != imgB.getNumBands()) {
throw new RuntimeException("Number of bands not equals");
}
if (imgA.getDataBuffer().getDataType() == DataBuffer.TYPE_BYTE) {
byte[] dataA = ((DataBufferByte) imgA.getDataBuffer()).getData();
int strideA = ConvertRaster.stride(imgA);
int offsetA = ConvertRaster.getOffset(imgA);
// handle a special case where the RGB conversion is screwed
for (int y = 0; y < imgA.getHeight(); y++) {
int indexA = offsetA + strideA * y;
for (int x = 0; x < imgA.getWidth(); x++) {
genericB.get(x, y, pixelB);
for (int k = 0; k < imgB.getNumBands(); k++) {
int valueA = dataA[indexA++] & 0xFF;
double valueB = pixelB[k];
if (Math.abs(valueA - valueB) > tol)
throw new RuntimeException("Images are not equal: A = " + valueA + " B = " + valueB);
}
}
}
} else if (imgA.getDataBuffer().getDataType() == DataBuffer.TYPE_INT) {
int[] dataA = ((DataBufferInt) imgA.getDataBuffer()).getData();
int strideA = ConvertRaster.stride(imgA);
int offsetA = ConvertRaster.getOffset(imgA);
// handle a special case where the RGB conversion is screwed
for (int y = 0; y < imgA.getHeight(); y++) {
int indexA = offsetA + strideA * y;
for (int x = 0; x < imgA.getWidth(); x++) {
genericB.get(x, y, pixelB);
int valueA = dataA[indexA++];
if (imgB.getNumBands() == 4) {
int found0 = (valueA >> 24) & 0xFF;
int found1 = (valueA >> 16) & 0xFF;
int found2 = (valueA >> 8) & 0xFF;
int found3 = valueA & 0xFF;
if (Math.abs(found0 - pixelB[0]) > tol)
throw new RuntimeException("Images are not equal");
if (Math.abs(found1 - pixelB[1]) > tol)
throw new RuntimeException("Images are not equal");
if (Math.abs(found2 - pixelB[2]) > tol)
throw new RuntimeException("Images are not equal");
if (Math.abs(found3 - pixelB[3]) > tol)
throw new RuntimeException("Images are not equal");
} else if (imgB.getNumBands() == 3) {
int found0 = (valueA >> 16) & 0xFF;
int found1 = (valueA >> 8) & 0xFF;
int found2 = valueA & 0xFF;
if (Math.abs(found0 - pixelB[0]) > tol)
throw new RuntimeException("Images are not equal");
if (Math.abs(found1 - pixelB[1]) > tol)
throw new RuntimeException("Images are not equal");
if (Math.abs(found2 - pixelB[2]) > tol)
throw new RuntimeException("Images are not equal");
} else {
throw new RuntimeException("Unexpectd number of bands");
}
}
}
} else {
throw new RuntimeException("Add support for raster type " + imgA.getClass().getSimpleName());
}
}
Aggregations