001/** 002 * Copyright (c) 2011, The University of Southampton and the individual contributors. 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, 006 * are permitted provided that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, 009 * this list of conditions and the following disclaimer. 010 * 011 * * Redistributions in binary form must reproduce the above copyright notice, 012 * this list of conditions and the following disclaimer in the documentation 013 * and/or other materials provided with the distribution. 014 * 015 * * Neither the name of the University of Southampton nor the names of its 016 * contributors may be used to endorse or promote products derived from this 017 * software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030package org.openimaj.demos.sandbox; 031 032import java.io.File; 033import java.io.IOException; 034 035import javax.swing.JFrame; 036 037import org.openimaj.demos.utils.FeatureClickListener; 038import org.openimaj.feature.local.list.LocalFeatureList; 039import org.openimaj.feature.local.list.MemoryLocalFeatureList; 040import org.openimaj.image.DisplayUtilities; 041import org.openimaj.image.FImage; 042import org.openimaj.image.ImageUtilities; 043import org.openimaj.image.MBFImage; 044import org.openimaj.image.colour.RGBColour; 045import org.openimaj.image.colour.Transforms; 046import org.openimaj.image.feature.local.detector.ipd.collector.CircularInterestPointKeypoint; 047import org.openimaj.image.feature.local.engine.ipd.AbstractIPDSIFTEngine; 048import org.openimaj.image.feature.local.engine.ipd.EllipticIPDSIFTEngine; 049import org.openimaj.image.feature.local.engine.ipd.FinderMode; 050import org.openimaj.image.feature.local.interest.AffineAdaption; 051import org.openimaj.image.feature.local.interest.EllipticInterestPointData; 052import org.openimaj.image.feature.local.interest.HarrisIPD; 053import org.openimaj.image.feature.local.interest.IPDSelectionMode; 054import org.openimaj.image.feature.local.interest.InterestPointData; 055import org.openimaj.image.feature.local.interest.InterestPointVisualiser; 056import org.openimaj.image.feature.local.keypoints.InterestPointKeypoint; 057import org.openimaj.io.IOUtils; 058 059public class ImageIPDSIFTEngine { 060 061 public static void main(String[] args) throws IOException { 062 MBFImage image = ImageUtilities.readMBF(ImageIPDSIFTEngine.class.getResourceAsStream("/org/openimaj/image/feature/validator/graf/img1.ppm")); 063 FImage fimage = Transforms.calculateIntensity(image); 064 065 File featureOut = new File("/tmp/img1.oi-sift-features"); 066 LocalFeatureList<? extends InterestPointKeypoint<? extends InterestPointData>> kps = null; 067 boolean force = true; 068 HarrisIPD harrisIPD = new HarrisIPD(1.4f); 069 harrisIPD.setImageBlurred(true); 070 AffineAdaption affineIPD = new AffineAdaption(harrisIPD,new IPDSelectionMode.Threshold(250f)); 071 affineIPD.setFastDifferentiationScale(true); 072 AbstractIPDSIFTEngine<EllipticInterestPointData> engine = new EllipticIPDSIFTEngine(affineIPD); 073 engine.setFinderMode(new FinderMode.Basic<EllipticInterestPointData>()); 074// engine.setFinderMode(new FinderMode.Basic<InterestPointData>()); 075// engine.setSelectionMode(new IPDSelectionMode.Threshold(10000f)); 076 engine.setSelectionMode(new IPDSelectionMode.All()); 077 engine.setAcrossScales(true); 078 if (!featureOut.exists() || force) { 079 kps = engine.findFeatures(fimage); 080 IOUtils.writeBinary(featureOut, kps); 081 } else { 082 kps = MemoryLocalFeatureList.read(featureOut, 083 CircularInterestPointKeypoint.class); 084 } 085 086 InterestPointVisualiser<Float[], MBFImage> visualiser = InterestPointVisualiser 087 .visualiseKeypoints(image, kps); 088 MBFImage out = visualiser.drawPatches(RGBColour.RED, RGBColour.GREEN); 089 090 JFrame f = DisplayUtilities.display(out); 091 FeatureClickListener l = new FeatureClickListener(); 092 l.setImage(kps, image); 093 l.setDisplayFrame(f); 094 f.getContentPane().addMouseListener(l); 095 096 } 097}