1 /** 2 * Copyright (c) 2011, The University of Southampton and the individual contributors. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * * Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * * Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * * Neither the name of the University of Southampton nor the names of its 16 * contributors may be used to endorse or promote products derived from this 17 * software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 package org.openimaj.demos; 31 32 import java.io.IOException; 33 import java.net.MalformedURLException; 34 import java.net.URL; 35 36 import org.openimaj.image.FImage; 37 import org.openimaj.image.ImageUtilities; 38 import org.openimaj.image.MBFImage; 39 import org.openimaj.image.feature.local.engine.DoGSIFTEngine; 40 import org.openimaj.image.feature.local.engine.DoGSIFTEngineOptions; 41 import org.openimaj.image.processing.convolution.FFastGaussianConvolve; 42 import org.openimaj.image.processor.SinglebandImageProcessor; 43 44 public class GaussPyr { 45 46 /** 47 * @param args 48 * @throws IOException 49 * @throws MalformedURLException 50 */ 51 public static void main(String[] args) throws MalformedURLException, IOException { 52 final MBFImage im = ImageUtilities.readMBF(new URL( 53 "http://fc01.deviantart.net/fs71/i/2013/102/4/a/erica_the_rhino__update_03_by_c_clancy-d61fznp.jpg")); 54 55 // final int[] ts = { 0, 1, 2, 4, 16, 32 }; 56 // for (final int t : ts) { 57 // final long t1 = System.currentTimeMillis(); 58 // final MBFImage proc = im.process(new FGaussianConvolve((float) 59 // Math.sqrt(t))); 60 // final long t2 = System.currentTimeMillis(); 61 // final MBFImage proc2 = im.process(new FFastGaussianConvolve((float) 62 // Math.sqrt(t), 5)); 63 // final long t3 = System.currentTimeMillis(); 64 // 65 // System.out.println(t + " slow " + (t2 - t1)); 66 // System.out.println(t + " fast " + (t3 - t2)); 67 // 68 // DisplayUtilities.display(proc.subtract(proc2).abs().threshold(1e-4f)); 69 // 70 // // ImageUtilities.write(proc, new File("/Users/jsh2/Desktop/level" + 71 // // t + ".png")); 72 // } 73 74 final DoGSIFTEngineOptions<FImage> opts = new 75 DoGSIFTEngineOptions<FImage>(); 76 final DoGSIFTEngineOptions<FImage> fastopts = new 77 DoGSIFTEngineOptions<FImage>() 78 { 79 @Override 80 public SinglebandImageProcessor<Float, FImage> 81 createGaussianBlur(float sigma) 82 { 83 return new FFastGaussianConvolve(sigma, 8); 84 } 85 }; 86 87 final DoGSIFTEngine sift = new DoGSIFTEngine(opts); 88 final DoGSIFTEngine fastsift = new DoGSIFTEngine(fastopts); 89 final FImage fimg = im.flatten(); 90 for (int i = 0; i < 10; i++) { 91 final long t1 = System.currentTimeMillis(); 92 System.out.println(sift.findFeatures(fimg).size()); 93 final long t2 = System.currentTimeMillis(); 94 System.out.println(fastsift.findFeatures(fimg).size()); 95 final long t3 = System.currentTimeMillis(); 96 97 System.out.println((t2 - t1) + " " + (t3 - t2)); 98 } 99 } 100 }