Search in sources :

Example 1 with InterestPointDetector

use of boofcv.abst.feature.detect.interest.InterestPointDetector in project BoofCV by lessthanoptimal.

the class DetectPointScaleOriWithNoiseApp method setActiveAlgorithm.

@Override
public synchronized void setActiveAlgorithm(int indexFamily, String name, Object cookie) {
    if (input == null)
        return;
    // corrupt the input image
    corruptPanel.corruptImage(grayImage, corruptImage);
    final InterestPointDetector<T> det = (InterestPointDetector<T>) cookie;
    det.detect(corruptImage);
    render.reset();
    for (int i = 0; i < det.getNumberOfFeatures(); i++) {
        Point2D_F64 p = det.getLocation(i);
        int radius = (int) Math.ceil(det.getRadius(i));
        render.addCircle((int) p.x, (int) p.y, radius);
    }
    SwingUtilities.invokeLater(() -> {
        ConvertBufferedImage.convertTo(corruptImage, workImage, true);
        Graphics2D g2 = workImage.createGraphics();
        g2.setStroke(new BasicStroke(3));
        render.draw(g2);
        panel.repaint();
    });
}
Also used : InterestPointDetector(boofcv.abst.feature.detect.interest.InterestPointDetector) Point2D_F64(georegression.struct.point.Point2D_F64) FactoryInterestPoint(boofcv.factory.feature.detect.interest.FactoryInterestPoint)

Example 2 with InterestPointDetector

use of boofcv.abst.feature.detect.interest.InterestPointDetector in project narchy by automenta.

the class RasterHierarchy method rasterizeImage.

// /**
// * Generate the raster hierarchy for a given image.
// *
// * @param input The image to rasterize
// * @return The rasterized image.
// */
// 
// public class Value {
// public int x;
// public int y;
// public float r, g, b;
// public float diff;
// 
// public Value() {
// }
// 
// public void set(float r, float g, float b, int xsize, int ysize, int x, int y) {
// this.x = x;
// this.y = y;
// 
// float dr = (r - (this.r));
// float dg = (g - (this.g));
// float db = (b - (this.b));
// float newDiff = (dr * dr + dg * dg + db * db) * xsize * ysize;
// if (this.diff < newDiff) {
// this.diff = newDiff;
// this.r = r;
// this.g = g;
// this.b = b;
// }
// }
// 
// @Override
// public String toString() {
// return x + "," + y + ":" + r + "=" + diff;
// }
// 
// public void fade() {
// diff *= 0.9f;
// }
// }
public synchronized BufferedImage rasterizeImage(BufferedImage input) {
    if (input == null)
        return null;
    // voter.clear();
    // vladimir
    boolean putin = false;
    cnt--;
    if (cnt == 0) {
        putin = true;
        cnt = updaterate;
    }
    long ntime = nar.time();
    float red, green, blue;
    int redSum, greenSum, blueSum;
    int x, y, startX, startY;
    float newX, newY;
    int width = input.getWidth();
    int height = input.getHeight();
    float fblockXSize = width / divisions;
    float fblockYSize = height / divisions;
    multiInputImg = ConvertBufferedImage.convertFromMulti(input, multiInputImg, true, ImageUInt8.class);
    final ImageUInt8 ib0 = multiInputImg.getBand(0);
    final ImageUInt8 ib1 = multiInputImg.getBand(1);
    final ImageUInt8 ib2 = multiInputImg.getBand(2);
    MultiSpectral<ImageUInt8> output = new MultiSpectral<>(ImageUInt8.class, width, height, 3);
    BufferedImage rasterizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    // Set the initial raster region
    float regionWidth = width, regionHeight = height;
    newX = 0;
    newY = 0;
    startX = 0;
    startY = 0;
    for (int step = 1; step <= numberRasters; step++) {
        if (step > 1) {
            newX = startX + (regionWidth - regionWidth / scalingFactor) / scalingFactor;
            newY = startY + (regionHeight - regionHeight / scalingFactor) / scalingFactor;
            if (newX < 0) {
                newX = 0;
            }
            if (newY < 0) {
                newY = 0;
            }
            regionWidth = regionWidth / scalingFactor;
            regionHeight = regionHeight / scalingFactor;
            fblockXSize = fblockXSize / scalingFactor;
            fblockYSize = fblockYSize / scalingFactor;
            if (fblockXSize < 1) {
                fblockXSize = 1;
            }
            if (fblockYSize < 1) {
                fblockYSize = 1;
            }
        }
        // Set the starting point for the next step
        startX = Math.round(this.focusPoint.getX() - ((regionWidth) / 2));
        startY = Math.round(this.focusPoint.getY() - ((regionHeight) / 2));
        int blockXSize = Math.round(fblockXSize);
        int blockYSize = Math.round(fblockYSize);
        // Number of pixels per block
        float pixelCount = blockXSize * blockYSize;
        int h = 0, j = 0;
        // StringBuilder to hold the Narsese translation
        for (x = Math.round(newX); x < ((step == 1 ? 0 : startX) + regionWidth); x += blockXSize) {
            h++;
            for (y = Math.round(newY); y < ((step == 1 ? 0 : startY) + regionHeight); y += blockYSize) {
                j++;
                redSum = 0;
                greenSum = 0;
                blueSum = 0;
                for (int pixelX = 0; (pixelX < blockXSize) && (x + pixelX < width); pixelX++) {
                    for (int pixelY = 0; (pixelY < blockYSize) && (y + pixelY < height); pixelY++) {
                        redSum += ib0.get(x + pixelX, y + pixelY);
                        greenSum += ib1.get(x + pixelX, y + pixelY);
                        blueSum += ib2.get(x + pixelX, y + pixelY);
                    }
                }
                red = redSum / pixelCount;
                green = greenSum / pixelCount;
                blue = blueSum / pixelCount;
                float fred = red / 256.0f;
                // was: red / 255f
                float fgreen = green / 256.0f;
                // was: blue/255f
                float fblue = blue / 256.0f;
                // manage move heuristic
                // maybe not needed
                float brightness = (red + green + blue) / 3;
                // int key=step+10*x+10000*y;
                // int key = (step * (int)pixelCount) + y * frameWidth + x;
                int key = /*(step * (int)pixelCount) +*/
                y * frameWidth + x;
                if (putin) {
                // Value value = voter.get(key);
                // 
                // if (value == null) {
                // value = new Value();
                // voter.put(key, value);
                // }
                // 
                // value.set(fred, fgreen, fblue, blockXSize, blockYSize,
                // x + blockXSize / 2,
                // y + blockYSize / 2
                // );
                }
                if (putin && /* && step == numberRasters)*/
                (ntime != lastInputTime)) {
                    // input Narsese translation, one statement for each band.
                    // ArrayList<String> nalStrings = new ArrayList<String>();
                    // nalStrings.add("<(*,r"+ String.valueOf(step)+","+String.valueOf(h)+","+String.valueOf(j)+") --> RED>. :|: %"+String.valueOf(fred)+System.getProperty("line.separator"));
                    // nalStrings.add("<(*,r" + String.valueOf(step) + "," + String.valueOf(h) + "," + String.valueOf(j) + ") --> GREEN>. :|: %" + String.valueOf(fgreen) + System.getProperty("line.separator"));
                    // nalStrings.add("<(*,r"+ String.valueOf(step)+","+String.valueOf(h)+","+String.valueOf(j)+") --> BLUE>. :|: %"+String.valueOf(fblue)+System.getProperty("line.separator"));
                    /* Here we use the gamma corrected, grayscale version of the image.  Use CCIR 601 weights to convert.
                         * If it is desirable to use only one sentence (vs RGB for example) then use this.
                         *  see: https://en.wikipedia.org/wiki/Luma_%28video%29 or http://cadik.posvete.cz/color_to_gray_evaluation */
                    float dgray = 0.2989f * red + 0.5870f * green + 0.1140f * blue;
                    dgray /= 256.0f;
                    // TODO create the Term / Task programmaticaly
                    // nar.input("<(*,r" + String.valueOf(step) + "," + String.valueOf(h) + "," + String.valueOf(j) + ") --> GRAY>. :|: %" + String.valueOf(dgray) + System.getProperty("line.separator"));
                    input(h, j, fblockXSize, fblockYSize, dgray);
                }
                ImageMiscOps.fillRectangle(output.getBand(0), Math.round(red), x, y, blockXSize, blockYSize);
                ImageMiscOps.fillRectangle(output.getBand(1), Math.round(green), x, y, blockXSize, blockYSize);
                ImageMiscOps.fillRectangle(output.getBand(2), Math.round(blue), x, y, blockXSize, blockYSize);
            }
        }
    }
    // //search for maximum vote to move heuristic
    // if (putin) {
    // final Value[] maxvalue = {null};
    // float threshold = 0.05f;
    // voter.forEachKeyValue((key, value) -> {
    // if (maxvalue[0] == null || value.diff > maxvalue[0].diff) {
    // if (value.diff > threshold)
    // maxvalue[0] = value;
    // }
    // value.fade();
    // });
    // 
    // 
    // Value maxValue = maxvalue[0];
    // if (maxValue != null && maxValue.x != 0 && maxValue.y != 0) {
    // this.setFocus(maxValue.x, maxValue.y);
    // }
    // 
    // }
    lastInputTime = ntime;
    ConvertBufferedImage.convertTo(output, rasterizedImage, true);
    // Create a Fast Hessian detector from the SURF paper.
    // Other detectors can be used in this example too.
    InterestPointDetector detector = FactoryInterestPoint.fastHessian(new ConfigFastHessian(4, 2, 8, 2, 9, 3, 8));
    // find interest points in the image
    detector.detect(ib0);
    displayResults(rasterizedImage, detector, Color.RED);
    // find interest points in the image
    detector.detect(ib1);
    displayResults(rasterizedImage, detector, Color.BLUE);
    // find interest points in the image
    detector.detect(ib2);
    displayResults(rasterizedImage, detector, Color.GREEN);
    return rasterizedImage;
}
Also used : ImageUInt8(boofcv.struct.image.ImageUInt8) MultiSpectral(boofcv.struct.image.MultiSpectral) ConfigFastHessian(boofcv.abst.feature.detect.interest.ConfigFastHessian) InterestPointDetector(boofcv.abst.feature.detect.interest.InterestPointDetector) FactoryInterestPoint(boofcv.factory.feature.detect.interest.FactoryInterestPoint) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.core.image.ConvertBufferedImage)

Example 3 with InterestPointDetector

use of boofcv.abst.feature.detect.interest.InterestPointDetector in project BoofCV by lessthanoptimal.

the class TestDetectDescribeFusion method checkFeatureNotInBounds.

/**
 * If a feature is not in bounds make sure everything is handled correctly
 */
@Test
void checkFeatureNotInBounds() {
    InterestPointDetector detector = new DummyDetector();
    DescribePointRadiusAngle describe = new DummyRegionPoint();
    DetectDescribeFusion alg = new DetectDescribeFusion(detector, null, describe);
    alg.detect(new GrayF32(2, 2));
    // one feature should not be inside the image
    assertEquals(9, alg.getNumberOfFeatures());
    for (int i = 0; i < 9; i++) {
        assertEquals(2, alg.getRadius(i), 1e-8);
        assertEquals(1, alg.getOrientation(i), 1e-8);
        assertTrue(alg.getDescription(i) != null);
        assertTrue(alg.getLocation(i) != null);
    }
}
Also used : GrayF32(boofcv.struct.image.GrayF32) InterestPointDetector(boofcv.abst.feature.detect.interest.InterestPointDetector) DescribePointRadiusAngle(boofcv.abst.feature.describe.DescribePointRadiusAngle) FactoryDescribePointRadiusAngle(boofcv.factory.feature.describe.FactoryDescribePointRadiusAngle) FactoryInterestPoint(boofcv.factory.feature.detect.interest.FactoryInterestPoint) Test(org.junit.jupiter.api.Test)

Example 4 with InterestPointDetector

use of boofcv.abst.feature.detect.interest.InterestPointDetector in project BoofCV by lessthanoptimal.

the class ExampleDetectDescribe method createFromComponents.

/**
 * Any arbitrary implementation of InterestPointDetector, OrientationImage, DescribeRegionPoint
 * can be combined into DetectDescribePoint. The syntax is more complex, but the end result is more flexible.
 * This should only be done if there isn't a pre-made DetectDescribePoint.
 */
public static <T extends ImageGray<T>, TD extends TupleDesc<TD>> DetectDescribePoint<T, TD> createFromComponents(Class<T> imageType) {
    // create a corner detector
    Class derivType = GImageDerivativeOps.getDerivativeType(imageType);
    GeneralFeatureDetector corner = FactoryDetectPoint.createShiTomasi(new ConfigGeneralDetector(1000, 5, 1), null, derivType);
    InterestPointDetector detector = FactoryInterestPoint.wrapPoint(corner, 1, imageType, derivType);
    // describe points using BRIEF
    DescribePointRadiusAngle describe = FactoryDescribePointRadiusAngle.brief(new ConfigBrief(true), imageType);
    // NOTE: orientation will not be estimated
    return FactoryDetectDescribe.fuseTogether(detector, null, describe);
}
Also used : ConfigBrief(boofcv.abst.feature.describe.ConfigBrief) InterestPointDetector(boofcv.abst.feature.detect.interest.InterestPointDetector) GeneralFeatureDetector(boofcv.alg.feature.detect.interest.GeneralFeatureDetector) DescribePointRadiusAngle(boofcv.abst.feature.describe.DescribePointRadiusAngle) FactoryDescribePointRadiusAngle(boofcv.factory.feature.describe.FactoryDescribePointRadiusAngle) ConfigGeneralDetector(boofcv.abst.feature.detect.interest.ConfigGeneralDetector)

Aggregations

InterestPointDetector (boofcv.abst.feature.detect.interest.InterestPointDetector)4 FactoryInterestPoint (boofcv.factory.feature.detect.interest.FactoryInterestPoint)3 DescribePointRadiusAngle (boofcv.abst.feature.describe.DescribePointRadiusAngle)2 FactoryDescribePointRadiusAngle (boofcv.factory.feature.describe.FactoryDescribePointRadiusAngle)2 ConfigBrief (boofcv.abst.feature.describe.ConfigBrief)1 ConfigFastHessian (boofcv.abst.feature.detect.interest.ConfigFastHessian)1 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)1 GeneralFeatureDetector (boofcv.alg.feature.detect.interest.GeneralFeatureDetector)1 ConvertBufferedImage (boofcv.core.image.ConvertBufferedImage)1 GrayF32 (boofcv.struct.image.GrayF32)1 ImageUInt8 (boofcv.struct.image.ImageUInt8)1 MultiSpectral (boofcv.struct.image.MultiSpectral)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1 BufferedImage (java.awt.image.BufferedImage)1 Test (org.junit.jupiter.api.Test)1