Search in sources :

Example 41 with Planar

use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.

the class BatchDownSizeImage method main.

public static void main(String[] args) {
    parseArguments(args);
    ImageBase input = new GrayU8(1, 1);
    ImageBase small = null;
    int index = 0;
    int numDigits = BoofMiscOps.numDigits(images.size() - 1);
    String format = "%" + numDigits + "d";
    String format0 = "%0" + numDigits + "d";
    for (File f : images) {
        BufferedImage orig = UtilImageIO.loadImage(f.getPath());
        WritableRaster info = orig.getRaster();
        boolean missMatch = false;
        if (input.getWidth() != info.getWidth() || input.getHeight() != info.getHeight()) {
            missMatch = true;
        }
        if (info.getNumBands() == 1) {
            if (!(input instanceof ImageGray))
                missMatch = true;
        } else {
            if (!(input instanceof Planar)) {
                missMatch = true;
            } else if (info.getNumBands() != ((Planar) input).getNumBands()) {
                missMatch = true;
            }
        }
        if (missMatch) {
            // declare the BoofCV image to conver the input into
            if (info.getNumBands() == 1) {
                input = new GrayU8(info.getWidth(), info.getHeight());
            } else {
                input = new Planar<>(GrayU8.class, info.getWidth(), info.getHeight(), info.getNumBands());
            }
            // Now declare storage for the small image
            int smallHeight, smallWidth;
            if (useSide) {
                if (input.getWidth() > input.getHeight()) {
                    width = side;
                    height = 0;
                } else {
                    height = side;
                    width = 0;
                }
            }
            if (height == 0) {
                smallWidth = width;
                smallHeight = input.getHeight() * width / input.getWidth();
            } else if (width == 0) {
                smallWidth = input.getWidth() * height / input.getHeight();
                smallHeight = height;
            } else {
                smallWidth = width;
                smallHeight = height;
            }
            small = input.createNew(smallWidth, smallHeight);
        }
        System.out.printf(" " + format + " out of " + format + "   %s\n", index + 1, images.size(), f.getName());
        ConvertBufferedImage.convertFrom(orig, input, true);
        AverageDownSampleOps.down(input, small);
        String nout;
        if (rename) {
            nout = String.format("image" + format0 + ".png", index);
        } else {
            nout = f.getName();
            nout = nout.substring(0, nout.length() - 3) + "png";
        }
        File fout = new File(outputDir, nout);
        UtilImageIO.saveImage(small, fout.getPath());
        index++;
    }
    System.out.println("Done");
}
Also used : WritableRaster(java.awt.image.WritableRaster) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) ImageGray(boofcv.struct.image.ImageGray) File(java.io.File) ImageBase(boofcv.struct.image.ImageBase) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 42 with Planar

use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.

the class BatchRemoveLensDistortion method main.

public static void main(String[] args) {
    String inputPath, regex, pathIntrinsic, outputDir;
    AdjustmentType adjustmentType = AdjustmentType.FULL_VIEW;
    boolean rename = false;
    if (args.length >= 4) {
        int numFlags = args.length - 4;
        for (int i = 0; i < numFlags; i++) {
            if (args[i].compareToIgnoreCase("-rename") == 0) {
                rename = true;
            } else if (args[i].compareToIgnoreCase("-EXPAND") == 0) {
                adjustmentType = AdjustmentType.EXPAND;
            } else if (args[i].compareToIgnoreCase("-FULL_VIEW") == 0) {
                adjustmentType = AdjustmentType.FULL_VIEW;
            } else {
                System.err.println("Unknown flag " + args[i]);
            }
        }
        inputPath = args[numFlags];
        regex = args[numFlags + 1];
        pathIntrinsic = args[numFlags + 2];
        outputDir = args[numFlags + 3];
    } else {
        printHelpAndExit(args);
        System.exit(0);
        return;
    }
    System.out.println("AdjustmentType = " + adjustmentType);
    System.out.println("rename         = " + rename);
    System.out.println("input path     = " + inputPath);
    System.out.println("name regex     = " + regex);
    System.out.println("output dir     = " + outputDir);
    File fileOutputDir = new File(outputDir);
    if (!fileOutputDir.exists()) {
        if (!fileOutputDir.mkdirs()) {
            throw new RuntimeException("Output directory did not exist and failed to create it");
        } else {
            System.out.println("  created output directory");
        }
    }
    CameraPinholeRadial param = CalibrationIO.load(pathIntrinsic);
    CameraPinholeRadial paramAdj = new CameraPinholeRadial();
    List<File> files = Arrays.asList(UtilIO.findMatches(new File(inputPath), regex));
    Collections.sort(files);
    System.out.println("Found a total of " + files.size() + " matching files");
    Planar<GrayF32> distoredImg = new Planar<>(GrayF32.class, param.width, param.height, 3);
    Planar<GrayF32> undistoredImg = new Planar<>(GrayF32.class, param.width, param.height, 3);
    ImageDistort distort = LensDistortionOps.changeCameraModel(adjustmentType, BorderType.ZERO, param, new CameraPinhole(param), paramAdj, (ImageType) distoredImg.getImageType());
    CalibrationIO.save(paramAdj, new File(outputDir, "intrinsicUndistorted.yaml").getAbsolutePath());
    BufferedImage out = new BufferedImage(param.width, param.height, BufferedImage.TYPE_INT_RGB);
    int numDigits = BoofMiscOps.numDigits(files.size() - 1);
    String format = "%0" + numDigits + "d";
    for (int i = 0; i < files.size(); i++) {
        File file = files.get(i);
        System.out.println("processing " + file.getName());
        BufferedImage orig = UtilImageIO.loadImage(file.getAbsolutePath());
        if (orig == null) {
            throw new RuntimeException("Can't load file: " + file.getAbsolutePath());
        }
        if (orig.getWidth() != param.width || orig.getHeight() != param.height) {
            System.err.println("intrinsic parameters and image size do not match!");
            System.exit(-1);
        }
        ConvertBufferedImage.convertFromPlanar(orig, distoredImg, true, GrayF32.class);
        distort.apply(distoredImg, undistoredImg);
        ConvertBufferedImage.convertTo(undistoredImg, out, true);
        String nameOut;
        if (rename) {
            nameOut = String.format("image" + format + ".png", i);
        } else {
            nameOut = file.getName().split("\\.")[0] + "_undistorted.png";
        }
        UtilImageIO.saveImage(out, new File(outputDir, nameOut).getAbsolutePath());
    }
}
Also used : ImageDistort(boofcv.alg.distort.ImageDistort) CameraPinhole(boofcv.struct.calib.CameraPinhole) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) AdjustmentType(boofcv.alg.distort.AdjustmentType) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Planar(boofcv.struct.image.Planar) File(java.io.File)

Example 43 with Planar

use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.

the class TestHistogramFeatureOps method histogram_PL_F32_compareToSingle.

/**
 * Compare to single band image.  Results should be identical
 */
@Test
public void histogram_PL_F32_compareToSingle() {
    GrayF32 image = new GrayF32(width, height);
    ImageMiscOps.fillUniform(image, rand, -100, 100);
    Planar<GrayF32> ms = new Planar<>(GrayF32.class, width, height, 1);
    ms.setBand(0, image);
    TupleDesc_F64 expected = new TupleDesc_F64(200);
    Histogram_F64 found = new Histogram_F64(200);
    found.setRange(0, -100, 100);
    HistogramFeatureOps.histogram(image, -100, 100, expected);
    HistogramFeatureOps.histogram_F32(ms, found);
    for (int i = 0; i < found.size(); i++) {
        assertEquals(expected.getDouble(i), found.getDouble(i), 1e-8);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) Planar(boofcv.struct.image.Planar) Test(org.junit.Test)

Example 44 with Planar

use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.

the class TestDescribePlanar method checkNumBands.

/**
 * Sanity check to see if input image and number of descriptors is the same
 */
@Test(expected = IllegalArgumentException.class)
public void checkNumBands() {
    DescribeRegionPoint[] descs = new DummyDesc[3];
    descs[0] = new DummyDesc();
    descs[1] = new DummyDesc();
    descs[2] = new DummyDesc();
    DummyAlg alg = new DummyAlg(descs);
    alg.setImage(new Planar(GrayS8.class, 1, 1, 2));
}
Also used : GrayS8(boofcv.struct.image.GrayS8) DescribeRegionPoint(boofcv.abst.feature.describe.DescribeRegionPoint) Planar(boofcv.struct.image.Planar) Test(org.junit.Test)

Example 45 with Planar

use of boofcv.struct.image.Planar in project BoofCV by lessthanoptimal.

the class TestDescribePointSurfPlanar method compareToSingleBand.

/**
 * Computes the descriptor inside a random image.  Sees if it has the expected results by comparing it to
 * the single band algorithm which it uses internally.
 */
@Test
public void compareToSingleBand() {
    Planar<GrayF32> input = new Planar<>(GrayF32.class, width, height, 3);
    GImageMiscOps.addUniform(input, rand, 0, 200);
    DescribePointSurf<GrayF32> desc = new DescribePointSurf<>(GrayF32.class);
    DescribePointSurfPlanar<GrayF32> alg = new DescribePointSurfPlanar<>(desc, 3);
    GrayF32 gray = ConvertImage.average(input, null);
    // input isn't an integral image, but I just want to see if it produces the expected results
    alg.setImage(gray, input);
    for (int i = 0; i < 100; i++) {
        double x = rand.nextDouble() * width;
        double y = rand.nextDouble() * height;
        double angle = rand.nextDouble() * Math.PI * 2;
        double scale = rand.nextDouble() * 10 + 0.9;
        BrightFeature found = alg.createDescription();
        alg.describe(x, y, angle, scale, found);
        desc.setImage(gray);
        boolean expectedLaplace = desc.computeLaplaceSign((int) (x + 0.5), (int) (y + 0.5), scale);
        assertEquals(expectedLaplace, found.white);
        BrightFeature expected = desc.createDescription();
        for (int b = 0; b < 3; b++) {
            desc.setImage(input.getBand(b));
            desc.describe(x, y, angle, scale, expected);
            // should be off by a constant scale factor since it is normalized across all bands not just one
            double norm = 0;
            for (int j = 0; j < expected.size(); j++) {
                double v = found.getDouble(j + b * expected.size());
                norm += v * v;
            }
            norm = Math.sqrt(norm);
            for (int j = 0; j < expected.size(); j++) {
                assertEquals(expected.getDouble(j), found.getDouble(j + b * expected.size()) / norm, 1e-8);
            }
        }
    }
}
Also used : BrightFeature(boofcv.struct.feature.BrightFeature) GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Test(org.junit.Test)

Aggregations

Planar (boofcv.struct.image.Planar)73 Test (org.junit.Test)39 GrayF32 (boofcv.struct.image.GrayF32)34 GrayU8 (boofcv.struct.image.GrayU8)28 BufferedImage (java.awt.image.BufferedImage)21 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)20 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)12 File (java.io.File)9 Bitmap (android.graphics.Bitmap)4 ListDisplayPanel (boofcv.gui.ListDisplayPanel)4 ImageGray (boofcv.struct.image.ImageGray)4 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)3 LensDistortionUniversalOmni (boofcv.alg.distort.universal.LensDistortionUniversalOmni)3 MediaManager (boofcv.io.MediaManager)3 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 GrayU16 (boofcv.struct.image.GrayU16)3 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)3 Se3_F64 (georegression.struct.se.Se3_F64)3 DescribeRegionPoint (boofcv.abst.feature.describe.DescribeRegionPoint)2