Search in sources :

Example 1 with InterpolationType

use of boofcv.alg.interpolate.InterpolationType in project BoofCV by lessthanoptimal.

the class ExampleInterpolation method main.

public static void main(String[] args) {
    String imagePath;
    imagePath = "eye01.jpg";
    // imagePath = "small_sunflower.jpg";
    BufferedImage buffered = UtilImageIO.loadImage(UtilIO.pathExample(imagePath));
    ListDisplayPanel gui = new ListDisplayPanel();
    gui.addImage(buffered, "Original");
    // For sake of simplicity assume it's a gray scale image.  Interpolation functions exist for planar and
    // interleaved color images too
    GrayF32 input = ConvertBufferedImage.convertFrom(buffered, (GrayF32) null);
    GrayF32 scaled = input.createNew(500, 500 * input.height / input.width);
    for (InterpolationType type : InterpolationType.values()) {
        // Create the single band (gray scale) interpolation function for the input image
        InterpolatePixelS<GrayF32> interp = FactoryInterpolation.createPixelS(0, 255, type, BorderType.EXTENDED, input.getDataType());
        // Tell it which image is being interpolated
        interp.setImage(input);
        // the same thing and is slightly more efficient
        for (int y = 0; y < scaled.height; y++) {
            // iterate using the 1D index for added performance.  Altertively there is the set(x,y) operator
            int indexScaled = scaled.startIndex + y * scaled.stride;
            float origY = y * input.height / (float) scaled.height;
            for (int x = 0; x < scaled.width; x++) {
                float origX = x * input.width / (float) scaled.width;
                scaled.data[indexScaled++] = interp.get(origX, origY);
            }
        }
        // Add the results to the output
        BufferedImage out = ConvertBufferedImage.convertTo(scaled, null, true);
        gui.addImage(out, type.toString());
    }
    ShowImages.showWindow(gui, "Example Interpolation", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) GrayF32(boofcv.struct.image.GrayF32) InterpolationType(boofcv.alg.interpolate.InterpolationType) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

InterpolationType (boofcv.alg.interpolate.InterpolationType)1 ListDisplayPanel (boofcv.gui.ListDisplayPanel)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 GrayF32 (boofcv.struct.image.GrayF32)1 BufferedImage (java.awt.image.BufferedImage)1