Search in sources :

Example 16 with GrayF32

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;
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32)

Example 17 with GrayF32

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);
            }
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GImageGray(boofcv.core.image.GImageGray) FactoryGImageGray(boofcv.core.image.FactoryGImageGray) ImageGray(boofcv.struct.image.ImageGray) GrayU8(boofcv.struct.image.GrayU8)

Example 18 with GrayF32

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);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayS16(boofcv.struct.image.GrayS16) ImageGray(boofcv.struct.image.ImageGray) ImageBorder_F32(boofcv.core.image.border.ImageBorder_F32) ImageBorder_S32(boofcv.core.image.border.ImageBorder_S32)

Example 19 with GrayF32

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);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) GrayS16(boofcv.struct.image.GrayS16) ImageGray(boofcv.struct.image.ImageGray) ImageBorder_F32(boofcv.core.image.border.ImageBorder_F32) ImageBorder_S32(boofcv.core.image.border.ImageBorder_S32)

Example 20 with GrayF32

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);
            }
        }
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) Test(org.junit.Test)

Aggregations

GrayF32 (boofcv.struct.image.GrayF32)530 Test (org.junit.Test)291 BufferedImage (java.awt.image.BufferedImage)81 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)76 GrayU8 (boofcv.struct.image.GrayU8)49 Planar (boofcv.struct.image.Planar)34 ArrayList (java.util.ArrayList)28 ImageBorder_F32 (boofcv.core.image.border.ImageBorder_F32)20 ImageGray (boofcv.struct.image.ImageGray)20 File (java.io.File)20 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)19 Se3_F64 (georegression.struct.se.Se3_F64)18 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)17 GrayS8 (boofcv.struct.image.GrayS8)16 ListDisplayPanel (boofcv.gui.ListDisplayPanel)14 PathLabel (boofcv.io.PathLabel)14 Kernel2D_F32 (boofcv.struct.convolve.Kernel2D_F32)13 GrayS16 (boofcv.struct.image.GrayS16)13 GrayS32 (boofcv.struct.image.GrayS32)13 Point2D_F64 (georegression.struct.point.Point2D_F64)13