Commit 70e6fedc authored by danyfel80's avatar danyfel80

Version 1.0.0

First code commit
parent 60c56bf4
# org.bioimageanalysis.icy.surf
# SURF - Speeded Up Robust Features
Surf feature matching
\ No newline at end of file
This repository contains the code used for the plugin Match SURF Features and Extract SURF Features.
This two plugins are available as both Interface plugins and Protocols blocks.
The project has been prepared using gradle and eclipse to simplify project configuration. See below to setup this project on your machine.
## Installation
### Requirements
In order to be able to work with this project you must have installed the following software:
- **Icy**, version 1.9.5.1 or above. ( [Available here](http://icy.bioimageanalysis.org) )
- The following plugins should be already installed in order to use the SURF project:
- EzPlug SDK
- Protocols SDK
- **Eclipse**, version _Neon_ or above. Make sure to have the _Buildship_ plugin installed. ([Available here](http://www.eclipse.org/downloads/))
- **Icy4Eclipse** plugin for Eclipse, the latest version available. Follow [these](http://icy.bioimageanalysis.org/index.php?display=startDevWithIcy) instructions.
### Setup
1. Use your *Git* repository manager of preference to download this repository (even Eclipse can do this). The repository URL is [https://gitlab.pasteur.fr/bia/org.bioimageanalysis.icy.surf.git](https://gitlab.pasteur.fr/bia/org.bioimageanalysis.icy.surf.git).
2. Make sure the environment variable **ICY_HOME** is set to the location of your Icy installation. _**Note**: This could be tricky on Mac so make sure to follow [these](https://stackoverflow.com/questions/829749/launch-mac-eclipse-with-environment-variables-set) instructions._
3. Open Eclipse and select the menu *File > Import...* Then select *Gradle > Existing Gradle Project*. Click *Next* the project root directory is demanded select the folder **org.bioimageanalysis.icy.surf** inside the folder you downloaded the at. Finally, click *Finish* to create the project in eclipse.
Eclipse will download the dependencies specified in the *gradle.build* file. When it finishes you should see the project without any problem on the project explorer of Eclipse. *If this is not the case, check that the environment variable ICY_HOME is correctly defined.*
\ No newline at end of file
/.settings/
/.gradle/
/bin/
/build/
.classpath
.project
println "ICY_HOME=${System.env.ICY_HOME}"
apply plugin: 'java-library'
apply plugin: 'eclipse'
version = '1.0.0'
configurations {
extraLibs // configuration that holds jars to include in the jar
}
// In this section you declare where to find the dependencies of your project
repositories {
jcenter()
}
dependencies {
extraLibs 'org.apache.commons:commons-math3:3.0' // Apache Math
configurations.implementation.extendsFrom(configurations.extraLibs)
implementation files("${System.env.ICY_HOME}/icy.jar") // Icy
implementation files("${System.env.ICY_HOME}/plugins/adufour/ezplug/EzPlug.jar") // EzPlug
implementation files("${System.env.ICY_HOME}/plugins/adufour/blocks/Blocks.jar") // Blocks
implementation files("${System.env.ICY_HOME}/plugins/adufour/protocols/Protocols.jar") // Protocols
implementation files("${System.env.ICY_HOME}/lib/bioformats.jar") // Bioformats
implementation files("${System.env.ICY_HOME}/lib/jai_core.jar") // JAI
testImplementation 'junit:junit:4.12'
testImplementation 'org.hamcrest:hamcrest-all:1.3' // Hamcrest
}
eclipse {
classpath.downloadJavadoc = true
project {
natures += ['icy.icy4eclipse.core.icynature']
}
}
jar {
from {
configurations.extraLibs.collect { it.isDirectory() ? it : zipTree(it) }
}
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.output
from sourceSets.main.java
from configurations.extraLibs.collect { it.isDirectory() ? it : zipTree(it) }
}
artifacts {
archives sourcesJar
}
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-bin.zip
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
/*
* This settings file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
* In a single project build this file can be empty or even removed.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user guide at https://docs.gradle.org/4.3/userguide/multi_project_builds.html
*/
/*
// To declare projects as part of a multi-project build use the 'include' method
include 'shared'
include 'api'
include 'services:webservice'
*/
rootProject.name = 'org.bioimageanalysis.icy.surf'
package org.bioimageanalysis.icy.surf;
public class KeyPoint {
private double x, y;
private double scale;
private double orientation;
private boolean laplacianSignPositive;
public KeyPoint(double x, double y, double scale, double orientation, boolean laplacianSign) {
this.x = x;
this.y = y;
this.scale = scale;
this.orientation = orientation;
this.laplacianSignPositive = laplacianSign;
}
public KeyPoint(KeyPoint keyPoint) {
this.x = keyPoint.getX();
this.y = keyPoint.getY();
this.scale = keyPoint.getScale();
this.orientation = keyPoint.getOrientation();
this.laplacianSignPositive = keyPoint.isLaplacianSignPositive();
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getScale() {
return scale;
}
public double getOrientation() {
return orientation;
}
public boolean isLaplacianSignPositive() {
return laplacianSignPositive;
}
@Override
public String toString() {
return String.format("Key point [x=%f, y=%f, scale=%f, orientation=%f, laplacianSignPositive=%b]", x, y, scale, orientation,
laplacianSignPositive);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (laplacianSignPositive ? 1231 : 1237);
long temp;
temp = Double.doubleToLongBits(orientation);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(scale);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(x);
result = prime * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(y);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof KeyPoint)) {
return false;
}
KeyPoint other = (KeyPoint) obj;
if (laplacianSignPositive != other.laplacianSignPositive) {
return false;
}
if (Double.doubleToLongBits(orientation) != Double.doubleToLongBits(other.orientation)) {
return false;
}
if (Double.doubleToLongBits(scale) != Double.doubleToLongBits(other.scale)) {
return false;
}
if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x)) {
return false;
}
if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y)) {
return false;
}
return true;
}
}
package org.bioimageanalysis.icy.surf;
import java.util.ArrayList;
import java.util.List;
import org.bioimageanalysis.icy.surf.image.ArrayImageIntegrator;
public class KeyPointDescriptor {
private static final int DESCRIPTOR_SECTOR_SIZE_1D = 4;
private static final int DESCRIPTOR_SECTOR_GRID_SIZE_2D = DESCRIPTOR_SECTOR_SIZE_1D * DESCRIPTOR_SECTOR_SIZE_1D;
public static List<KeyPointDescriptor> createDescriptors(ArrayImageIntegrator integrator,
List<KeyPoint> keyPoints) {
List<KeyPointDescriptor> descriptors = new ArrayList<>(keyPoints.size());
for (KeyPoint keyPoint : keyPoints) {
descriptors.add(createKeyPointDescriptor(integrator, keyPoint));
}
return descriptors;
}
private static KeyPointDescriptor createKeyPointDescriptor(ArrayImageIntegrator integrator, KeyPoint keyPoint) {
KeyPointDescriptor descriptor = new KeyPointDescriptor();
// Divide in a 4x4 zone the space around the interest point
// First compute the orientation.
double cosP = Math.cos(keyPoint.getOrientation());
double sinP = Math.sin(keyPoint.getOrientation());
double norm = 0;
// Divide in 16 sectors the space around the interest point.
for (int i = 0; i < DESCRIPTOR_SECTOR_SIZE_1D; i++) {
for (int j = 0; j < DESCRIPTOR_SECTOR_SIZE_1D; j++) {
computeSectorDescriptorInDescriptor(integrator, keyPoint, cosP, sinP, descriptor, i, j);
// Compute the norm of the vector
norm += computeSectorDescriptorsNorm(descriptor, i, j);
}
}
// Normalization of the descriptors in order to improve invariance to
// contrast change and whitening the descriptors.
norm = Math.sqrt(norm);
if (norm != 0)
normalizeSectorDescriptorsBy(descriptor, norm);
descriptor.setKeyPoint(keyPoint);
return descriptor;
}
private static void computeSectorDescriptorInDescriptor(ArrayImageIntegrator integrator, KeyPoint keyPoint,
double cosP, double sinP, KeyPointDescriptor descriptor, int i, int j) {
double u, v, gauss, responseU, responseV, responseX, responseY;
descriptor.getSectorDescriptor(DESCRIPTOR_SECTOR_SIZE_1D * i + j).setSumDx(0);
descriptor.getSectorDescriptor(DESCRIPTOR_SECTOR_SIZE_1D * i + j).setSumAbsDx(0);
descriptor.getSectorDescriptor(DESCRIPTOR_SECTOR_SIZE_1D * i + j).setSumDy(0);
descriptor.getSectorDescriptor(DESCRIPTOR_SECTOR_SIZE_1D * i + j).setSumAbsDy(0);
// Then each 4x4 is subsampled into a 5x5 zone
for (int k = 0; k < 5; k++) {
for (int l = 0; l < 5; l++) {
// We pre compute Haar answers
u = (keyPoint.getX() + keyPoint.getScale() * (cosP * ((i - 2) * 5 + k + 0.5) - sinP * ((j - 2) * 5 + l + 0.5)));
v = (keyPoint.getY() + keyPoint.getScale() * (sinP * ((i - 2) * 5 + k + 0.5) + cosP * ((j - 2) * 5 + l + 0.5)));
responseX = integrator.getHaarX((int) u, (int) v, (int) Math.round(keyPoint.getScale()));
// (u,v) are already translated of 0.5, which means
// that there is no round-off to perform: one takes
// the integer part of the coordinates.
responseY = integrator.getHaarY((int) u, (int) v, (int) Math.round(keyPoint.getScale()));
// Gaussian weight
gauss = getGaussian(((i - 2) * 5 + k + 0.5), ((j - 2) * 5 + l + 0.5), 3.3);
// Rotation of the axis
// responseU = gauss*( -responseX*sinP + responseY*cosP);
// responseV = gauss*(responseX*cosP + responseY*sinP);
responseU = gauss * (responseX * cosP + responseY * sinP);
responseV = gauss * (-responseX * sinP + responseY * cosP);
// The descriptors.
descriptor.getSectorDescriptor(DESCRIPTOR_SECTOR_SIZE_1D * i + j).addToSumDx(responseU);
descriptor.getSectorDescriptor(DESCRIPTOR_SECTOR_SIZE_1D * i + j).addToSumAbsDx(Math.abs(responseU));
descriptor.getSectorDescriptor(DESCRIPTOR_SECTOR_SIZE_1D * i + j).addToSumDy(responseV);
descriptor.getSectorDescriptor(DESCRIPTOR_SECTOR_SIZE_1D * i + j).addToSumAbsDy(Math.abs(responseV));
}
}
}
public static double getGaussian(double x, double y, double sigma) {
return 1 / (2 * Math.PI * sigma * sigma) * Math.exp(-(x * x + y * y) / (2 * sigma * sigma));
}
private static double computeSectorDescriptorsNorm(KeyPointDescriptor descriptor, int i, int j) {
return descriptor.getSectorDescriptor(DESCRIPTOR_SECTOR_SIZE_1D * i + j).getSumAbsDx()
* descriptor.getSectorDescriptor(DESCRIPTOR_SECTOR_SIZE_1D * i + j).getSumAbsDx()