0

I need to make a convolution function in C and I'm kind of lost. Basically I need something like:

enter image description here

My function needs to be prepared for square matrices from 3x3 to even 1000x1000. This is what I tried:

int calcConv(int **matrix, int ** filter,int i, int j){
  int calc=0;

  for(int ii=i ; ii<i+3 ; ii++){             //Fixed posible Infinite Loop
    for(int jj=j ; jj<j+3 ; jj++){
      calc+= matrix[ii][jj] * filter[ii][jj];
    }
  }

  return calc;
}


int ** convolucion(int **matrix, int **filter, int size){
  int i,j;

  int ** convMatrix = (int**)malloc( size * sizeof(int*));

  for(i=0;i<size;i++){
    convMatrix[i]= (int*)malloc( size * sizeof(int));
  }

  for(i=0;i<size;i++){
    for(j=0;j<size;j++){
      convMatrix[i][j]=matrix[i][j];
    }
  }

  for(i=1;i<size-1;i++){
    for(j=0;j<size-2;j++){
      convMatrix[i][j+1]= calcConv(matriz,filter,i-1,j);
    }
  }

  return convMatrix;
}

Any help or advice is very appreciate!

RaCo
  • 21
  • 2
  • 8

0 Answers0