Example Non Maximum Suppression

Non-maximum suppression is a class of algorithm used to find local peaks and minimums inside a feature intensity image. This example demonstrations how to use efficient algorithms inside of BoofCV to quickly find extremes.
Example Code:

Example Code

/** * Non-maximum suppression is used to identify local maximums and/or minimums in an image feature intensity map. This * is a common step in feature detection. BoofCV includes an implementation of non-maximum suppression which is much * faster than the naive algorithm that is often used because of its ease of implementation. The following code * demonstrates how some of the tuning parameters affects the final output. * * @author Peter Abeles */publicclassExampleNonMaximumSupression{publicstaticBufferedImagerenderNonMax(GrayF32intensity,intradius,floatthreshold){// Create and configure the feature detectorNonMaxSuppressionnonmax=FactoryFeatureExtractor.nonmax(newConfigExtract(radius,threshold));// We will only searching for the maximums. Other variants will look for minimums or will exclude previous// candidate detections from being detected twiceQueueCornermaximums=newQueueCorner();nonmax.process(intensity,null,null,null,maximums);// Visualize the intensity imageBufferedImageoutput=newBufferedImage(intensity.width,intensity.height,BufferedImage.TYPE_INT_RGB);VisualizeImageData.colorizeSign(intensity,output,-1);// render each maximum with a circleGraphics2Dg2=output.createGraphics();g2.setColor(Color.blue);for(inti=0;i<maximums.size();i++){Point2D_I16c=maximums.get(i);VisualizeFeatures.drawCircle(g2,c.x,c.y,radius);}returnoutput;}publicstaticvoidmain(String[]args){BufferedImagebuffered=UtilImageIO.loadImage(UtilIO.pathExample("standard/boat.jpg"));GrayF32input=ConvertBufferedImage.convertFrom(buffered,(GrayF32)null);// Compute the image gradientGrayF32derivX=input.createSameShape();GrayF32derivY=input.createSameShape();GImageDerivativeOps.gradient(DerivativeType.SOBEL,input,derivX,derivY,BorderType.EXTENDED);// From the gradient compute intensity of shi-tomasi featuresGeneralFeatureIntensity<GrayF32,GrayF32>featureIntensity=FactoryIntensityPoint.shiTomasi(3,false,GrayF32.class);featureIntensity.process(input,derivX,derivY,null,null,null);GrayF32intensity=featureIntensity.getIntensity();ListDisplayPanelpanel=newListDisplayPanel();panel.addImage(buffered,"Input Image");// hack to just show intensity - no features can be detectedpanel.addImage(renderNonMax(intensity,10,Float.MAX_VALUE),"Intensity Image");// Detect maximums with different settings and visualize the resultspanel.addImage(renderNonMax(intensity,3,-Float.MAX_VALUE),"Radius 3");panel.addImage(renderNonMax(intensity,3,30000),"Radius 3 threshold");panel.addImage(renderNonMax(intensity,20,-Float.MAX_VALUE),"Radius 10");panel.addImage(renderNonMax(intensity,20,30000),"Radius 10 threshold");ShowImages.showWindow(panel,"Non-Maximum Suppression",true);}}