use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class ColorYuv method yuvToRgb_F32.
/**
* Convert a 3-channel {@link Planar} image from YUV into RGB.
*
* @param rgb (Input) RGB encoded image
* @param yuv (Output) YUV encoded image
*/
public static void yuvToRgb_F32(Planar<GrayF32> yuv, Planar<GrayF32> rgb) {
InputSanityCheck.checkSameShape(yuv, rgb);
GrayF32 Y = yuv.getBand(0);
GrayF32 U = yuv.getBand(1);
GrayF32 V = yuv.getBand(2);
GrayF32 R = rgb.getBand(0);
GrayF32 G = rgb.getBand(1);
GrayF32 B = rgb.getBand(2);
for (int row = 0; row < yuv.height; row++) {
int indexYuv = yuv.startIndex + row * yuv.stride;
int indexRgb = rgb.startIndex + row * rgb.stride;
for (int col = 0; col < yuv.width; col++, indexYuv++, indexRgb++) {
float y = Y.data[indexYuv];
float u = U.data[indexYuv];
float v = V.data[indexYuv];
R.data[indexRgb] = y + 1.13983f * v;
G.data[indexRgb] = y - 0.39465f * u - 0.58060f * v;
B.data[indexRgb] = y + 2.032f * u;
}
}
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class TestThresholdImageOps method naiveLocalSquare.
public void naiveLocalSquare(ImageGray input, GrayU8 output, int radius, double scale, boolean down) {
ImageGray blur;
boolean isInt;
if (input instanceof GrayU8) {
isInt = true;
blur = BlurImageOps.mean((GrayU8) input, null, radius, null);
} else {
isInt = false;
blur = BlurImageOps.mean((GrayF32) input, null, radius, null);
}
float fscale = (float) scale;
for (int y = 0; y < input.height; y++) {
for (int x = 0; x < input.width; x++) {
double threshold = GeneralizedImageOps.get(blur, x, y);
double v = GeneralizedImageOps.get(input, x, y);
boolean one;
if (down) {
if (isInt) {
one = (int) v <= ((int) threshold) * fscale;
} else {
one = v <= threshold * fscale;
}
} else {
if (isInt) {
one = ((int) v) * fscale > (int) threshold;
} else {
one = v * fscale > threshold;
}
}
if (one) {
output.set(x, y, 1);
} else {
output.set(x, y, 0);
}
}
}
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class TestImplEnhanceFilter method sharpenBorder4.
public void sharpenBorder4(ImageGray input, ImageGray output) {
ImageGray expected;
GImageMiscOps.fillUniform(input, rand, 0, 10);
if (input.getDataType().isInteger()) {
BoofTesting.callStaticMethod(ImplEnhanceFilter.class, "sharpenBorder4", input, output, 0, 255);
expected = new GrayS16(input.width, input.height);
ImageBorder_S32 border = BoofDefaults.borderDerivative_I32();
border.setImage(input);
ConvolveJustBorder_General_SB.convolve(ImplEnhanceFilter.kernelEnhance4_I32, border, (GrayS16) expected);
GPixelMath.boundImage(expected, 0, 255);
} else {
BoofTesting.callStaticMethod(ImplEnhanceFilter.class, "sharpenBorder4", input, output, 0f, 255f);
expected = new GrayF32(input.width, input.height);
ImageBorder_F32 border = BoofDefaults.borderDerivative_F32();
border.setImage((GrayF32) input);
ConvolveJustBorder_General_SB.convolve(ImplEnhanceFilter.kernelEnhance4_F32, border, (GrayF32) expected);
GPixelMath.boundImage(expected, 0, 255);
}
BoofTesting.assertEquals(expected, output, 1e-5);
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class TestImplEnhanceFilter method sharpenBorder8.
public void sharpenBorder8(ImageGray input, ImageGray output) {
ImageGray expected;
GImageMiscOps.fillUniform(input, rand, 0, 10);
if (input.getDataType().isInteger()) {
BoofTesting.callStaticMethod(ImplEnhanceFilter.class, "sharpenBorder8", input, output, 0, 255);
expected = new GrayS16(input.width, input.height);
ImageBorder_S32 border = BoofDefaults.borderDerivative_I32();
border.setImage(input);
ConvolveJustBorder_General_SB.convolve(ImplEnhanceFilter.kernelEnhance8_I32, border, (GrayS16) expected);
GPixelMath.boundImage(expected, 0, 255);
} else {
BoofTesting.callStaticMethod(ImplEnhanceFilter.class, "sharpenBorder8", input, output, 0f, 255f);
expected = new GrayF32(input.width, input.height);
ImageBorder_F32 border = BoofDefaults.borderDerivative_F32();
border.setImage((GrayF32) input);
ConvolveJustBorder_General_SB.convolve(ImplEnhanceFilter.kernelEnhance8_F32, border, (GrayF32) expected);
GPixelMath.boundImage(expected, 0, 255);
}
BoofTesting.assertEquals(expected, output, 1e-5);
}
use of boofcv.struct.image.GrayF32 in project BoofCV by lessthanoptimal.
the class TestDistortImageOps method scale_InterpTypeStyle.
/**
* Checks to see if the two ways of specifying interpolation work
*/
@Test
public void scale_InterpTypeStyle() {
GrayF32 input = new GrayF32(width, height);
GrayF32 output = new GrayF32(width, height);
GImageMiscOps.fillUniform(input, rand, 0, 100);
DistortImageOps.scale(input, output, BorderType.ZERO, InterpolationType.BILINEAR);
InterpolatePixelS<GrayF32> interp = FactoryInterpolation.bilinearPixelS(input, BorderType.EXTENDED);
interp.setImage(input);
float scaleX = (float) input.width / (float) output.width;
float scaleY = (float) input.height / (float) output.height;
if (input.getDataType().isInteger()) {
for (int i = 0; i < output.height; i++) {
for (int j = 0; j < output.width; j++) {
float val = interp.get(j * scaleX, i * scaleY);
assertEquals((int) val, output.get(j, i), 1e-4);
}
}
} else {
for (int i = 0; i < output.height; i++) {
for (int j = 0; j < output.width; j++) {
float val = interp.get(j * scaleX, i * scaleY);
assertEquals(val, output.get(j, i), 1e-4);
}
}
}
}
Aggregations