Exemplo n.º 1
0
void FeatureEval::blurred_intensity() {
    boost::shared_ptr<PointCloud> cloud = core_->cl_->active_;
    if(cloud == nullptr)
        return;
    int h = cloud->scan_width();
    int w = cloud->scan_height();

    boost::shared_ptr<std::vector<float>> intensity = boost::make_shared<std::vector<float>>(cloud->size());

    // Create intensity cloud
    for(uint i = 0; i < intensity->size(); i++){
        (*intensity)[i] = (*cloud)[i].intensity;
    }

    boost::shared_ptr<std::vector<float>> img = cloudToGrid(cloud->cloudToGridMap(), w*h, intensity);


    boost::shared_ptr<std::vector<float> > smooth_grad_image = convolve(img, w, h, gaussian, 5);
    smooth_grad_image = convolve(smooth_grad_image, w, h, gaussian, 5);
    smooth_grad_image = convolve(smooth_grad_image, w, h, gaussian, 5);
    smooth_grad_image = convolve(smooth_grad_image, w, h, gaussian, 5);
/*
    boost::shared_ptr<std::vector<float>> highfreq = img;

    for(int i = 0; i < highfreq->size(); i++){
        (*highfreq)[i] = (*highfreq)[i] - (*smooth_grad_image)[i];
    }

    drawFloats(highfreq, cloud);
*/
    drawFloats(smooth_grad_image, cloud);

}
Exemplo n.º 2
0
/**
 * Hybrid window filtering, see blocks 36 and 49 of the G.728 specification.
 *
 * @param order   filter order
 * @param n       input length
 * @param non_rec number of non-recursive samples
 * @param out     filter output
 * @param hist    pointer to the input history of the filter
 * @param out     pointer to the non-recursive part of the output
 * @param out2    pointer to the recursive part of the output
 * @param window  pointer to the windowing function table
 */
static void do_hybrid_window(RA288Context *ractx,
                             int order, int n, int non_rec, float *out,
                             float *hist, float *out2, const float *window)
{
    int i;
    float buffer1[MAX_BACKWARD_FILTER_ORDER + 1];
    float buffer2[MAX_BACKWARD_FILTER_ORDER + 1];
    LOCAL_ALIGNED(32, float, work, [FFALIGN(MAX_BACKWARD_FILTER_ORDER +
                                            MAX_BACKWARD_FILTER_LEN   +
                                            MAX_BACKWARD_FILTER_NONREC, 16)]);

    av_assert2(order>=0);

    ractx->fdsp->vector_fmul(work, window, hist, FFALIGN(order + n + non_rec, 16));

    convolve(buffer1, work + order    , n      , order);
    convolve(buffer2, work + order + n, non_rec, order);

    for (i=0; i <= order; i++) {
        out2[i] = out2[i] * 0.5625 + buffer1[i];
        out [i] = out2[i]          + buffer2[i];
    }

    /* Multiply by the white noise correcting factor (WNCF). */
    *out *= 257.0 / 256.0;
}
Exemplo n.º 3
0
/**
 * Hybrid window filtering. See blocks 36 and 49 of the G.728 specification.
 *
 * @param order   the order of the filter
 * @param n       the length of the input
 * @param non_rec the number of non-recursive samples
 * @param out     the filter output
 * @param in      pointer to the input of the filter
 * @param hist    pointer to the input history of the filter. It is updated by
 *                this function.
 * @param out     pointer to the non-recursive part of the output
 * @param out2    pointer to the recursive part of the output
 * @param window  pointer to the windowing function table
 */
static void do_hybrid_window(int order, int n, int non_rec, const float *in,
                             float *out, float *hist, float *out2,
                             const float *window)
{
    int i;
    float buffer1[order + 1];
    float buffer2[order + 1];
    float work[order + n + non_rec];

    /* update history */
    memmove(hist                  , hist + n, (order + non_rec)*sizeof(*hist));
    memcpy (hist + order + non_rec, in      , n                *sizeof(*hist));

    colmult(work, window, hist, order + n + non_rec);

    convolve(buffer1, work + order    , n      , order);
    convolve(buffer2, work + order + n, non_rec, order);

    for (i=0; i <= order; i++) {
        out2[i] = out2[i] * 0.5625 + buffer1[i];
        out [i] = out2[i]          + buffer2[i];
    }

    /* Multiply by the white noise correcting factor (WNCF) */
    *out *= 257./256.;
}
Exemplo n.º 4
0
/**
 * Hybrid window filtering, see blocks 36 and 49 of the G.728 specification.
 *
 * @param order   filter order
 * @param n       input length
 * @param non_rec number of non-recursive samples
 * @param out     filter output
 * @param hist    pointer to the input history of the filter
 * @param out     pointer to the non-recursive part of the output
 * @param out2    pointer to the recursive part of the output
 * @param window  pointer to the windowing function table
 */
static void do_hybrid_window(int order, int n, int non_rec, float *out,
                             float *hist, float *out2, const float *window)
{
    int i;
#ifndef _MSC_VER
    float buffer1[order + 1];
    float buffer2[order + 1];
    float work[order + n + non_rec];
#else
    float *buffer1 = av_malloc_items(order + 1, float);
    float *buffer2 = av_malloc_items(order + 1, float);
    float *work = av_malloc_items(order + n + non_rec, float);
#endif

    apply_window(work, window, hist, order + n + non_rec);

    convolve(buffer1, work + order    , n      , order);
    convolve(buffer2, work + order + n, non_rec, order);

    for (i=0; i <= order; i++) {
        out2[i] = out2[i] * 0.5625 + buffer1[i];
        out [i] = out2[i]          + buffer2[i];
    }

    /* Multiply by the white noise correcting factor (WNCF). */
    *out *= 257./256.;

#ifdef _MSC_VER
	av_free(buffer1);
	av_free(buffer2);
	av_free(work);
#endif
}
Exemplo n.º 5
0
/**
 * Hybrid window filtering, see blocks 36 and 49 of the G.728 specification.
 *
 * @param order   filter order
 * @param n       input length
 * @param non_rec number of non-recursive samples
 * @param out     filter output
 * @param hist    pointer to the input history of the filter
 * @param out     pointer to the non-recursive part of the output
 * @param out2    pointer to the recursive part of the output
 * @param window  pointer to the windowing function table
 */
static void do_hybrid_window(int order, int n, int non_rec, float *out,
                             float *hist, float *out2, const float *window)
{
    int i;
    #if __STDC_VERSION__ >= 199901L
    float buffer1[order + 1];
    float buffer2[order + 1];
    float work[order + n + non_rec];
    #else
    float *buffer1=(float *)alloca((order + 1)*sizeof(float));
    float *buffer2=(float *)alloca((order + 1)*sizeof(float));
    float *work=(float *)alloca((order + n + non_rec)*sizeof(float));
    #endif

    apply_window(work, window, hist, order + n + non_rec);

    convolve(buffer1, work + order    , n      , order);
    convolve(buffer2, work + order + n, non_rec, order);

    for (i=0; i <= order; i++) {
        out2[i] = out2[i] * 0.5625 + buffer1[i];
        out [i] = out2[i]          + buffer2[i];
    }

    /* Multiply by the white noise correcting factor (WNCF). */
    *out *= 257./256.;
}
Exemplo n.º 6
0
  //static
  void GradientsMergeMosaic::convolveMask(weightImageType_t &rMask_p, int32 featherRadius_p)
  {
    int sideLength=1+2*featherRadius_p;
    int nElements=sideLength*sideLength;

#if 0
#if 0
    // linear filter
    LinearFilter filter(sideLength,1.0/nElements,1.0/nElements);
#else
    // box filter
    KernelFilter filter( sideLength, 1.0/nElements );
#endif
#if 1
    std::cout<<"FilterCoefficients ";
    for (const float *val=filter.Begin();val!=filter.End();++val){
      std::cout<<*val<<",";
    }
    std::cout<<std::endl;
#endif
    Convolution convolve(filter);
#else
    // separable filter
    SeparableFilter filter( sideLength,1.0/nElements);
    SeparableConvolution convolve(filter);
#endif
    convolve >>rMask_p;
  }
Exemplo n.º 7
0
// TODO: THIS IS A 2D FEATURE CALCULATION! help!
// Compute the distance for each point
// Gaussian weighted average in neighbourhood
// Subtract
void FeatureEval::difference_of_gaussian_distances(){
    boost::shared_ptr<PointCloud> cloud = core_->cl_->active_;
    if(cloud == nullptr)
        return;
    int h = cloud->scan_width();
    int w = cloud->scan_height();

    // Create distance map
    boost::shared_ptr<std::vector<float>> distmap = makeDistmap(cloud);

    //distmap = interpolate(distmap, w, h, 21);

    boost::shared_ptr<std::vector<float> > smooth_grad_image = convolve(distmap, w, h, gaussian, 5);
    smooth_grad_image = convolve(smooth_grad_image, w, h, gaussian, 5);
    smooth_grad_image = convolve(smooth_grad_image, w, h, gaussian, 5);
    smooth_grad_image = convolve(smooth_grad_image, w, h, gaussian, 5);

    boost::shared_ptr<std::vector<float>> highfreq = distmap;

    for(uint i = 0; i < distmap->size(); i++){
        (*highfreq)[i] = (*distmap)[i] - (*smooth_grad_image)[i];
    }

    drawFloats(highfreq, cloud);
}
Exemplo n.º 8
0
/*
 * Main
 */
int main(int argc, char *argv[]) {
  int i, j;
  int sobel_y[3][3] = {{-1, -2, -1},
                       {0, 0, 0},
                       {1, 2, 1}};
  int sobel_x[3][3] = {{-1, 0, 1},
                       {-2, 0, 2},
                       {-1, 0, 1}};

  Image src;
  Image G_y;
  Image G_x;
  Image out;

  if (argc < 2) {
    fprintf(stderr, "Pass the name of a PGM P5 file.\n");
    return 1;
  }

  // Read source PGM file
  if (read_PGM(argv[1], &src))
    return 1;

  // Initialize all the matrices to be of the same size as the source image.
  init_matrix(src, &G_y);
  init_matrix(src, &G_x);
  init_matrix(src, &out);

  // Convolve the Sobel filters with the source image
  convolve(sobel_y, src, &G_y);
  convolve(sobel_x, src, &G_x);

  // Calculate the gradient magnitude and put it in out.
  sobel_grad_mag(&out, G_y, G_x);

  // Normalize values to 0-255
  normalize(&G_y);
  normalize(&G_x);
  normalize(&out);

  // Write final output PGMs
  if (write_PGM("g_y.pgm", G_y))
    return 1;
  if (write_PGM("g_x.pgm", G_x))
    return 1;
  if (write_PGM("out.pgm", out))
    return 1;

  // Free the matrices
  dealloc_matrix(src.img, src.row);
  dealloc_matrix(G_y.img, 4);
  dealloc_matrix(G_x.img, 4);
  dealloc_matrix(out.img, out.row);

  return 0;
}
Exemplo n.º 9
0
inline void edge_detector::edge_detect(int **a, int kernel, qreal *gradient, qreal *gangle)
{
    // Scharr kernel
    int SCx[3][3] = {{-3, 0, 3}, {-10, 0, 10}, {-3, 0, 3}};
    int SCy[3][3] = {{-3,-10,-3}, { 0, 0, 0}, { 3, 10, 3}};

    // Sobel kernel
    int Sx[3][3] = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};
    int Sy[3][3] = {{-1,-2,-1}, { 0, 0, 0}, { 1, 2, 1}};

    // Prewitt kernel
    int Px[3][3] = {{-1, 0, 1}, {-1, 0, 1}, {-1, 0, 1}};
    int Py[3][3] = {{-1,-1,-1}, { 0, 0, 0}, { 1, 1, 1}};

    // Roberts Cross
    int Rx[3][3] = {{1, 0, 0}, {0, -1, 0}, {0, 0, 0}};
    int Ry[3][3] = {{0, 1, 0}, {-1, 0, 0}, {0, 0, 0}};

    int **Kx, **Ky;
    int k, gx, gy;

    if (kernel == 0) // Scharr kernel
    {
        k = 16;
        Kx = copy(SCx);
        Ky = copy(SCy);
    }
    else if (kernel == 1) // Sobel kernel
    {
        k = 4;
        Kx = copy(Sx);
        Ky = copy(Sy);
    }
    else if (kernel == 2) // Prewitt kernel
    {
        k = 3;
        Kx = copy(Px);
        Ky = copy(Py);
    }
    else if (kernel == 3) // Roberts Cross
    {
        k = 2;
        Kx = copy(Rx);
        Ky = copy(Ry);
    }

    gx = convolve(a, Kx, 3);
    gy = convolve(a, Ky, 3);

    deleteArray(Kx, 3);
    deleteArray(Ky, 3);

    *gradient = sqrt(gx*gx + gy*gy)/k;
    *gangle = 180/M_PI * atan2(gy, gx);
}
Exemplo n.º 10
0
 static void convolve_two_segments(std::vector<point>& figure, const edge& a, const edge& b) {
   figure.clear();
   figure.push_back(point(a.first));
   figure.push_back(point(a.first));
   figure.push_back(point(a.second));
   figure.push_back(point(a.second));
   convolve(figure[0], b.second);
   convolve(figure[1], b.first);
   convolve(figure[2], b.first);
   convolve(figure[3], b.second);
 }
Exemplo n.º 11
0
void image_u8_gaussian_blur(image_u8_t *im, double sigma, int ksz)
{
    assert((ksz & 1) == 1); // ksz must be odd.

    // build the kernel.
    double dk[ksz];

    // for kernel of length 5:
    // dk[0] = f(-2), dk[1] = f(-1), dk[2] = f(0), dk[3] = f(1), dk[4] = f(2)
    for (int i = 0; i < ksz; i++) {
        int x = -ksz/2 + i;
        double v = exp(-.5*sq(x / sigma));
        dk[i] = v;
    }

    // normalize
    double acc = 0;
    for (int i = 0; i < ksz; i++)
        acc += dk[i];

    for (int i = 0; i < ksz; i++)
        dk[i] /= acc;

    uint8_t k[ksz];
    for (int i = 0; i < ksz; i++)
        k[i] = dk[i]*255;

    if (0) {
        for (int i = 0; i < ksz; i++)
            printf("%d %15f %5d\n", i, dk[i], k[i]);
    }

    for (int y = 0; y < im->height; y++) {

        uint8_t x[im->stride];
        memcpy(x, &im->buf[y*im->stride], im->stride);

        convolve(x, &im->buf[y*im->stride], im->width, k, ksz);
    }

    for (int x = 0; x < im->width; x++) {
        uint8_t xb[im->height];
        uint8_t yb[im->height];

        for (int y = 0; y < im->height; y++)
            xb[y] = im->buf[y*im->stride + x];

        convolve(xb, yb, im->height, k, ksz);

        for (int y = 0; y < im->height; y++)
            im->buf[y*im->stride + x] = yb[y];
    }
}
Exemplo n.º 12
0
APPROX float sobel(float w[][3]) {
    float sx;
    float sy;
    float s;

    sx = convolve(w, ky);
    sy = convolve(w, kx);

    s = sqrt(sx * sx + sy * sy);
    if (s >= (256 / sqrt(256 * 256 + 256 * 256)))
        s = 255 / sqrt(256 * 256 + 256 * 256);

    return s ;
}
Exemplo n.º 13
0
/*----------------------------------------------------------------------------
 * norm_corr - Find the normalized correlation between the target vector and
 *             the filtered past excitation.
 *----------------------------------------------------------------------------
 */
static void norm_corr(
 FLOAT exc[],           /* input : excitation buffer */
 FLOAT xn[],            /* input : target vector */
 FLOAT h[],             /* input : imp response of synth and weighting flt */
 int l_subfr,           /* input : Length of frame to compute pitch */
 int t_min,             /* input : minimum value of searched range */
 int t_max,             /* input : maximum value of search range */
 FLOAT corr_norm[]      /* output: normalized correlation (correlation between
                                   target and filtered excitation divided by
                                   the square root of energy of filtered
                                    excitation) */
)
{
 int    i, j, k;
 FLOAT excf[L_SUBFR];     /* filtered past excitation */
 FLOAT  alp, s, norm;

 k = -t_min;

 /* compute the filtered excitation for the first delay t_min */

 convolve(&exc[k], h, excf, l_subfr);

 /* loop for every possible period */

 for (i = t_min; i <= t_max; i++)
 {
   /* Compute 1/sqrt(energie of excf[]) */

   alp = (F)0.01;
   for (j = 0; j < l_subfr; j++)
     alp += excf[j]*excf[j];

   norm = inv_sqrt(alp);


   /* Compute correlation between xn[] and excf[] */

   s = (F)0.0;
   for (j = 0; j < l_subfr; j++)  s += xn[j]*excf[j];


   /* Normalize correlation = correlation * (1/sqrt(energie)) */

   corr_norm[i] = s*norm;

   /* modify the filtered excitation excf[] for the next iteration */

   if (i != t_max)
   {
     k--;
     for (j = l_subfr-1; j > 0; j--)
        excf[j] = excf[j-1] + exc[k]*h[j];
     excf[0] = exc[k];
   }
 }

 return;

}
Exemplo n.º 14
0
lpyramid_t *
lpyramid_create (float *image, int width, int height)
{
    lpyramid_t *pyramid;
    int i;

    pyramid = malloc (sizeof (lpyramid_t));
    if (pyramid == NULL) {
	fprintf (stderr, "Out of memory.\n");
	exit (1);
    }
    pyramid->width = width;
    pyramid->height = height;

    /* Make the Laplacian pyramid by successively
     * copying the earlier levels and blurring them */
    for (i=0; i<MAX_PYR_LEVELS; i++) {
	pyramid->levels[i] = malloc (width * height * sizeof (float));
	if (pyramid->levels[i] == NULL) {
	    fprintf (stderr, "Out of memory.\n");
	    exit (1);
	}
	if (i == 0) {
	    memcpy (pyramid->levels[i], image, width * height * sizeof (float));
	} else {
	    convolve(pyramid, pyramid->levels[i], pyramid->levels[i - 1]);
	}
    }

    return pyramid;
}
Exemplo n.º 15
0
void CONVOLVE1::process(const float *buf, const int len)
{
	DPRINT1("CONVOLVE1::process (len=%d)\n", len);

	// NOTE: <len> will always be equal to _impframes
	if (_winosc)
		for (int i = 0; i < len; i++)
			_fftbuf[i] = buf[i] * _winosc->next(i);
	else
		for (int i = 0; i < len; i++)
			_fftbuf[i] = buf[i];
	for (int i = len; i < _fftlen; i++)
		_fftbuf[i] = 0.0f;

	convolve();

	for (int i = 0, j = len; i < len; i++, j++) {
		_ovadd[i] += _fftbuf[i];
		_wet[_outWriteIndex] = _ovadd[i];
		_dry[_outWriteIndex] = buf[i];
		incrementOutWriteIndex();
		_ovadd[i] = _fftbuf[j];
	}

//	for (int i = 0; i < _fftlen; i++) printf("[%d] = %f\n", i, _fftbuf[i]);
}
Exemplo n.º 16
0
void FeatureEval::sobel_erode(){
    boost::shared_ptr<PointCloud> cloud = core_->cl_->active_;
    if(cloud == nullptr)
        return;
    int h = cloud->scan_width();
    int w = cloud->scan_height();

    // Create distance map
    boost::shared_ptr<std::vector<float>> distmap = makeDistmap(cloud);

    boost::shared_ptr<std::vector<float> > grad_image = gradientImage(distmap, w, h);
    boost::shared_ptr<std::vector<float> > smooth_grad_image = convolve(grad_image, w, h, gaussian, 5);

    // Threshold && Erode

    const int strct[] = {
        0, 1, 0,
        1, 0, 1,
        0, 1, 0,
    };

    boost::shared_ptr<std::vector<float> > dilated_image =  morphology(
            smooth_grad_image,
            w, h, strct, 3, Morphology::ERODE,
            grad_image); // <-- reuse

    drawFloats(dilated_image, cloud);
}
Exemplo n.º 17
0
QImage edge_detector::smoothImage(const QImage image)
{
    QImage destImage = QImage( image);
    QColor qc;
    int Gauss[5][5] = {{2, 4, 5, 4, 2}, {4, 9, 12, 9, 4}, {5, 12, 15, 12, 5},
                       {4, 9, 12, 9, 4}, {2, 4, 5, 4, 2}};

    int **G = new int*[5];
    for (int i=0; i<5; i++)
    {
        G[i] = new int[5];
        for(int j=0; j<5; j++)
            G[i][j] = Gauss[i][j];
    }

    int H = image.height();
    int W = image.width();

    int* destData= (int *)destImage.bits();

    int **a, smooth;
    for (int y=2; y<H-2; y++)
    {
        for (int x=2; x<W-2; x++)
        {
            a = get_neighbor_pixels(image, x, y, 2);
            smooth = convolve(a, G, 5) / 159.f;
            deleteArray(a, 5); //2*2+1

            qc.setRgb(smooth, smooth, smooth);
            destData[x + y*W] = qc.rgba();
        }
    }
    return destImage;
}
Exemplo n.º 18
0
int perform_convolution(FILE *in, FILE *out, float sigma, int kx, int ky, const char *comment, BOOL binary) {
  int ux = 0, uy = 0;
  float **u = ip_load_image(in, &ux, &uy, NULL);

  if (!u)
    return 4;

  float **kernel = gaussian_kernel(kx, ky, sigma);

  if (!kernel) {
    ip_deallocate_image(ux, uy, u);
    return 5;
  }

  // TODO Schummlung entfernen
  dummies(u, ux, uy);
  float **v = convolve(ux + 2, uy + 2, u, kx, ky, kernel);

  ip_deallocate_image(ux, uy, u);
  ip_deallocate_image(kx, ky, kernel);

  if (!v)
    return 6;

  ip_save_image(out, ux, uy, v, comment, binary);

  ip_deallocate_image(ux, uy, v);

  return 0;
}
Exemplo n.º 19
0
DNNReturnType ff_dnn_execute_model_native(const DNNModel* model)
{
    ConvolutionalNetwork* network = (ConvolutionalNetwork*)model->model;
    InputParams* input_params;
    int cur_width, cur_height;
    int32_t layer;

    if (network->layers_num <= 0 || network->layers[0].type != INPUT || !network->layers[0].output){
        return DNN_ERROR;
    }
    else{
        input_params = (InputParams*)network->layers[0].params;
        cur_width = input_params->width;
        cur_height = input_params->height;
    }

    for (layer = 1; layer < network->layers_num; ++layer){
        if (!network->layers[layer].output){
            return DNN_ERROR;
        }
        switch (network->layers[layer].type){
        case CONV:
            convolve(network->layers[layer - 1].output, network->layers[layer].output, (ConvolutionalParams*)network->layers[layer].params, cur_width, cur_height);
            break;
        case INPUT:
            return DNN_ERROR;
        }
    }

    return DNN_SUCCESS;
}
Exemplo n.º 20
0
template <typename PointInT, typename IntensityT> void
pcl::tracking::PyramidalKLTTracker<PointInT, IntensityT>::downsample (const FloatImageConstPtr& input,
                                                               FloatImageConstPtr& output) const
{
  FloatImage smoothed (input->width, input->height);
  convolve (input, smoothed);

  int width = (smoothed.width +1) / 2;
  int height = (smoothed.height +1) / 2;
  std::vector<int> ii (width);
  for (int i = 0; i < width; ++i)
    ii[i] = 2 * i;

  FloatImagePtr down (new FloatImage (width, height));
#ifdef _OPENMP
#pragma omp parallel for shared (output) firstprivate (ii) num_threads (threads_)
#endif
  for (int j = 0; j < height; ++j)
  {
    int jj = 2*j;
    for (int i = 0; i < width; ++i)
      (*down) (i,j) = smoothed (ii[i],jj);
  }

  output = down;
}
Exemplo n.º 21
0
void propagate_x(quasse_fft *obj, int idx) {
  double *x = obj->x, *wrk = obj->wrk;
  int i, id, nx = obj->nx;
  int nkl = obj->nkl, nkr = obj->nkr, npad = obj->npad;
  int nd=obj->nd[idx];

  /* TODO: I am not sure if these are flipped nkl/nkr */
  for ( i = 0; i < nkl; i++ )
    wrk[i] = x[i];
  for ( i = nx-npad-nkr; i < nx - npad; i++ )
    wrk[i] = x[i];

  convolve(obj->fft[idx], obj->kern_y);

  for ( i = 0; i < nkl; i++ )
    x[i] = wrk[i];
  for ( i = nx-npad-nkr; i < nx - npad; i++ )
    x[i] = wrk[i];

  /* Zeroing takes a little more work, now.  We might be able to get
     away with just zeroing the E though */
  for ( id = 0; id < nd; id++ ) {
    x = obj->x + (obj->nx)*(id+1) - npad;
    for ( i = 0; i < npad; i++ ) 
      x[i] = 0;
  }
}
Exemplo n.º 22
0
	bool Kernel<T, U>::Convolve(const Image<T>& iImage, Image<U>& oImage) const
	{
		if (m_separable)
		{
			return convolveSeparable(iImage, oImage);
		}
		return convolve(iImage, oImage);
	}
Exemplo n.º 23
0
// C = fconv(A, B);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 
{
    if (nlhs != 1 || nrhs != 2){
        mexErrMsgTxt("Usage: C = fconv(A, B)");
    }
    
    // get A
    const mxArray *mxA = prhs[0];
    const mwSize *A_dims = mxGetDimensions(mxA);
    if (mxGetNumberOfDimensions(mxA)<2 || mxGetNumberOfDimensions(mxA)>3 || 
            mxGetClassID(mxA) != mxDOUBLE_CLASS)
        mexErrMsgTxt("Invalid input: A");
    double *A = (double *)mxGetPr(mxA);
    
    // get B
    const mxArray *mxB = prhs[1];
    const mwSize *B_dims = mxGetDimensions(mxB);
    if (mxGetNumberOfDimensions(mxB) < mxGetNumberOfDimensions(mxA) || 
            mxGetNumberOfDimensions(mxB) > 4 ||
            mxGetClassID(mxA) != mxDOUBLE_CLASS)
        mexErrMsgTxt("Invalid input: B");
    double *B = (double *)mxGetPr(mxB);
    
    int srcHeight = A_dims[0];
    int srcWidth = A_dims[1];
    int srcDims = mxGetNumberOfDimensions(mxA)>2 ? (int)A_dims[2] : 1;
    
    int filterHeight = B_dims[0];
    int filterWidth = B_dims[1];
    int filterDims = mxGetNumberOfDimensions(mxB)>2 ? (int)B_dims[2] : 1;   
    int filterNum = mxGetNumberOfDimensions(mxB) > 3 ? (int)B_dims[3] : 1;
    
    if(srcDims != filterDims){
        mexErrMsgTxt("Feature dimension mismatch.");
    }
    
    // prepare output
    int outHeight = srcHeight - filterHeight + 1;
    int outWidth = srcWidth - filterWidth + 1;
    if (outHeight < 1 || outWidth < 1)
        mexErrMsgTxt("Invalid input: B should be smaller than A");
    mwSize C_dims[] = {outHeight, outWidth, filterNum};
    mxArray* mxC = mxCreateNumericArray(3, C_dims, mxDOUBLE_CLASS, mxREAL);
    double *C = (double*)mxGetPr(mxC);
    plhs[0] = mxC;
    
    // do convolutions
    #pragma omp parallel for
    for (int i = 0; i < filterNum; ++i) 
    {
        convolve(A, 
                &B[i*filterHeight*filterWidth*filterDims], 
                &C[i*outHeight*outWidth], 
                outHeight, outWidth,
                filterHeight, filterWidth, filterDims,
                srcHeight, srcWidth);
    }
}
Exemplo n.º 24
0
void bestMatches(LifeList *cells1, LifeList *cells2, int period, 
                     int nmatches, PartialOscillatorDesc *osc) {
 
  int nConvolution, nEmpty;
  int i;
  Transformation T, bestT;

  setValues(cells1->cellList, cells1->ncells, 1);
  setValues(cells2->cellList, cells2->ncells, 1);

  T.translateBy= 0;
  for (T.flipxF=0; T.flipxF<=1; T.flipxF++) {
    for (T.flipyF=0; T.flipyF<=1; T.flipyF++) {
      for (T.transposeF=0; T.transposeF<=1; T.transposeF++) {

        transform(cells2->cellList, T, cells2->ncells);
        nConvolution=convolve(cells1->cellList, cells1->ncells, 
                              cells2->cellList, cells2->ncells, 
                              &convolution, &scratch1, &scratch2,
                              makeWorkSpace);

   
        for (i=0; i<nConvolution; i++) { 
          
           
          if (cells1->ncells - convolution[i].value 
                           < osc[nmatches-1].matchDistance) {
            int j,matchDistance; 


            matchDistance = cells1->ncells - convolution[i].value;

            nEmpty =emptyNeighbors(cells1);
            copyList(cells1->neighborhoods, nEmpty,
                     cells1->neighborhoods, convolution[i].position);

            matchDistance+=countMatch(cells1->neighborhoods, nEmpty,
                                      cells2->cellList, cells2->ncells);

            j= nmatches-1;

            while (j>=0 && matchDistance < osc[j].matchDistance) {
                osc[j+1]=osc[j];
                j--; 
            }

            osc[j+1].period=period;
            osc[j+1].T=T;
            osc[j+1].T.translateBy= convolution[i].position;
            osc[j+1].matchDistance=matchDistance;

          }
        }
        transformBack(cells2->cellList, T, cells2->ncells);
      }
    }
  }
}
Exemplo n.º 25
0
void visc_tens(Field *fld) {
/* Calculates the stress tensor including viscosity and pressure */

	int i;
	double twoth = (2.0/3.0);
	double qom = (fld->Params->q)*(fld->Params->omega);
	double c = (fld->Params->c)*(fld->Params->c);
	double nu = (fld->Params->nu);
	double complex divv;
	
/* Forms Navier-Stokes stress tensor T=grad(v) + grad(v)^T - 2/3 div(v) I */
#ifdef OPENMP 
	#pragma omp parallel private(i,divv) shared(fld) num_threads(NUMTHREADS)
	#pragma omp for schedule(static)
#endif	
	for(i=0;i<NTOTC;i++) {
		if (i<istart || i>=iend) {
			fld->Tens->Pixx[i] = -c*(fld->sig[i]);
			fld->Tens->Pixy[i] = -nu*qom*(fld->sig[i]);
			fld->Tens->Piyy[i] = -c*(fld->sig[i]);	
		}
		else {
			
			divv = fld->dxu[i] + fld->dyv[i];
			divv *= twoth;
			fld->Tens->Txx[i] = 2*(fld->dxu[i])-divv;
			fld->Tens->Txy[i] = fld->dxv[i] + fld->dyu[i];
			fld->Tens->Tyy[i] = 2*(fld->dyv[i]) - divv;
			fld->Tens->Pixx[i] = -c*(fld->sig[i]);
			fld->Tens->Pixy[i] = -nu*qom*(fld->sig[i]);
			fld->Tens->Piyy[i] = -c*(fld->sig[i]);		
			fld->Tens->divPix[i] = 0;
			fld->Tens->divPiy[i] = 0;
		}
	}
	convolve(&fld->Tens->Txx[istart],&fld->sig[istart],&fld->Tens->Pixx[istart],nu);
	convolve(&fld->Tens->Txy[istart],&fld->sig[istart],&fld->Tens->Pixy[istart],nu);
	convolve(&fld->Tens->Tyy[istart],&fld->sig[istart],&fld->Tens->Piyy[istart],nu);

/* Set Tensor B.C's */



	return;
}
Exemplo n.º 26
0
int main(){
	
	const int length = 5;
	float input[length] = {-0.665365, -0.329988, 0.164465, 0.043962, 0.295885};
	
	float output[length];           	// array for storing Kalman processed values
	float temp[length];             	// array for storing subtraction results
	float temp2[length];	
	float miscresult[2] = {0, 0};   	// array for storing mean and std dev results
	float holder[length];           	// array for storing convolution results
	int i, j;
	float corr_temp[1] = {0};

	/*START OF PART II*/
	kalman_state kstate;
	reset(&kstate);
	//Kalmanfilter_C(input, output, &kstate, length);
	Kalmanfilter_asm(output, input, length, &kstate);
	printf("\n");
	/*END OF PART II*/

	/*START OF PART III*/	
	// subtract
	printf("subtraction:\n");
	subtract(temp, input, output, length);
	arm_sub_f32(input, output, temp2, length);
	for(j = 0; j < length; j++){
		printf("My implementation: %f CMSIS: %f\n", temp[j], temp2[j]);
	}

	// misc
	printf("\n");
	//misc(miscresult, temp, length);
	arm_mean_f32(temp, length, &miscresult[0]);
	arm_std_f32(temp, length, &miscresult[1]);
	printf("mean: %f stdev: %f\n", miscresult[0], miscresult[1]);

	// correlation
	//corr_temp[0] = correlation(input, output, length);
	arm_correlate_f32(input, length, output, length, &corr_temp[0]);
	printf("correlation: %f\n", corr_temp[0]);
	

	// convolution
	printf("\n");
	for(i = 0; i < length; i++){
		holder[i] = 0;
	}
	convolve(holder, input, output, length);
	//arm_conv_f32(input, length, output, length, holder);
	for(i = 0; i < length; i++){
		printf("convolution %f \n", holder[i]);
	}
	/*END OF PART III*/

	return 0;
}
Exemplo n.º 27
0
double AEC::compensate(double V)
{
        if (!m_withKernel)
                return V;
        double toCompensate = m_buffer[0];
        m_buffer[0] = m_buffer[1];
        m_buffer[1] = V;
        return toCompensate - 1e3*convolve();
}
Exemplo n.º 28
0
// Assumes symbol-rate sampling!!!!
SoftVector *equalizeBurst(signalVector &rxBurst,
		       float TOA,
		       int samplesPerSymbol,
		       signalVector &w, // feedforward filter
		       signalVector &b) // feedback filter
{

  delayVector(rxBurst,-TOA);

  signalVector* postForwardFull = convolve(&rxBurst,&w,NULL,FULL_SPAN);

  signalVector* postForward = new signalVector(rxBurst.size());
  postForwardFull->segmentCopyTo(*postForward,w.size()-1,rxBurst.size());
  delete postForwardFull;

  signalVector::iterator dPtr = postForward->begin();
  signalVector::iterator dBackPtr;
  signalVector::iterator rotPtr = GMSKRotation->begin();
  signalVector::iterator revRotPtr = GMSKReverseRotation->begin();

  signalVector *DFEoutput = new signalVector(postForward->size());
  signalVector::iterator DFEItr = DFEoutput->begin();

  // NOTE: can insert the midamble and/or use midamble to estimate BER
  for (; dPtr < postForward->end(); dPtr++) {
    dBackPtr = dPtr-1;
    signalVector::iterator bPtr = b.begin();
    while ( (bPtr < b.end()) && (dBackPtr >= postForward->begin()) ) {
      *dPtr = *dPtr + (*bPtr)*(*dBackPtr);
      bPtr++;
      dBackPtr--;
    }
    *dPtr = *dPtr * (*revRotPtr);
    *DFEItr = *dPtr;
    // make decision on symbol
    *dPtr = (dPtr->real() > 0.0) ? 1.0 : -1.0;
    //*DFEItr = *dPtr;
    *dPtr = *dPtr * (*rotPtr);
    DFEItr++;
    rotPtr++;
    revRotPtr++;
  }

  vectorSlicer(DFEoutput);

  SoftVector *burstBits = new SoftVector(postForward->size());
  SoftVector::iterator burstItr = burstBits->begin();
  DFEItr = DFEoutput->begin();
  for (; DFEItr < DFEoutput->end(); DFEItr++) 
    *burstItr++ = DFEItr->real();

  delete postForward;

  delete DFEoutput;

  return burstBits;
}
Exemplo n.º 29
0
// Gaussian blur
void blur(void *src_pixels, void *dst_pixels, size_t width, size_t height, size_t stride) {
  int kernel_blur[3][3] = { { 1, 2, 1 },
                            { 2, 4, 2 },
                            { 1, 2, 1 } };

  int factor = 16;
	int offset = 0;
  
  convolve(src_pixels, dst_pixels, width, height, stride, kernel_blur, factor, offset);
}
Exemplo n.º 30
0
void blur(Image * I, int factor)
{
	convMatrix * tmp = new_conv(factor);
	for(int i = 0; i <tmp->size; i++)
	{
		tmp->CPU_Matrix[i] = 1.0;
	}
	convolve(I,tmp);
	del_conv(tmp);
}