/* IPOL SIFT Copyright (C) 2014, Ives Rey-Otero, CMLA ENS Cachan Version 20140911 (September 11th, 2014) This C ANSI source code is related to the IPOL publication [1] "Anatomy of the SIFT Method." I. Rey Otero and M. Delbracio Image Processing Online, 2013. http://www.ipol.im/pub/algo/rd_anatomy_sift/ An IPOL demo is available at http://www.ipol.im/pub/demo/rd_anatomy_sift/ == Patent Warning and License ================================================= The SIFT method is patented [2] "Method and apparatus for identifying scale invariant features in an image." David G. Lowe Patent number: 6711293 Filing date: Mar 6, 2000 Issue date: Mar 23, 2004 Application number: 09/519,89 These source codes are made available for the exclusive aim of serving as scientific tool to verify the soundness and completeness of the algorithm description. Compilation, execution and redistribution of this file may violate patents rights in certain countries. The situation being different for every country and changing over time, it is your responsibility to determine which patent rights restrictions apply to you before you compile, use, modify, or redistribute this file. A patent lawyer is qualified to make this determination. If and only if they don't conflict with any patent terms, you can benefit from the following license terms attached to this file. This program is free software: you can use, modify and/or redistribute it under the terms of the simplified BSD License. You should have received a copy of this license along this program. If not, see . */ /** * @file sift_scalespace.c * @brief data structures to store the scale-space * * @li struct keypoint keypoint data structure. * @li struct sift_keypoints list of keypoints with variable length. * * @author Ives Rey-Otero */ #include #include #include #include #include "lib_discrete.h" #include "lib_scalespace.h" #include "lib_util.h" /** ************************************ ALLOCATION *******************************************/ /** @brief Octave structure memory allocation * * An octave is a stack of images sharing same w, h and intersample distance. * Each image of the stack has a level of blur. * * @param nSca : number of images in the stack. * @param delta : intersample distance * @param w * @param h * @param sigma : levels of blur for each image in the stack * * */ static struct octa *malloc_octa(float delta, int w, int h, int nSca, const float* sigmas) { /* Memory allocation */ struct octa* octave = xmalloc(sizeof(struct octa)); /* pointer to a (structure octave) */ /* Modifying structure members */ octave->delta = delta; octave->w = w; octave->h = h; octave->nSca = nSca; octave->sigmas = xmalloc(nSca*sizeof(float)); /* pointer to the array of level of simulated blurs */ octave->imStack = xmalloc(nSca*w*h*sizeof(float)); /* pointer to the array of pixels */ for(int i=0; isigmas[i] = sigmas[i]; } return octave; } /** @brief allocation and attributes modification * * Allocate memory for a scalespace structure * and modify attributes that will be used to actually build the scalespace * * @param nOct : number of octaves * @param deltas : intersample distance in each octave of the scalespace * @param ws : image w in each octave of the scalespace * @param hs : * @param nScas : number of images in each octave of the scalespace * @param sigmas : array of blurs for each image in each octave of the scalespace * */ struct sift_scalespace* sift_malloc_scalespace(int nOct, const float* deltas, const int* ws, const int* hs, const int* nScas, float** sigmas) { struct sift_scalespace* scalespace = xmalloc(sizeof(struct sift_scalespace)); scalespace->nOct = nOct; for(int o=0; ooctaves[o] = malloc_octa(deltas[o], ws[o], hs[o], nScas[o], sigmas[o]); } return scalespace; } static void free_octa(struct octa *octave) { xfree(octave->sigmas); /* the memory allocated to store simulated values */ xfree(octave->imStack); /* the memory allocated to store the octave samples */ xfree(octave); } void sift_free_scalespace(struct sift_scalespace *scalespace) { int nOct = scalespace->nOct; for(int o=0; ooctaves[o]); xfree(scalespace); } /** ********************************** ALLOCATION WRAPPERS ****************************************/ /** @brief Allocation via copy a scalespace structure * * - Copy structure (number of octaves, dimensions, sampling rates, levels of blur) * - Doesn't copy the image stacks * */ struct sift_scalespace* sift_malloc_scalespace_from_model(struct sift_scalespace* model_sift_scalespace) { struct sift_scalespace * copy_sift_scalespace; int nOct = model_sift_scalespace->nOct; int* nScas = xmalloc(nOct*sizeof(int)); int* ws = xmalloc(nOct*sizeof(int)); int* hs = xmalloc(nOct*sizeof(int)); float* deltas = xmalloc(nOct*sizeof(float)); float** sigmas = xmalloc(nOct*sizeof(float*)); for(int o=0; ooctaves[o]->nSca; ws[o] = model_sift_scalespace->octaves[o]->w; hs[o] = model_sift_scalespace->octaves[o]->h; deltas[o] = model_sift_scalespace->octaves[o]->delta; sigmas[o] = xmalloc(nScas[o]*sizeof(float)); for(int i=0; ioctaves[o]->sigmas[i]; } copy_sift_scalespace = sift_malloc_scalespace(nOct, deltas, ws, hs, nScas, sigmas); xfree(deltas); xfree(ws); xfree(hs); xfree(nScas); for(int o=0; onOct; int nSca; int w; int h; for(int o=0; ooctaves[o]->sigmas); xfree(dog->octaves[o]->imStack); nSca = scalespace->octaves[o]->nSca-1; w = scalespace->octaves[o]->w; h = scalespace->octaves[o]->h; dog->octaves[o]->nSca = nSca; dog->octaves[o]->sigmas = xmalloc(nSca*sizeof(float)); dog->octaves[o]->imStack = xmalloc(nSca*w*h*sizeof(float)); for(int i=0; ioctaves[o]->sigmas[i] = scalespace->octaves[o]->sigmas[i]; } } return dog; }