use of boofcv.struct.image.InterleavedF32 in project BoofCV by lessthanoptimal.
the class TestImageDistortBasic_IL method applyRenderAll_true.
@Test
public void applyRenderAll_true() {
Helper alg = new Helper(interp);
alg.setRenderAll(true);
offX = offY = 0;
alg.reset();
alg.setModel(tran);
alg.apply(new InterleavedF32(10, 15, NUM_BANDS), new InterleavedF32(10, 15, NUM_BANDS));
assertEquals(150, alg.getTotal());
offX = offY = 0.1f;
alg.reset();
alg.setModel(tran);
alg.apply(new InterleavedF32(10, 15, NUM_BANDS), new InterleavedF32(10, 15, NUM_BANDS));
assertEquals(150, alg.getTotal());
offX = offY = -0.1f;
alg.reset();
alg.setModel(tran);
alg.apply(new InterleavedF32(10, 15, NUM_BANDS), new InterleavedF32(10, 15, NUM_BANDS));
assertEquals(150, alg.getTotal());
}
use of boofcv.struct.image.InterleavedF32 in project BoofCV by lessthanoptimal.
the class TestInterleavedImageOps method split2.
@Test
public void split2() {
InterleavedF32 interleaved = new InterleavedF32(2, 4, 2);
for (int i = 0; i < interleaved.data.length; i++) {
interleaved.data[i] = i + 1;
}
GrayF32 a = new GrayF32(2, 4);
GrayF32 b = new GrayF32(2, 4);
InterleavedImageOps.split2(interleaved, a, b);
for (int y = 0; y < interleaved.height; y++) {
for (int x = 0; x < interleaved.width; x++) {
assertEquals(interleaved.getBand(x, y, 0), a.get(x, y), 1e-8);
assertEquals(interleaved.getBand(x, y, 1), b.get(x, y), 1e-8);
}
}
}
use of boofcv.struct.image.InterleavedF32 in project BoofCV by lessthanoptimal.
the class GeneralFft_to_DiscreteFourierTransform_F32 method inverse.
@Override
public void inverse(InterleavedF32 transform, GrayF32 image) {
DiscreteFourierTransformOps.checkImageArguments(image, transform);
if (image.isSubimage() || transform.isSubimage())
throw new IllegalArgumentException("Subimages are not supported");
checkDeclareAlg(image);
// If he user lets us, modify the transform
InterleavedF32 workImage;
if (modifyInputs) {
workImage = transform;
} else {
tmp.reshape(transform.width, transform.height);
tmp.setTo(transform);
workImage = tmp;
}
alg.complexInverse(workImage.data, true);
// copy the real portion. imaginary should be zeros
int N = image.width * image.height;
for (int i = 0; i < N; i++) {
image.data[i] = workImage.data[i * 2];
}
}
use of boofcv.struct.image.InterleavedF32 in project BoofCV by lessthanoptimal.
the class TestInterleavedImageOps method merge2.
@Test
public void merge2() {
GrayF32 a = new GrayF32(2, 4);
GrayF32 b = new GrayF32(2, 4);
for (int i = 0; i < a.data.length; i++) {
a.data[i] = i * 2 + 1;
b.data[i] = i * 2 + 2;
}
InterleavedF32 interleaved = new InterleavedF32(2, 4, 2);
InterleavedImageOps.merge2(a, b, interleaved);
for (int y = 0; y < interleaved.height; y++) {
for (int x = 0; x < interleaved.width; x++) {
assertEquals(a.get(x, y), interleaved.getBand(x, y, 0), 1e-8);
assertEquals(b.get(x, y), interleaved.getBand(x, y, 1), 1e-8);
}
}
}
use of boofcv.struct.image.InterleavedF32 in project BoofCV by lessthanoptimal.
the class ExampleFourierTransform method applyBoxFilter.
/**
* Demonstration of how to apply a box filter in the frequency domain and compares the results
* to a box filter which has been applied in the spatial domain
*/
public static void applyBoxFilter(GrayF32 input) {
// declare storage
GrayF32 boxImage = new GrayF32(input.width, input.height);
InterleavedF32 boxTransform = new InterleavedF32(input.width, input.height, 2);
InterleavedF32 transform = new InterleavedF32(input.width, input.height, 2);
GrayF32 blurredImage = new GrayF32(input.width, input.height);
GrayF32 spatialBlur = new GrayF32(input.width, input.height);
DiscreteFourierTransform<GrayF32, InterleavedF32> dft = DiscreteFourierTransformOps.createTransformF32();
// Make the image scaled from 0 to 1 to reduce overflow issues
PixelMath.divide(input, 255.0f, input);
// compute the Fourier Transform
dft.forward(input, transform);
// the image edges
for (int y = 0; y < 15; y++) {
int yy = y - 7 < 0 ? boxImage.height + (y - 7) : y - 7;
for (int x = 0; x < 15; x++) {
int xx = x - 7 < 0 ? boxImage.width + (x - 7) : x - 7;
// Set the value such that it doesn't change the image intensity
boxImage.set(xx, yy, 1.0f / (15 * 15));
}
}
// compute the DFT for the box filter
dft.forward(boxImage, boxTransform);
// Visualize the Fourier Transform for the input image and the box filter
displayTransform(transform, "Input Image");
displayTransform(boxTransform, "Box Filter");
// apply the filter. convolution in spacial domain is the same as multiplication in the frequency domain
DiscreteFourierTransformOps.multiplyComplex(transform, boxTransform, transform);
// convert the image back and display the results
dft.inverse(transform, blurredImage);
// undo change of scale
PixelMath.multiply(blurredImage, 255.0f, blurredImage);
PixelMath.multiply(input, 255.0f, input);
// For sake of comparison, let's compute the box blur filter in the spatial domain
// NOTE: The image border will be different since the frequency domain wraps around and this implementation
// of the spacial domain adapts the kernel size
BlurImageOps.mean(input, spatialBlur, 7, null);
// Convert to BufferedImage for output
BufferedImage originOut = ConvertBufferedImage.convertTo(input, null);
BufferedImage spacialOut = ConvertBufferedImage.convertTo(spatialBlur, null);
BufferedImage blurredOut = ConvertBufferedImage.convertTo(blurredImage, null);
ListDisplayPanel listPanel = new ListDisplayPanel();
listPanel.addImage(originOut, "Original Image");
listPanel.addImage(spacialOut, "Spacial Domain Box");
listPanel.addImage(blurredOut, "Frequency Domain Box");
ShowImages.showWindow(listPanel, "Box Blur in Spacial and Frequency Domain of Input Image");
}
Aggregations