Class SIFT

All Implemented Interfaces:
ActionListener, WindowListener, Runnable, EventListener

public class SIFT extends AlgorithmBase
Copyright (C) 2007-11, Andrea Vedaldi and Brian Fulkerson Copyright (C) 2012-13, The VLFeat Team All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  • Field Details

    • VL_ERR_OK

      private final int VL_ERR_OK
      See Also:
    • VL_ERR_OVERFLOW

      private final int VL_ERR_OVERFLOW
      invalid input: '<' No error
      See Also:
    • VL_ERR_ALLOC

      private final int VL_ERR_ALLOC
      invalid input: '<' Buffer overflow error
      See Also:
    • VL_ERR_BAD_ARG

      private final int VL_ERR_BAD_ARG
      invalid input: '<' Resource allocation error
      See Also:
    • VL_ERR_IO

      private final int VL_ERR_IO
      invalid input: '<' Bad argument or illegal data error
      See Also:
    • VL_ERR_EOF

      private final int VL_ERR_EOF
      invalid input: '<' Input/output error
      See Also:
    • VL_PROT_UNKNOWN

      private final int VL_PROT_UNKNOWN
      invalid input: '<' End-of-file or end-of-sequence error
      See Also:
    • VL_PROT_NONE

      private final int VL_PROT_NONE
      invalid input: '<' unknown protocol
      See Also:
    • VL_PROT_ASCII

      private final int VL_PROT_ASCII
      invalid input: '<' no protocol
      See Also:
    • VL_PROT_BINARY

      private final int VL_PROT_BINARY
      invalid input: '<' ASCII protocol
      See Also:
    • VL_ERR_PGM_INV_HEAD

      private final int VL_ERR_PGM_INV_HEAD
      invalid input: '<' Binary protocol
      See Also:
    • VL_ERR_PGM_INV_META

      private final int VL_ERR_PGM_INV_META
      invalid input: '<' Invalid PGM header section.
      See Also:
    • VL_ERR_PGM_INV_DATA

      private final int VL_ERR_PGM_INV_DATA
      invalid input: '<' Invalid PGM meta section.
      See Also:
    • VL_ERR_PGM_IO

      private final int VL_ERR_PGM_IO
      invalid input: '<' Invalid PGM data section.
      See Also:
    • EOF

      private final int EOF
      invalid input: '<' Generic I/O error.
      See Also:
    • fileDir

      private String[] fileDir
    • fileName

      private String[] fileName
    • fileNum

      private int fileNum
    • mosaic

      private boolean mosaic
    • verbose

      private boolean verbose
    • outarg

      private String outarg
    • framesarg

      private String framesarg
    • descriptorarg

      private String descriptorarg
    • metaarg

      private String metaarg
    • read_framesarg

      private String read_framesarg
    • gssarg

      private String gssarg
    • O

      private int O
    • S

      private int S
    • omin

      private int omin
    • edge_thresh

      private double edge_thresh
    • peak_thresh

      private double peak_thresh
    • norm_thresh

      private double norm_thresh
    • magnif

      private double magnif
    • window_size

      private double window_size
    • force_orientations

      private boolean force_orientations
    • writeFrames

      private boolean writeFrames
    • readFrames

      private boolean readFrames
    • writeDescriptor

      private boolean writeDescriptor
    • writeMeta

      private boolean writeMeta
    • writeGss

      private boolean writeGss
    • NBO

      private int NBO
    • NBP

      private int NBP
    • EXPN_SZ

      private int EXPN_SZ
    • EXPN_MAX

      private double EXPN_MAX
      invalid input: '<' ::fast_expn table size @internal
    • expn_tab

      private double[] expn_tab
      invalid input: '<' ::fast_expn table max @internal
    • VL_PAD_BY_ZERO

      private int VL_PAD_BY_ZERO
      invalid input: '<' ::fast_expn table /** @name Image convolution flags
    • VL_PAD_BY_CONTINUITY

      private int VL_PAD_BY_CONTINUITY
      invalid input: '<' @brief Pad with zeroes.
    • VL_PAD_MASK

      private int VL_PAD_MASK
      invalid input: '<' @brief Pad by continuity.
    • VL_TRANSPOSE

      private int VL_TRANSPOSE
      invalid input: '<' @brief Padding field selector.
    • VL_EPSILON_F

      private float VL_EPSILON_F
      invalid input: '<' @brief Transpose result.
    • VL_EPSILON_D

      private double VL_EPSILON_D
    • VL_SIFT_BILINEAR_ORIENTATIONS

      private boolean VL_SIFT_BILINEAR_ORIENTATIONS
  • Constructor Details

    • SIFT

      public SIFT()
      SIFT - default constructor.
    • SIFT

      public SIFT(String[] fileDir, String[] fileName, boolean mosaic, boolean verbose, String outarg, String framesarg, String descriptorarg, String metaarg, String read_framesarg, String gssarg, int O, int S, int omin, double edge_thresh, double peak_thresh, double norm_thresh, double magnif, double window_size, boolean force_orientations, boolean writeFrames, boolean readFrames, boolean writeDescriptor, boolean writeMeta, boolean writeGss)
  • Method Details

    • runAlgorithm

      public void runAlgorithm()
      Description copied from class: AlgorithmBase
      Actually runs the algorithm. Implemented by inheriting algorithms.
      Specified by:
      runAlgorithm in class AlgorithmBase
    • vl_imwbackwardmx

      private float[] vl_imwbackwardmx(int[] X_pt, int[] Y_pt, float[] I_pt, double[][] iwXp_pt, double[][] iwYp_pt, int M, int N)
    • findNeighbor

      private int findNeighbor(double x, int[] X, int K)
    • vl_imwbackwardmx

      private double[] vl_imwbackwardmx(int[] X_pt, int[] Y_pt, double[] I_pt, double[][] iwXp_pt, double[][] iwYp_pt, int M, int N)
    • randomize

      private void randomize(int[] arr)
    • vl_file_meta_open

      private RandomAccessFile vl_file_meta_open(SIFT.VlFileMeta self, String basename, String mode, int[] error)
      Parameters:
      self - File meta information.
      basename - Basename.
      mode - Opening mode (as in @c fopen).
      Returns:
      error code. The error may be either either ::VL_ERR_OVERFLOW if the file name is too long or to ::VL_ERR_IO if the file cannot be opened.
    • vl_file_meta_close

      private void vl_file_meta_close(SIFT.VlFileMeta self)
      Parameters:
      self - File meta information.
    • vl_file_meta_parse

      private int vl_file_meta_parse(SIFT.VlFileMeta self, String optarg)
      Parameters:
      self - structure to initalize. The function parses the string @a optarg to fill the structure @a self. @a optarg is supposed to be composed of two parts: a file protocol specification and a file pattern. Then the function: - Sets VlFileMeta::active to true. - Sets VlFileMeta::protocol to the file protocol id (if any). - Sets VlFileMeta::pattern to the file pattern (if any).
      optarg - argument to parse.
      Returns:
      error code. The funciton may fail either because the file protocol is not recognized (::VL_ERR_BAD_ARG) or because the file pattern is too long to be stored (::VL_ERR_OVERFLOW).
    • vl_string_parse_protocol

      private String vl_string_parse_protocol(String string, int[] protocol)
      ------------------------------------------------------------------
      Parameters:
      string - string.
      protocol - protocol code (output).
      Returns:
      pointer to the first character after the protocol prefix. The function extracts the prefix of the string @a string terminated by the first occurrence of the @c :// substring (if any). It then matches the suffix terminated by @c :// to the supported @ref vl-stringop-file-protocols protocols. If @c protocol is not
    • vl_string_protocol_name

      private String vl_string_protocol_name(int protocol)
      ------------------------------------------------------------------
      Parameters:
      protocol - protocol code.
      Returns:
      pointer protocol name string. The function returns a pointer to a string containing the name of the protocol @a protocol (see the @a vl-file-protocols protocols list). If the protocol is unknown the function returns the empty string.
    • PRNFO

      private void PRNFO(String name, SIFT.VlFileMeta fm)
    • vl_string_basename

      private String vl_string_basename(String destination, int destinationSize, String source, int maxNumStrippedExtensions, int[] num)
      ------------------------------------------------------------------
      Parameters:
      destination - destination buffer.
      destinationSize - size of destination buffer.
      source - input string.
      maxNumStrippedExtensions - maximum number of extensions to strip.
      Returns:
      length of the destination string. The function removes the leading path and up to @c maxNumStrippedExtensions trailing extensions from the string @a source and writes the result to the buffer @a destination. The leading path is the longest suffix that ends with either the
    • vl_string_copy_sub

      private String vl_string_copy_sub(String destination, int destinationSize, String source, int beginning, int end, int[] num)
      ------------------------------------------------------------------
      Parameters:
      destination - output buffer.
      destinationSize - size of output buffer.
      beginning - start of the substring.
      end - end of the substring.
      Returns:
      length of the destination string. The function copies the substring from at @a beginning to @a end (not included) to the buffer @a destination of size @a destinationSize. If, however, the null character is found before
    • vl_pgm_extract_head

      private int vl_pgm_extract_head(RandomAccessFile f, SIFT.VlPgmImage im)
      ------------------------------------------------------------------
      Parameters:
      f - input file.
      im - image structure to fill.
      Returns:
      error code. The function extracts from the file @a f the meta-data section of an image encoded in PGM format. The function fills the structure ::VlPgmImage accordingly. The error may be either ::VL_ERR_PGM_INV_HEAD or ::VL_ERR_PGM_INV_META depending whether the error occurred in decoding the header or meta section of the PGM file.
    • remove_line

      private int remove_line(RandomAccessFile f)
      ------------------------------------------------------------------
      Parameters:
      f - file to strip.
      Returns:
      number of characters removed.
    • remove_blanks

      private int remove_blanks(RandomAccessFile f, int[] err)
      ------------------------------------------------------------------
      Parameters:
      f - file to strip.
      Returns:
      number of characters removed.
    • readAsciiInt

      private int readAsciiInt(RandomAccessFile f)
    • readAsciiDouble

      private double readAsciiDouble(RandomAccessFile f, int[] err)
    • vl_pgm_get_npixels

      private int vl_pgm_get_npixels(SIFT.VlPgmImage im)
    • vl_pgm_get_bpp

      private int vl_pgm_get_bpp(SIFT.VlPgmImage im)
    • vl_pgm_extract_data

      int vl_pgm_extract_data(RandomAccessFile f, SIFT.VlPgmImage im, int[] data)
    • vl_string_replace_wildcard

      private String vl_string_replace_wildcard(String destination, int destinationSize, String source, String wildcardChar, String escapeChar, String replacement, int[] num)
      ------------------------------------------------------------------
      Parameters:
      destination - output buffer.
      destinationSize - size of the output buffer.
      source - input string.
      wildcardChar - wildcard character.
      escapeChar - escape character.
      replacement - replacement string. The function replaces the occurrence of the specified wildcard character @a wildcardChar by the string @a replacement. The result is written to the buffer @a destination of size @a destinationSize. Wildcard characters may be escaped by preceding them by the @a esc character. More in general, anything following an occurrence of @a esc character is copied verbatim. To disable the escape characters simply set @a esc to 0.
      Returns:
      length of the result.
    • vl_file_meta_get_double

      private int vl_file_meta_get_double(int protocol, RandomAccessFile file, double[] x)
      Parameters:
      x - Datum read.
      self - File meta information.
      Returns:
      error code. The function returns ::VL_ERR_EOF if the end-of-file is reached and ::VL_ERR_BAD_ARG if the file is malformed.
    • log2

      private double log2(double x)
    • VL_SHIFT_LEFT

      private int VL_SHIFT_LEFT(int x, int n)
      Parameters:
      x - value.
      n - number of shift positions.
      Returns:
      @c x invalid input: '<'invalid input: '<' n . The macro is equivalent to the builtin @c invalid input: '<'invalid input: '<' operator, but it supports negative shifts too.
    • fast_expn_init

      private void fast_expn_init()
    • vl_sift_new

      SIFT.VlSiftFilt vl_sift_new(int width, int height, int noctaves, int nlevels, int o_min)
    • copy_and_upsample_rows

      private void copy_and_upsample_rows(float[] dst, int dstIndex, float[] src, int srcIndex, int width, int height)
      ------------------------------------------------------------------
      Parameters:
      f - SIFT filter.
      im - image data. The function starts processing a new image by computing its Gaussian scale space at the lower octave. It also empties the internal keypoint buffer.
    • copy_and_downsample

      private void copy_and_downsample(float[] dst, int dstIndex, float[] src, int srcIndex, int width, int height, int d)
      ------------------------------------------------------------------
      Parameters:
      dst - output imgae buffer.
      src - input image buffer.
      width - input image width.
      height - input image height.
      d - octaves (non negative). The function downsamples the image @a d times, reducing it to @c 1/2^d of its original size. The parameters @a width and @a height are the size of the input image. The destination image @a dst is assumed to be floor(width/2^d) pixels wide and floor(height/2^d) pixels high.
    • vl_imconvcol_vf

      private void vl_imconvcol_vf(float[] dst, int dst_index, int dst_stride, float[] src, int src_index, int src_width, int src_height, int src_stride, float[] filt, int filt_begin, int filt_end, int step, int flags)
    • _vl_sift_smooth

      private void _vl_sift_smooth(SIFT.VlSiftFilt self, float[] outputImage, int output_index, float[] tempImage, float[] inputImage, int input_index, int width, int height, double sigma)
      ------------------------------------------------------------------
      Parameters:
      self - SIFT filter.
      outputImage - output imgae buffer.
      tempImage - temporary image buffer.
      inputImage - input image buffer.
      width - input image width.
      height - input image height.
      sigma - smoothing.
    • vl_sift_process_first_octave

      private int vl_sift_process_first_octave(SIFT.VlSiftFilt f, float[] im)
    • vl_sift_get_octave

      private float[] vl_sift_get_octave(SIFT.VlSiftFilt f, int s, int[] octave_index)
      ------------------------------------------------------------------
      Parameters:
      f - SIFT filter.
      s - level index. The level index @a s ranges in the interval s_min = -1 and s_max = S + 2, where @c S is the number of levels per octave.
      Returns:
      pointer to the octave data for level @a s.
    • vl_sift_process_next_octave

      private int vl_sift_process_next_octave(SIFT.VlSiftFilt f)
      ------------------------------------------------------------------
      Parameters:
      f - SIFT filter. The function computes the next octave of the Gaussian scale space. Notice that this clears the record of any feature detected in the previous octave.
      Returns:
      error code. The function returns the error ::VL_ERR_EOF when there are no more octaves to process.
    • save_gss

      private int save_gss(SIFT.VlSiftFilt filt, SIFT.VlFileMeta fm, String basename, boolean verbose)
    • vl_pgm_insert

      private int vl_pgm_insert(RandomAccessFile f, SIFT.VlPgmImage im, byte[] data)
    • vl_sift_detect

      private void vl_sift_detect(SIFT.VlSiftFilt f)
      ------------------------------------------------------------------
      Parameters:
      f - SIFT filter.
    • vl_sift_keypoint_init

      private void vl_sift_keypoint_init(SIFT.VlSiftFilt f, SIFT.VlSiftKeypoint k, double x, double y, double sigma)
      ------------------------------------------------------------------
      Parameters:
      f - SIFT filter.
      k - SIFT keypoint (output).
      x - x coordinate of the keypoint center.
      y - y coordinate of the keypoint center.
      sigma - keypoint scale. The function initializes a keypoint structure @a k from the location @a x and @a y and the scale @a sigma of the keypoint. The keypoint structure maps the keypoint to an octave and scale level of the discretized Gaussian scale space, which is required for instance to compute the keypoint SIFT descriptor.
    • vl_sift_calc_keypoint_orientations

      private int vl_sift_calc_keypoint_orientations(SIFT.VlSiftFilt f, double[] angles, SIFT.VlSiftKeypoint k)
      ------------------------------------------------------------------
      Parameters:
      f - SIFT filter.
      angles - orientations (output).
      k - keypoint. The function computes the orientation(s) of the keypoint @a k. The function returns the number of orientations found (up to four). The orientations themselves are written to the vector @a angles.
      Returns:
      number of orientations found.
    • update_gradient

      private void update_gradient(SIFT.VlSiftFilt f)
      ------------------------------------------------------------------
      Parameters:
      f - SIFT filter. The function makes sure that the gradient buffer is up-to-date with the current GSS data.
    • vl_mod_2pi_f

      private float vl_mod_2pi_f(float x)
    • vl_sift_calc_keypoint_descriptor

      private void vl_sift_calc_keypoint_descriptor(SIFT.VlSiftFilt f, float[] descr, SIFT.VlSiftKeypoint k, double angle0)
      ------------------------------------------------------------------
      Parameters:
      f - SIFT filter.
      descr - SIFT descriptor (output)
      k - keypoint.
      angle0 - keypoint direction. The function computes the SIFT descriptor of the keypoint @a k of orientation @a angle0. The function fills the buffer @a descr which must be large enough to hold the descriptor. The function assumes that the keypoint is on the current octave. If not, it does not do anything.
    • normalize_histogram

      private float normalize_histogram(float[] buf, int begin, int end)
      ------------------------------------------------------------------
      Parameters:
      begin - begin of histogram.
      end - end of histogram.
    • vl_file_meta_put_double

      private int vl_file_meta_put_double(int protocol, RandomAccessFile file, double x)
      Parameters:
      x - Datum to write.
      self - File meta information.
      Returns:
      error code. The function returns ::VL_ERR_ALLOC if the datum cannot be written.
    • vl_file_meta_put_uint8

      private int vl_file_meta_put_uint8(int protocol, RandomAccessFile file, byte x)
      Parameters:
      x - Datum to write.
      self - File meta information.
      Returns:
      error code. The function returns ::VL_ERR_ALLOC if the datum cannot be written.
    • vl_sift_delete

      private void vl_sift_delete(SIFT.VlSiftFilt f)
      ------------------------------------------------------------------
      Parameters:
      dst - destination 8-byte buffer.
      src - source 8-byte bufffer.