hello all,
here is an implementation of the median mask along with some parameters:
but i get a segmentation fault when the "memcpy" is called
( the implementation of median is for sure correct, the problem is in the way i use it ),
can someone please help me overcome this ?
thank you
here is an implementation of the median mask along with some parameters:
Code:
/* necessary definitions */
#define M 100
char array1[M] ;
char array2[M] ;
/* initialization */
for( i=0; i<M; i++ ) array1[i] = i ;
/* call median */
median(array1, array2, M, M) ;
/* median filter implementation */
void median(char* imageIn,
char* imageOut,
unsigned width,
unsigned height) {
const int matrix_size = 9;
char values [matrix_size];
int i;
memset(imageOut, 0, width);
// scan the picture starting at second row
for (i = width; i < width * (height - 1); i++) {
// copy first pixels into matrix
memcpy ((char*)&values, &imageIn[i-width-1], 3);
memcpy ((char*)&values+3, &imageIn[i-1], 3);
memcpy ((char*)&values+6, &imageIn[i+width-1], 3);
// insertion sort with the matrix
{
int x, min;
char tmp;
for (x=0; x<9; x++) {
tmp = values[x];
min = x;
while ( (min>0) && (values[min-1]>tmp) ) {
values[min] = values [min-1];
min--;
}
values[min] = tmp;
}
}
// end of insertion sort with the matrix
// store median value in pixel considered
imageOut[i] = values[4];
memset(imageOut+i, 0, width);
}
}
but i get a segmentation fault when the "memcpy" is called
( the implementation of median is for sure correct, the problem is in the way i use it ),
can someone please help me overcome this ?
thank you